How lusehair/computorv1 works
Main Components
• Input Module: This starts by receiving the equation (from command-line input) and sends it to the parser.
• Polynomial Parser: Reads the raw input and breaks it into its constituent parts (terms, coefficients, operators, and degrees).
• Canonical Form Builder: Reorganizes and simplifies the input equation into its standard canonical form (ax² + bx + c = 0).
• Degree Evaluator & Solver:
• Degree 0 Handler: Checks for trivial validity (e.g., 3 = 3) or inconsistency.
• Degree 1 Solver: Implements the linear formula.
• Degree 2 Solver: Calculates the discriminant and applies the quadratic formula, with branches to handle:
• Positive discriminant (two real roots)
• Zero discriminant (one repeated root)
• Negative discriminant (two complex roots)
• Error Handling Component: Captures and reports syntax errors and unsupported degree cases.
• Test Suite: Located in test.py, this component orchestrates various tests against all scenarios (subject, correction, additional).
Relationships and Data Flow
• The input is fed into the Polynomial Parser.
• Parsed data is sent to the Canonical Form Builder.
• Once in its canonical form, the data flows to the Degree Evaluator, which selects the appropriate solver based on the degree.
• Solvers perform the computation and return the result.
• Any exceptions or invalid input are captured by the Error Handling component.
• Additionally, a separate testing flow leverages the Test Suite (test.py) to exercise all of the above components.
Architectural Patterns and Principles
• Separation of Concerns: Each module has a clearly defined responsibility (parsing, simplifying, solving, and testing).
• Decision Branching: The Degree Evaluator uses conditional logic to divert to different solution methods based on the polynomial’s degree.