This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ | |
| ************************************** | |
| ADDRESS BOOK (REFACTORED VERSION) | |
| Behavior preserved, design improved | |
| ************************************** | |
| """ | |
| from datetime import datetime | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Existing global state (KEEP) | |
| let contacts = []; | |
| let lastId = 0; | |
| /** | |
| * NEW: AddressBook class | |
| * We introduce it but DO NOT break existing code | |
| */ | |
| class AddressBook { | |
| constructor(store, clock = () => new Date().toISOString()) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /*************************************** | |
| * Characterization Tests for AddressBook | |
| ***************************************/ | |
| describe('Legacy Address Book – Characterization Tests', () => { | |
| beforeEach(() => { | |
| // Reset module state before every test | |
| jest.resetModules(); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| √ adds a contact successfully with valid data | |
| √ does not add contact when name is missing | |
| √ does not add contact with duplicate phone number | |
| √ finds a contact by phone number | |
| √ returns null when searching for non-existent phone | |
| √ updates an existing contact | |
| √ returns false when updating a non-existent contact | |
| √ deletes an existing contact | |
| √ returns false when deleting non-existent contact | |
| √ searches contacts by keyword across name, phone, and email |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /************************************** | |
| * ADDRESS BOOK (LEGACY / MESSY VERSION) | |
| **************************************/ | |
| let contacts = []; | |
| let lastId = 0; | |
| function addContact(name, phone, email, address) { | |
| if (name == null || name === "") { | |
| console.log("Name is required"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /*********************** | |
| * Simple Grading System | |
| ***********************/ | |
| let students = []; | |
| let totalProcessed = 0; | |
| function doIt( | |
| name, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /************************ | |
| * Clean Grading System | |
| * Refactored for clarity, | |
| * structure, and safety | |
| ************************/ | |
| /* ===== Constants (No Magic Numbers) ===== */ | |
| const SUBJECT_COUNT = 4; | |
| const ATTENDANCE_BONUS_THRESHOLD = 90; | |
| const ATTENDANCE_BONUS_POINTS = 5; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /*********************** | |
| * Simple Grading System | |
| ***********************/ | |
| let students = []; | |
| let totalProcessed = 0; | |
| function doIt( | |
| name, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // config with dotenv | |
| impl Config { | |
| pub fn from_env() -> Result<Self, ConfigError> { | |
| let s = config::Config::builder() | |
| .add_source(config::Environment::default()) | |
| .build()?; | |
| s.try_deserialize() | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package builder; | |
| import java.util.ArrayList; | |
| import java.util.List; | |
| public class Car { | |
| private String make; | |
| private String name; | |
| private String color; | |
| private int model; |
NewerOlder