-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunction_plotter_test.py
84 lines (69 loc) · 3 KB
/
function_plotter_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import pytest
from function_plotter import MainWindow
@pytest.fixture
def main_window(qtbot):
window = MainWindow()
qtbot.addWidget(window)
return window
#test if inputs valid so no error
def test_valid_input(main_window):
main_window.functionInput.setText("10*x")
main_window.minValueInput.setText("1")
main_window.maxValueInput.setText("10")
main_window.plotButton.click()
assert main_window.errorMessageBox.isHidden() == True
def test_empty_inputs(main_window):
main_window.plotButton.click()
assert main_window.errorMessageBox.isHidden() == False
def test_invalid_function(main_window):
main_window.functionInput.setText("xy")
main_window.minValueInput.setText("1")
main_window.maxValueInput.setText("10")
main_window.plotButton.click()
assert main_window.errorMessageBox.isHidden() == False
#tes if user try to replace ^ by ** then it is error as we support ^ instead of **
def test_invalid_function(main_window):
main_window.functionInput.setText("x**2")
main_window.minValueInput.setText("1")
main_window.maxValueInput.setText("10")
main_window.plotButton.click()
assert main_window.errorMessageBox.isHidden() == False
def test_invalid_minValue(main_window):
main_window.functionInput.setText("10*x")
main_window.minValueInput.setText("h")
main_window.maxValueInput.setText("10")
main_window.plotButton.click()
assert main_window.errorMessageBox.isHidden() == False
def test_invalid_maxValue(main_window):
main_window.functionInput.setText("10*x")
main_window.minValueInput.setText("1")
main_window.maxValueInput.setText("msd")
main_window.plotButton.click()
assert main_window.errorMessageBox.isHidden() == False
# test if minValue smaller than maxValue
def test_maxValue_minVAlue(main_window):
main_window.functionInput.setText("10*x")
main_window.minValueInput.setText("10")
main_window.maxValueInput.setText("1")
main_window.plotButton.click()
assert main_window.errorMessageBox.isHidden() == False
#test if function enterd is constant function
def test_const_function(main_window):
main_window.functionInput.setText("10")
main_window.minValueInput.setText("1")
main_window.maxValueInput.setText("10")
main_window.plotButton.click()
assert main_window.errorMessageBox.isHidden() == True
#test clear button
def test_clear_button(main_window, qtbot):
main_window.functionInput.setText("x")
main_window.minValueInput.setText("0")
main_window.maxValueInput.setText("10")
main_window.plotButton.click()
main_window.clearButton.click()
canvas = main_window.canvas
ax = canvas.figure.axes[0]
assert main_window.functionInput.text() == ""
assert main_window.minValueInput.text() == ""
assert main_window.maxValueInput.text() == ""
assert ax.get_lines() == []