-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
120 lines (105 loc) · 3.86 KB
/
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
from main import*
#our test object
testObject = main()
#our test functions
def testEmpty():
assert testObject.expression == "", "Should be empty string"
print("Test 1 Passed")
def testErrors():
assert testObject.update_graph() == None, "Should be None"
testObject.expression = "sin(x)ghf"
assert testObject.update_graph() == None, "Shouldn't be None"
testObject.expression = "1+^*x"
assert testObject.update_graph() == None, "Shouldn't be None"
print("Test 2 Passed")
def testSin():
testObject.expression = "sin(x)"
plot, = testObject.update_graph()
x = np.arange(testObject.min, testObject.max, 0.1)
np.testing.assert_array_equal(plot.get_ydata(), np.sin(x))
print("Test 3 Passed")
def testSinh():
testObject.expression = "sinh(x)"
plot, = testObject.update_graph()
x = np.arange(testObject.min, testObject.max, 0.1)
np.testing.assert_array_equal(plot.get_ydata(), np.sinh(x))
print("Test 4 Passed")
def testCos():
testObject.expression = "cos(x)"
plot, = testObject.update_graph()
x = np.arange(testObject.min, testObject.max, 0.1)
np.testing.assert_array_equal(plot.get_ydata(), np.cos(x))
print("Test 5 Passed")
def testCosh():
testObject.expression = "cosh(x)"
plot, = testObject.update_graph()
x = np.arange(testObject.min, testObject.max, 0.1)
np.testing.assert_array_equal(plot.get_ydata(), np.cosh(x))
print("Test 6 Passed")
def testTan():
testObject.expression = "tan(x)"
plot, = testObject.update_graph()
x = np.arange(testObject.min, testObject.max, 0.1)
np.testing.assert_array_equal(plot.get_ydata(), np.tan(x))
print("Test 7 Passed")
def testTanh():
testObject.expression = "tanh(x)"
plot, = testObject.update_graph()
x = np.arange(testObject.min, testObject.max, 0.1)
np.testing.assert_array_equal(plot.get_ydata(), np.tanh(x))
print("Test 8 Passed")
def testAbs():
testObject.expression = "abs(x)"
plot, = testObject.update_graph()
x = np.arange(testObject.min, testObject.max, 0.1)
np.testing.assert_array_equal(plot.get_ydata(), np.abs(x))
print("Test 9 Passed")
def testLn():
testObject.expression = "ln(x)"
plot, = testObject.update_graph()
x = np.arange(testObject.min, testObject.max, 0.1)
np.testing.assert_array_equal(plot.get_ydata(), np.log(x))
print("Test 10 Passed")
def testLog():
testObject.expression = "log(x)"
plot, = testObject.update_graph()
x = np.arange(testObject.min, testObject.max, 0.1)
np.testing.assert_array_equal(plot.get_ydata(), np.log10(x))
print("Test 11 Passed")
def testSqrt():
testObject.expression = "sqrt(x)"
plot, = testObject.update_graph()
x = np.arange(testObject.min, testObject.max, 0.1)
np.testing.assert_array_equal(plot.get_ydata(), np.sqrt(x))
print("Test 12 Passed")
def testPolynomail():
testObject.expression = "5*x**3 + 2*x"
plot, = testObject.update_graph()
x = np.arange(testObject.min, testObject.max, 0.1)
np.testing.assert_array_equal(plot.get_ydata(), 5*x**3+2*x)
print("Test 13 Passed")
def testAll():
testObject.expression = "sin(x+pi/e+cos(tan(x**2)))"
plot, = testObject.update_graph()
x = np.arange(testObject.min, testObject.max, 0.1)
np.testing.assert_array_equal(plot.get_ydata(),np.sin(x+np.pi/np.e+np.cos(np.tan(x**2))))
print("Test 14 Passed")
#our main function
if __name__ == "__main__":
testObject.min = -10
testObject.max = 10
testEmpty()
testErrors()
testSin()
testSinh()
testCos()
testCosh()
testTanh()
testTan()
testAbs()
testLn()
testLog()
testSqrt()
testPolynomail()
testAll()
print("Passed All Tests")