Skip to content

Commit 14a19b7

Browse files
committed
adding some examples to test
1 parent 0bfa97b commit 14a19b7

File tree

5 files changed

+59
-18
lines changed

5 files changed

+59
-18
lines changed

readme.md

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ To run the application, execute the following command:
4545
python src/main.py
4646
```
4747

48+
## Running the Tests
49+
50+
To run the tests, use the following command:
51+
```bash
52+
pytest
53+
```
54+
4855
## Examples
4956

5057
### Basic Function Input
@@ -103,5 +110,21 @@ python src/main.py
103110
![constant function](screenshots/ex9.JPG)
104111

105112

106-
## automated tests. run some automated tests using `pytest`
107-
![tests passed](screenshots/ex10.JPG)
113+
### Empty Function
114+
- **Function:** ` `
115+
- **Range:** ` ` to ` `
116+
- **Expected Output:** Error message: "Function cannot be empty." <br>
117+
![constant function](screenshots/ex11.JPG)
118+
119+
### Min value is larger than Max value
120+
- **Function:** `x`
121+
- **Range:** `10` to `5`
122+
- **Expected Output:** Error message: "Min value must be less than Max value." <br>
123+
![constant function](screenshots/ex12.JPG)
124+
125+
126+
### Empty Min value
127+
- **Function:** `x`
128+
- **Range:** ` ` to `5`
129+
- **Expected Output:** Error message: "Min and Max values cannot be empty." <br>
130+
![constant function](screenshots/ex13.JPG)

screenshots/ex11.JPG

31.7 KB
Loading

screenshots/ex12.JPG

30.8 KB
Loading

screenshots/ex13.JPG

32 KB
Loading

tests/test_function_plotter.py

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,6 @@ def function_plotter(app_instance, qtbot):
4848

4949

5050
def test_basic_function_input(function_plotter, qtbot):
51-
"""
52-
Test plotting a basic function.
53-
"""
5451
function_plotter.function_input.setText("5*x^3 + 2*x")
5552
function_plotter.min_input.setText("0")
5653
function_plotter.max_input.setText("10")
@@ -70,9 +67,6 @@ def test_invalid_character_in_function(function_plotter, qtbot):
7067

7168

7269
def test_complex_formula_function(function_plotter, qtbot):
73-
"""
74-
Test plotting a complex formula function.
75-
"""
7670
function_plotter.function_input.setText("5*x^3 + 2*x - 4/x + 7")
7771
function_plotter.min_input.setText("-10")
7872
function_plotter.max_input.setText("10")
@@ -81,9 +75,6 @@ def test_complex_formula_function(function_plotter, qtbot):
8175

8276

8377
def test_using_sqrt_and_log10_in_function(function_plotter, qtbot):
84-
"""
85-
Test plotting a function using sqrt and log10.
86-
"""
8778
function_plotter.function_input.setText("2*x^4 - log10(x) + sqrt(x)")
8879
function_plotter.min_input.setText("0")
8980
function_plotter.max_input.setText("50")
@@ -114,9 +105,6 @@ def test_wrong_input_for_min_and_max_values(function_plotter, qtbot):
114105

115106

116107
def test_using_infinity_for_min_and_max_values(function_plotter, qtbot):
117-
"""
118-
Test plotting a function with -inf and +inf for min and max values.
119-
"""
120108
function_plotter.function_input.setText("x")
121109
function_plotter.min_input.setText("-inf")
122110
function_plotter.max_input.setText("inf")
@@ -125,11 +113,41 @@ def test_using_infinity_for_min_and_max_values(function_plotter, qtbot):
125113

126114

127115
def test_constant_function_formula(function_plotter, qtbot):
128-
"""
129-
Test plotting a constant function.
130-
"""
131116
function_plotter.function_input.setText("5")
132117
function_plotter.min_input.setText("-10")
133118
function_plotter.max_input.setText("10")
134119
qtbot.mouseClick(function_plotter.plot_button, Qt.LeftButton)
135-
assert function_plotter.ax.has_data()
120+
assert function_plotter.ax.has_data()
121+
122+
123+
def test_empty_function(function_plotter, qtbot):
124+
with qtbot.wait_signal(
125+
function_plotter.error_message_signal, timeout=5000
126+
) as blocker:
127+
function_plotter.function_input.setText("")
128+
function_plotter.min_input.setText("")
129+
function_plotter.max_input.setText("")
130+
qtbot.mouseClick(function_plotter.plot_button, Qt.LeftButton)
131+
assert blocker.args[0] == "Function cannot be empty."
132+
133+
134+
def test_min_greater_than_max(function_plotter, qtbot):
135+
with qtbot.wait_signal(
136+
function_plotter.error_message_signal, timeout=5000
137+
) as blocker:
138+
function_plotter.function_input.setText("x")
139+
function_plotter.min_input.setText("10")
140+
function_plotter.max_input.setText("5")
141+
qtbot.mouseClick(function_plotter.plot_button, Qt.LeftButton)
142+
assert blocker.args[0] == "Min value must be less than Max value."
143+
144+
145+
def test_empty_range_values(function_plotter, qtbot):
146+
with qtbot.wait_signal(
147+
function_plotter.error_message_signal, timeout=5000
148+
) as blocker:
149+
function_plotter.function_input.setText("x")
150+
function_plotter.min_input.setText("")
151+
function_plotter.max_input.setText("5")
152+
qtbot.mouseClick(function_plotter.plot_button, Qt.LeftButton)
153+
assert blocker.args[0] == "Min and Max values cannot be empty."

0 commit comments

Comments
 (0)