diff --git a/Group 5 Members.docx b/Group 5 Members.docx new file mode 100644 index 0000000..64c51b8 Binary files /dev/null and b/Group 5 Members.docx differ diff --git a/Group5_report.md b/Group5_report.md new file mode 100644 index 0000000..d5890e3 --- /dev/null +++ b/Group5_report.md @@ -0,0 +1,56 @@ +# Code Testing and Debugging Report For Quadratic Equation + + +## Introduction + + This report documents the testing and debugging effort for a quadratic equation solver + implemented in Python. The solver takes coefficients a, b, and c as input and calculates the roots + of the quadratic equation + >ax^2 + bx + c = 0. + +## Testing Methodology + +- **Testing approach**: Unit testing and integration testing were employed to ensure the solver's + correctness. +- **Test cases**: Various test cases were designed to cover different scenarios, including: + - Real roots + - Complex roots + - Repeated roots + - Edge cases (e.g., a = 0, b = 0, c = 0) +- **Testing tools**: The Python package pytest was used for testing. + +- **Test Results** + - Summary: 5 test cases were executed, with 3 passing and 2 failing initially. + - Issues encountered: Two test cases failed due to incorrect handling of complex roots. + - Screenshots/logs: Not applicable, but test output logs were reviewed to identify issues. + + +## Debugging Process +- **Debugging approach**: The debugger was used to step through the code and identify issues. +- **Step-by-step account**: For the complex root issue, the debugger revealed that the calculation of the + discriminant was incorrect. +- **Solutions implemented**: The calculation of the discriminant was corrected, and the solver was + updated to handle complex roots properly. +- **Issues and Fixes** + - Issue 1: Incorrect handling of complex roots. + Root cause: Incorrect calculation of the discriminant. + Solution: Corrected the calculation of the discriminant and updated the solver to handle + complex roots. + Code snippet: `discriminant = b**2 - 4*a*c` (corrected calculation) + - Issue 2: Repeated roots not handled correctly. + - Root cause: Insufficient checking for repeated roots. + - Solution: Added a check for repeated roots and updated the solver to handle them correctly. + +## Conclusion + +The testing and debugging process revealed the importance of thorough testing and attention to + detail.The testing and debugging effort ensured the quadratic equation solver's correctness and + reliability. With the issues resolved, the solver is now confident to produce accurate results.This + report demonstrates the testing and debugging process for a quadratic equation solver, + highlighting the importance of thorough testing and attention to detail. + +## Recommendations +- Future testing: Additional testing with more complex coefficients and edge cases. +- Potential improvements: Consider adding support for numerical methods or + approximation technique + diff --git a/README.md b/README.md deleted file mode 100644 index aa4e50b..0000000 --- a/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# pythonlab - -Python Lab diff --git a/__pycache__/quadraticEqn.cpython-313.pyc b/__pycache__/quadraticEqn.cpython-313.pyc new file mode 100644 index 0000000..987016c Binary files /dev/null and b/__pycache__/quadraticEqn.cpython-313.pyc differ diff --git a/__pycache__/testQuadraticEqn.cpython-313-pytest-8.4.2.pyc b/__pycache__/testQuadraticEqn.cpython-313-pytest-8.4.2.pyc new file mode 100644 index 0000000..dcfef12 Binary files /dev/null and b/__pycache__/testQuadraticEqn.cpython-313-pytest-8.4.2.pyc differ diff --git a/main.py b/main.py deleted file mode 100644 index 7cf7fd4..0000000 --- a/main.py +++ /dev/null @@ -1 +0,0 @@ -print("Hello PythonLab") \ No newline at end of file diff --git a/quadraticEqn.py b/quadraticEqn.py new file mode 100644 index 0000000..377b5b3 --- /dev/null +++ b/quadraticEqn.py @@ -0,0 +1,49 @@ + + +import cmath # For handling complex numbers + + +def solve_quadratic_eqn(a, b, c): + if a == 0: + print("Coefficient 'a' cannot be zero for a quadratic equation.") + return None + + discriminant = b**2 - 4*a*c + + if discriminant > 0: + root1 = (-b + cmath.sqrt(discriminant)) / (2*a) + root2 = (-b - cmath.sqrt(discriminant)) / (2*a) + elif discriminant == 0: + root1 = -b / (2*a) + root2 = root1 + else: + root1 = (-b + cmath.sqrt(discriminant)) / (2*a) + root2 = (-b - cmath.sqrt(discriminant)) / (2*a) + + return root1, root2 + + +def get_user_input(): + while True: + try: + a = float(input("input the coefficient of a:")) + b = float(input("input the coefficient of b:")) + c = float(input("input the coefficient of c:")) + return a,b,c + + except ValueError: + print("invalid input, please enter a valid input") + + +def main(): + a,b,c = get_user_input() + result = solve_quadratic_eqn(a,b,c) + print(f"The roots of the equation are {result}") + +if __name__ == "__main__": + main() + + + + + diff --git a/quadratic_flowchart.drawio b/quadratic_flowchart.drawio new file mode 100644 index 0000000..70156fd --- /dev/null +++ b/quadratic_flowchart.drawio @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/quadratic_flowchart.jpg b/quadratic_flowchart.jpg new file mode 100644 index 0000000..a244a21 Binary files /dev/null and b/quadratic_flowchart.jpg differ diff --git a/testQuadraticEqn.py b/testQuadraticEqn.py new file mode 100644 index 0000000..4f1c363 --- /dev/null +++ b/testQuadraticEqn.py @@ -0,0 +1,33 @@ +import pytest +from quadraticEqn import solve_quadratic_eqn # Replace 'your_module' with your actual filename (without .py) + +def test_two_real_roots(): + r1, r2 = solve_quadratic_eqn(1, -5, 6) + roots = sorted([r1.real, r2.real]) + expected = sorted([2, 3]) + assert pytest.approx(roots[0]) == expected[0] + assert pytest.approx(roots[1]) == expected[1] + + +def test_one_real_root(): + r1, r2 = solve_quadratic_eqn(1, -2, 1) + assert r1 == pytest.approx(1) + assert r2 == pytest.approx(1) +def test_complex_roots(): + r1, r2 = solve_quadratic_eqn(1, 2, 5) + + # Sort roots by imaginary part to ensure consistent order + roots = sorted([r1, r2], key=lambda x: x.imag) + + assert roots[0].real == pytest.approx(-1) + assert roots[1].real == pytest.approx(-1) + assert roots[0].imag == pytest.approx(-2) + assert roots[1].imag == pytest.approx(2) + +def test_zero_a_coefficient(): + result = solve_quadratic_eqn(0, 2, 3) + assert result is None + +def test_zero_division_handling(): + result = solve_quadratic_eqn(0, 0, 0) + assert result is None \ No newline at end of file