-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_node.py
52 lines (43 loc) · 1.57 KB
/
test_node.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
import pickle
import unittest
from node import Node
class TestRTreeNode(unittest.TestCase):
def test_knn(self):
b = Node(a=1, c=3, b=2)
d = Node(b=2000, m=55, children=[1, 2, 3])
self.assertEqual(d.m, 55)
self.assertEqual(d.children, [1, 2, 3])
self.assertEqual(d.size, 3)
self.assertEqual(b.children, [])
self.assertFalse(b.leaf)
self.assertFalse(b.hasattr("m"))
with self.assertRaises(Exception):
b.m
b.update(d)
self.assertDictEqual(
b, {'a' : 1, 'c': 3, 'b': 2000, 'leaf': False,
'm' : 55, 'height': 1,
'bbox' : [float('inf'), float('inf'), float('-inf'), float('-inf')],
'children': [1, 2, 3]}
)
with self.assertRaises(Exception):
hasattr(b, 'x')
self.assertFalse(b.hasattr('x'))
self.assertEqual(getattr(b, 'm'), 55)
self.assertTrue(hasattr(b, 'c'))
self.assertTrue(b.hasattr('c'))
self.assertEqual(
d, {'b' : 2000,
'leaf' : False,
'm' : 55,
'height' : 1,
'bbox' : [float('inf'), float('inf'), float('-inf'), float('-inf')],
'children': [1, 2, 3]
}
)
self.assertTrue(isinstance(b, dict))
self.assertEqual(b['b'], 2000)
self.assertDictEqual(pickle.loads(pickle.dumps(b)), b)
unittest.TextTestRunner(verbosity=10).run(
unittest.TestLoader().loadTestsFromTestCase(TestRTreeNode)
)