-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_distance_matrix_generate.py
79 lines (58 loc) · 1.87 KB
/
test_distance_matrix_generate.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
"""
Updated: 2017
Author: Sergei Shliakhtin
Contact: [email protected]
Notes:
"""
import numpy as np
import unittest
from graph_algos import INF
from graph_algos.distance_matrix_generate import triple_dist_oneb, triple_dist_zerob, half_mx_dist
class TestGenerate(unittest.TestCase):
def test_triple_zerob(self):
mx1 = np.array([(0, 1, 7), (1, 2, 8)])
mx1 = triple_dist_zerob(triples=mx1, num_vx=3)
check = np.array([
[INF, 7, INF],
[7, INF, 8],
[INF, 8, INF],
])
self.assertEqual(np.ma.allequal(mx1, check), True)
def test_triple_oneb(self):
mx1 = np.array([(1, 2, 10), (1, 4, 20), (1, 3, 15)])
mx1 = triple_dist_oneb(triples=mx1, num_vx=4)
check = np.array([[INF, 10, 15, 20],
[10, INF, INF, INF],
[15, INF, INF, INF],
[20, INF, INF, INF],
])
self.assertEqual(np.ma.allequal(mx1, check), True)
def test_triple_oneb_double(self):
mx1 = np.array([(1, 2), (2, 3)])
mx1 = triple_dist_oneb(triples=mx1, num_vx=3)
check = np.array([
[INF, 1, INF],
[1, INF, 1],
[INF, 1, INF],
])
self.assertEqual(np.ma.allequal(mx1, check), True)
def test_half_mx_dist(self):
half_mx = np.array([
[0, 1, 2],
[3, 4],
[5],
])
mx1 = half_mx_dist(half_mx)
check = np.array([
[INF, 0, 1, 2],
[0, INF, 3, 4],
[1, 3, INF, 5],
[2, 4, 5, INF],
] )
self.assertTrue(np.ma.allequal(mx1, check))
def setUp(self):
pass
def tearDown(self):
pass
suite = unittest.TestLoader().loadTestsFromTestCase(TestGenerate)
unittest.TextTestRunner(verbosity=2).run(suite)