-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
executable file
·37 lines (30 loc) · 1015 Bytes
/
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
#!/bin/env python3
import operations
import unittest
from exptree import ExpTree
from fit import sse
import numpy as np
class TestSSE(unittest.TestCase):
def test_sse1(self):
f = lambda x: x*2
xd = np.array([1, 2, 3])
yd = np.array([2, 4, 6])
self.assertEqual(sse(f, xd, yd), 0)
yd = np.array([2, 3, 3])
self.assertEqual(sse(f, xd, yd), 10)
def test_sse2(self):
''' Make sure we can mix ints and floats '''
f = lambda x: x*2
xd = np.array([1])
yd = np.array([2.5])
self.assertEqual(sse(f, xd, yd), 0.25)
class TestExpTree(unittest.TestCase):
def test_deepcopy(self):
tree = ExpTree()
tree.apply_binary_op(tree.root, operations.add)
tree2 = tree.copy()
self.assertEqual(str(tree), str(tree2))
tree2.apply_binary_op(tree2.root.lhs, operations.mul)
self.assertNotEqual(str(tree), str(tree2))
if __name__ == "__main__":
unittest.main()