-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.py
70 lines (57 loc) · 2.04 KB
/
tests.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
import unittest
from function import *
import errors
class TestDer(unittest.TestCase):
def setUp(self):
self.x, self.y, self.z = var('x'), var('y'), var('z')
x = self.x
self.fs = [
(5 * x ** 2 + 3 * x + 4,
5 * (2 * x) + 3),
(x ** 2 * sin(x),
2 * x * sin(x) + x ** 2 * cos(x)),
((x ** 2 + cos(x)) ** 0.5,
0.5 * (x ** 2 + cos(x)) ** (-0.5) * (2 * x + (-sin(x))))
]
def test_derivatives(self):
for i in self.fs:
self.assertEqual(i[0].derivative(self.x), i[1])
def test_create_function(self):
f = create_function(
lambda x, y: (x ** 5 + y * sin(x * y)) + log(y, 7 / x))
x = self.x
y = self.y
self.assertEqual(f, (x ** 5 + (y * sin(x * y)) + log(y, 7 / x)))
def test_mult_var_der(self):
f = create_function(
lambda x, y: x ** 5 + y * sin(x * y) + log(y, 7 / x))
g = f.derivative('y')
def test_antider_const(self):
const = 3
fconst = create_const(const)
self.assertEqual(fconst.antiderivative(self.x), fconst * self.x)
def test_antider_mult(self):
x = self.x
f = x ** 2 - 2 * x + 5
self.assertEqual(
x ** 3 / 3 - 2 * (x ** 2 / 2) + 5 * x, f.antiderivative())
def test_get_multipliers(self):
x = self.x
y = self.y
f = 2 * x ** 3 * (x + y) ** 5 / (x / y)
g = {'down': {x: 1}, 'up': {y: 1, x: 3, create_const(2): 1, x + y: 5}}
self.assertEqual(f.get_multipliers(), g)
def test_simplify_mult(self):
x = self.x
f = x ** 3 / x / x
self.assertEqual(f.simplify_mult(), x)
f = x / x
self.assertEqual(f.simplify_mult(), create_const(1))
f = 2 * (x ** 2 / 2)
self.assertEqual(f.simplify_mult(), x ** 2)
def test_simplify_sum(self):
x = self.x
y = self.y
self.assertEqual((x + 6 * 9 * y - 5 + x).simplify_sum(), 54 * y + 2 * x - 5)
if __name__ == '__main__':
unittest.main()