@@ -43,174 +43,93 @@ def function_plotter(app_instance, qtbot):
43
43
return plotter
44
44
45
45
46
- # good input tests
46
+ # test functions
47
47
48
48
49
- def test_valid_function_input (function_plotter , qtbot ):
50
- """
51
- Test plotting a valid function.
52
- """
53
- function_plotter .function_input .setText ("5*x^3 + 2*x" )
54
- function_plotter .min_input .setText ("0" )
55
- function_plotter .max_input .setText ("10" )
56
- qtbot .mouseClick (function_plotter .plot_button , Qt .LeftButton )
57
- assert function_plotter .ax .has_data ()
58
-
59
-
60
- def test_function_with_logarithm (function_plotter , qtbot ):
61
- """
62
- Test plotting a function with a logarithm.
63
- """
64
- function_plotter .function_input .setText ("log10(x)" )
65
- function_plotter .min_input .setText ("1" )
66
- function_plotter .max_input .setText ("100" )
67
- qtbot .mouseClick (function_plotter .plot_button , Qt .LeftButton )
68
- assert function_plotter .ax .has_data ()
69
-
70
49
71
- def test_function_with_square_root (function_plotter , qtbot ):
50
+ def test_basic_function_input (function_plotter , qtbot ):
72
51
"""
73
- Test plotting a function with a square root .
52
+ Test plotting a basic function .
74
53
"""
75
- function_plotter .function_input .setText ("sqrt(x) " )
54
+ function_plotter .function_input .setText ("5*x^3 + 2*x " )
76
55
function_plotter .min_input .setText ("0" )
77
- function_plotter .max_input .setText ("25" )
78
- qtbot .mouseClick (function_plotter .plot_button , Qt .LeftButton )
79
- assert function_plotter .ax .has_data ()
80
-
81
-
82
- def test_function_with_combined_operators (function_plotter , qtbot ):
83
- """
84
- Test plotting a function with combined operators.
85
- """
86
- function_plotter .function_input .setText ("sqrt(x) + log10(x) + x^2" )
87
- function_plotter .min_input .setText ("1" )
88
56
function_plotter .max_input .setText ("10" )
89
57
qtbot .mouseClick (function_plotter .plot_button , Qt .LeftButton )
90
58
assert function_plotter .ax .has_data ()
91
59
92
60
93
- def test_large_range_of_x (function_plotter , qtbot ):
94
- """
95
- Test plotting a function over a large range of x values.
96
- """
97
- function_plotter .function_input .setText ("x^2" )
98
- function_plotter .min_input .setText ("-1000" )
99
- function_plotter .max_input .setText ("1000" )
100
- qtbot .mouseClick (function_plotter .plot_button , Qt .LeftButton )
101
- assert function_plotter .ax .has_data ()
102
-
103
-
104
- def test_small_range_of_x (function_plotter , qtbot ):
105
- """
106
- Test plotting a function over a small range of x values.
107
- """
108
- function_plotter .function_input .setText ("x^2" )
109
- function_plotter .min_input .setText ("0" )
110
- function_plotter .max_input .setText ("1" )
111
- qtbot .mouseClick (function_plotter .plot_button , Qt .LeftButton )
112
- assert function_plotter .ax .has_data ()
113
-
114
-
115
- def test_negative_x_values (function_plotter , qtbot ):
116
- """
117
- Test plotting a function with negative x values.
118
- """
119
- function_plotter .function_input .setText ("x^3" )
120
- function_plotter .min_input .setText ("-10" )
121
- function_plotter .max_input .setText ("0" )
122
- qtbot .mouseClick (function_plotter .plot_button , Qt .LeftButton )
123
- assert function_plotter .ax .has_data ()
61
+ def test_invalid_character_in_function (function_plotter , qtbot ):
62
+ with qtbot .wait_signal (
63
+ function_plotter .error_message_signal , timeout = 5000
64
+ ) as blocker :
65
+ function_plotter .function_input .setText ("5*x^3 + 2*x + !" )
66
+ function_plotter .min_input .setText ("0" )
67
+ function_plotter .max_input .setText ("10" )
68
+ qtbot .mouseClick (function_plotter .plot_button , Qt .LeftButton )
69
+ assert blocker .args [0 ] == "Function contains invalid characters."
124
70
125
71
126
- def test_high_degree_polynomial (function_plotter , qtbot ):
72
+ def test_complex_formula_function (function_plotter , qtbot ):
127
73
"""
128
- Test plotting a high-degree polynomial function.
74
+ Test plotting a complex formula function.
129
75
"""
130
- function_plotter .function_input .setText ("x^6 - 2*x^4 + x^2 " )
76
+ function_plotter .function_input .setText ("5*x^3 + 2*x - 4/x + 7 " )
131
77
function_plotter .min_input .setText ("-10" )
132
78
function_plotter .max_input .setText ("10" )
133
79
qtbot .mouseClick (function_plotter .plot_button , Qt .LeftButton )
134
80
assert function_plotter .ax .has_data ()
135
81
136
82
137
- def test_floating_point_coefficients (function_plotter , qtbot ):
83
+ def test_using_sqrt_and_log10_in_function (function_plotter , qtbot ):
138
84
"""
139
- Test floating point coefficients function.
85
+ Test plotting a function using sqrt and log10 .
140
86
"""
141
- function_plotter .function_input .setText ("0.5*x^2 + 2.5*x" )
142
- function_plotter .min_input .setText ("-5" )
143
- function_plotter .max_input .setText ("5" )
144
- qtbot .mouseClick (function_plotter .plot_button , Qt .LeftButton )
145
- assert function_plotter .ax .has_data ()
146
-
147
-
148
- def test_function_with_spaces (function_plotter , qtbot ):
149
- """
150
- Test function with spaces.
151
- """
152
- function_plotter .function_input .setText (" x ^ 2 + 3 * x " )
153
- function_plotter .min_input .setText ("-5" )
154
- function_plotter .max_input .setText ("5" )
87
+ function_plotter .function_input .setText ("2*x^4 - log10(x) + sqrt(x)" )
88
+ function_plotter .min_input .setText ("0" )
89
+ function_plotter .max_input .setText ("50" )
155
90
qtbot .mouseClick (function_plotter .plot_button , Qt .LeftButton )
156
91
assert function_plotter .ax .has_data ()
157
92
158
93
159
- # bad input tests
160
-
161
-
162
- def test_invalid_function_input_characters (function_plotter , qtbot ):
94
+ def test_negative_input_to_sqrt_or_log10 (function_plotter , qtbot ):
163
95
with qtbot .wait_signal (
164
96
function_plotter .error_message_signal , timeout = 5000
165
97
) as blocker :
166
- function_plotter .function_input .setText ("5 *x^3 + 2*x + ! " )
167
- function_plotter .min_input .setText ("0 " )
168
- function_plotter .max_input .setText ("10 " )
98
+ function_plotter .function_input .setText ("2 *x^4 - log10(x) + sqrt(x) " )
99
+ function_plotter .min_input .setText ("-50 " )
100
+ function_plotter .max_input .setText ("500 " )
169
101
qtbot .mouseClick (function_plotter .plot_button , Qt .LeftButton )
170
- assert blocker .args [0 ] == "Function contains invalid characters ."
102
+ assert blocker .args [0 ] == "Min value must be non-negative for functions with log10 or sqrt ."
171
103
172
104
173
- def test_empty_function_input (function_plotter , qtbot ):
105
+ def test_wrong_input_for_min_and_max_values (function_plotter , qtbot ):
174
106
with qtbot .wait_signal (
175
107
function_plotter .error_message_signal , timeout = 5000
176
108
) as blocker :
177
- function_plotter .function_input .setText ("" )
178
- function_plotter .min_input .setText ("0" )
179
- function_plotter .max_input .setText ("10" )
180
- qtbot .mouseClick (function_plotter .plot_button , Qt .LeftButton )
181
- assert blocker .args [0 ] == "Function cannot be empty."
182
-
183
-
184
- def test_invalid_min_max_values (function_plotter , qtbot ):
185
- with qtbot .wait_signal (
186
- function_plotter .error_message_signal , timeout = 5000
187
- ) as blocker :
188
- function_plotter .function_input .setText ("5*x^3 + 2*x" )
189
- function_plotter .min_input .setText ("10" )
190
- function_plotter .max_input .setText ("0" )
191
- qtbot .mouseClick (function_plotter .plot_button , Qt .LeftButton )
192
- assert blocker .args [0 ] == "Min value must be less than Max value."
193
-
194
-
195
- def test_non_numeric_min_max_values (function_plotter , qtbot ):
196
- with qtbot .wait_signal (
197
- function_plotter .error_message_signal , timeout = 5000
198
- ) as blocker :
199
- function_plotter .function_input .setText ("5*x^3 + 2*x" )
109
+ function_plotter .function_input .setText ("x" )
200
110
function_plotter .min_input .setText ("a" )
201
- function_plotter .max_input .setText ("b " )
111
+ function_plotter .max_input .setText ("2 " )
202
112
qtbot .mouseClick (function_plotter .plot_button , Qt .LeftButton )
203
113
assert blocker .args [0 ] == "Min and Max values must be numbers."
204
114
205
115
206
- def test_empty_min_max_values (function_plotter , qtbot ):
207
- with qtbot . wait_signal (
208
- function_plotter . error_message_signal , timeout = 5000
209
- ) as blocker :
210
- function_plotter .function_input .setText ("x^2 " )
211
- function_plotter .min_input .setText ("" )
212
- function_plotter .max_input .setText ("" )
213
- qtbot .mouseClick (function_plotter .plot_button , Qt .LeftButton )
214
- assert blocker . args [ 0 ] == "Min and Max values cannot be empty."
116
+ 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
+ """
120
+ function_plotter .function_input .setText ("x" )
121
+ function_plotter .min_input .setText ("-inf " )
122
+ function_plotter .max_input .setText ("inf " )
123
+ qtbot .mouseClick (function_plotter .plot_button , Qt .LeftButton )
124
+ assert function_plotter . ax . has_data ()
215
125
216
126
127
+ def test_constant_function_formula (function_plotter , qtbot ):
128
+ """
129
+ Test plotting a constant function.
130
+ """
131
+ function_plotter .function_input .setText ("5" )
132
+ function_plotter .min_input .setText ("-10" )
133
+ function_plotter .max_input .setText ("10" )
134
+ qtbot .mouseClick (function_plotter .plot_button , Qt .LeftButton )
135
+ assert function_plotter .ax .has_data ()
0 commit comments