-
Notifications
You must be signed in to change notification settings - Fork 0
/
testnpgraph.py
51 lines (38 loc) · 1.26 KB
/
testnpgraph.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
import unittest
from numpy.testing import assert_array_almost_equal as aa
import numpy as np
from numpy import nan
from npgraph import djs, nbr_idx, uniq_path
A = np.array
class TestGraph(unittest.TestCase):
def setUp(self):
pass
def test_aanbr_idx(self):
_In = np.array([[0, nan, 2],
[nan, 0, 5],
[2, 5, 0]])
aa(nbr_idx(_In, 0), A([2]))
aa(nbr_idx(_In, 1), A([2]))
aa(nbr_idx(_In, 2), A([0, 1]))
def test_alg_n1(self):
_In = np.array([[0, 2],
[2, 0]])
aa(djs(_In)[0], A([nan, 0]))
aa(djs(_In)[1], A([0, 2]))
def test_alg_n2(self):
_In = np.array([[0, nan, 2],
[nan, 0, 5],
[2, 5, 0]])
aa(djs(_In)[0], A([nan, 2, 0]))
aa(djs(_In)[1], A([0, 7, 2]))
class TestUniqPath(unittest.TestCase):
def test_alg_n2_uniq(self):
_In = np.array([[0, nan, 2],
[nan, 0, 5],
[2, 5, 0]])
actual = uniq_path(_In, 2)
self.assertListEqual(actual, [0, 2] )
actual = uniq_path(_In, 1)
self.assertListEqual(actual, [0, 2, 1] )
if __name__ == '__main__':
unittest.main()