-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_euclidMST.py
124 lines (92 loc) · 3.41 KB
/
test_euclidMST.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
121
122
123
124
from unittest import TestCase
import numpy as np
from EuclidMST import EuclidMST
__author__ = 'herman'
class EuclidMST_instZ(TestCase):
def setUp(self):
segList = np.array([[[0, 0], [3, 0]], [[2, 1], [5, 1]]])
self.euclidmst = EuclidMST(segList)
class TestEuclidMSTZ(EuclidMST_instZ):
def runTest(self):
self.assertEqual(self.euclidmst.size, 4)
d = self.euclidmst.spnTree.sum()
d /= 2 # spnTree is undirected, so sum is 2x expected
self.assertAlmostEqual(d, 2)
class EuclidMST_instY(TestCase):
def setUp(self):
segList = np.array([[[0, 3], [1, 3]], [[3, 3], [4, 3]], [[2, 0], [2, 2]]])
self.euclidmst = EuclidMST(segList)
class TestEuclidMSTY(EuclidMST_instY):
def runTest(self):
self.assertEqual(self.euclidmst.size, 6)
d = self.euclidmst.spnTree.sum()
d /= 2 # spnTree is undirected, so sum is 2x expected
self.assertAlmostEqual(d, 4)
class TestEuclidMST_dfo(EuclidMST_instY):
def runTest(self):
tree = self.euclidmst.dfo_nonrec(0)
self.euclidmst.treetrav_nonrec(tree)
self.assertEqual(len(self.euclidmst.nodeTrav), 11)
class EuclidMST_instW(TestCase):
def setUp(self):
segList = np.array([[[1, 3]], [[3, 3], [4, 3]], [[2, 0], [2, 2]]])
self.euclidmst = EuclidMST(segList)
class TestEuclidMST_pt(EuclidMST_instW):
def runTest(self):
self.assertEqual(self.euclidmst.size, 5)
d = self.euclidmst.spnTree.sum()
d /= 2
self.assertAlmostEqual(d, 4)
tree = self.euclidmst.dfo_nonrec(0)
self.euclidmst.treetrav_nonrec(tree)
self.assertAlmostEqual(len(self.euclidmst.nodeTrav), 9)
class EuclidMST_instV(TestCase):
def setUp(self):
segList = np.array([[[1, 3]], [[3, 3]], [[2, 0]]])
self.euclidmst = EuclidMST(segList)
class TestEuclidMST_pts(EuclidMST_instV):
def runTest(self):
self.assertEqual(self.euclidmst.size, 3)
d = self.euclidmst.spnTree.sum()
d /= 2
self.assertAlmostEqual(d, 14)
tree = self.euclidmst.dfo_nonrec(0)
self.euclidmst.treetrav_nonrec(tree)
self.assertAlmostEqual(len(self.euclidmst.nodeTrav), 5)
class EuclidMST_instU(TestCase):
def setUp(self):
segList = np.array([[[3, 3], [4, 3]], [[2, 0], [2, 2]], [[1, 3]]])
self.euclidmst = EuclidMST(segList)
class TestEuclidMST_ptsU(EuclidMST_instU):
def runTest(self):
self.assertEqual(self.euclidmst.size, 5)
d = self.euclidmst.spnTree.sum()
d /= 2
self.assertAlmostEqual(d, 4)
tree = self.euclidmst.dfo_nonrec(0)
self.euclidmst.treetrav_nonrec(tree)
self.assertAlmostEqual(len(self.euclidmst.nodeTrav), 9)
class EuclidMST_inst100(TestCase):
def setUp(self):
l = []
for x in range(0, 100):
l.append([[x, 0], [x, 1]])
segList = np.array(l)
self.euclidmst = EuclidMST(segList)
class TestEuclidMST_100(EuclidMST_inst100):
def runTest(self):
# Shouldn't crash
self.euclidmst.segmentOrdering()
'''
class EuclidMST_instDEEP(TestCase):
def setUp(self):
l = []
for x in xrange(0, 10000):
l.append([[x, 0], [x, 1]])
segList = np.array(l)
self.euclidmst = EuclidMST(segList)
class TestEuclidMST_deep(EuclidMST_instDEEP):
def runTest(self):
# Shouldn't crash
self.euclidmst.segmentOrdering()
'''