Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added Group 5 Members.docx
Binary file not shown.
56 changes: 56 additions & 0 deletions Group5_report.md
Original file line number Diff line number Diff line change
@@ -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

3 changes: 0 additions & 3 deletions README.md

This file was deleted.

Binary file added __pycache__/quadraticEqn.cpython-313.pyc
Binary file not shown.
Binary file not shown.
1 change: 0 additions & 1 deletion main.py

This file was deleted.

49 changes: 49 additions & 0 deletions quadraticEqn.py
Original file line number Diff line number Diff line change
@@ -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()





56 changes: 56 additions & 0 deletions quadratic_flowchart.drawio
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<mxfile host="app.diagrams.net" agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36" version="28.2.1">
<diagram name="Page-1" id="FMp1MHaNlvcU11Jpijxr">
<mxGraphModel dx="1431" dy="838" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="850" pageHeight="1100" math="0" shadow="0">
<root>
<mxCell id="0" />
<mxCell id="1" parent="0" />
<mxCell id="0Ljvfr57Tc_P_qj9XOF8-19" value="" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;" edge="1" parent="1" source="0Ljvfr57Tc_P_qj9XOF8-2" target="0Ljvfr57Tc_P_qj9XOF8-4">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="0Ljvfr57Tc_P_qj9XOF8-2" value="start" style="ellipse;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="260" y="40" width="120" height="80" as="geometry" />
</mxCell>
<mxCell id="0Ljvfr57Tc_P_qj9XOF8-21" value="" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;" edge="1" parent="1" source="0Ljvfr57Tc_P_qj9XOF8-3" target="0Ljvfr57Tc_P_qj9XOF8-5">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="0Ljvfr57Tc_P_qj9XOF8-3" value="Compute discriminant&amp;nbsp;&amp;nbsp;&lt;div&gt;D=b^2 -4ac&lt;/div&gt;" style="shape=parallelogram;perimeter=parallelogramPerimeter;whiteSpace=wrap;html=1;fixedSize=1;" vertex="1" parent="1">
<mxGeometry x="230" y="260" width="180" height="60" as="geometry" />
</mxCell>
<mxCell id="0Ljvfr57Tc_P_qj9XOF8-20" value="" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;" edge="1" parent="1" source="0Ljvfr57Tc_P_qj9XOF8-4" target="0Ljvfr57Tc_P_qj9XOF8-3">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="0Ljvfr57Tc_P_qj9XOF8-4" value="Input a ,b ,c&amp;nbsp;" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="250" y="170" width="120" height="60" as="geometry" />
</mxCell>
<mxCell id="0Ljvfr57Tc_P_qj9XOF8-13" value="" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;" edge="1" parent="1" source="0Ljvfr57Tc_P_qj9XOF8-5" target="0Ljvfr57Tc_P_qj9XOF8-6">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="0Ljvfr57Tc_P_qj9XOF8-15" value="" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;" edge="1" parent="1" source="0Ljvfr57Tc_P_qj9XOF8-5" target="0Ljvfr57Tc_P_qj9XOF8-7">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="0Ljvfr57Tc_P_qj9XOF8-5" value="d&amp;gt;0" style="rhombus;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="260" y="380" width="80" height="80" as="geometry" />
</mxCell>
<mxCell id="0Ljvfr57Tc_P_qj9XOF8-14" value="" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;" edge="1" parent="1" source="0Ljvfr57Tc_P_qj9XOF8-6">
<mxGeometry relative="1" as="geometry">
<mxPoint x="290" y="620" as="targetPoint" />
</mxGeometry>
</mxCell>
<mxCell id="0Ljvfr57Tc_P_qj9XOF8-6" value="Output result" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="240" y="520" width="120" height="60" as="geometry" />
</mxCell>
<mxCell id="0Ljvfr57Tc_P_qj9XOF8-7" value="One&amp;nbsp; real roots (complex)" style="shape=parallelogram;perimeter=parallelogramPerimeter;whiteSpace=wrap;html=1;fixedSize=1;" vertex="1" parent="1">
<mxGeometry x="380" y="420" width="180" height="90" as="geometry" />
</mxCell>
<mxCell id="0Ljvfr57Tc_P_qj9XOF8-16" value="" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;" edge="1" parent="1" target="0Ljvfr57Tc_P_qj9XOF8-9">
<mxGeometry relative="1" as="geometry">
<mxPoint x="290" y="680" as="sourcePoint" />
</mxGeometry>
</mxCell>
<mxCell id="0Ljvfr57Tc_P_qj9XOF8-9" value="stop" style="ellipse;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="230" y="620" width="120" height="80" as="geometry" />
</mxCell>
</root>
</mxGraphModel>
</diagram>
</mxfile>
Binary file added quadratic_flowchart.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 33 additions & 0 deletions testQuadraticEqn.py
Original file line number Diff line number Diff line change
@@ -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