How piyush1105/string-calculator-tdd works
Main Components
• Calculator Logic: Located in src/calculator.js, this is where the core function (add) is implemented. It handles parsing the string input (using commas, newlines, and custom delimiters), converting values to numbers, error-checking negative numbers, and computing the sum.
• CLI Interface: Represented by index.js. This component acts as an entry point for users running the calculator from the terminal. It parses command-line arguments and delegates to the calculator logic.
• Testing Framework: The tests directory (tests/calculator.test.js) paired with Jest ensures that the calculator function conforms to the defined requirements. This component validates correctness via TDD practices.
• Configuration & Package Files: package.json, package-lock.json, and .gitignore provide essential configuration, dependency management, and version control settings. While not active runtime components, they define and support the system's structure.
Establish Relationships and Interactions
• Testing Integration: Illustrate that the Testing Framework (using Jest) invokes functions in the Calculator Logic to ensure expected outputs (e.g., summing numbers or throwing errors for negatives).
Architectural Patterns and Design Principles
• Modular Design: The separation of calculator logic (src) from the user interface (index.js) demonstrates a modular approach. This enables easy testing and future enhancements.
• Test-Driven Development (TDD): Emphasize that the tests (under tests/) drive the development cycle (Red-Green-Refactor), ensuring robust, maintainable code.
• Single Responsibility Principle: Each component (CLI, core logic, testing) is responsible for a distinct part of the system, making it easy to maintain and extend.
Incorporate Relevant Technologies and Frameworks
• JavaScript (Node.js): Represent this as the runtime environment.
• Jest: Highlight its role in the testing component.
• Git: You might note version control support via .gitignore and repository setup instructions (although this is more about process than runtime architecture).