[ea0fd6]: / tests / edgepy / test_compressMatrix.py

Download this file

58 lines (49 with data), 1.9 kB

 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
import unittest
import numpy as np
from inmoose.edgepy.makeCompressedMatrix import makeCompressedMatrix
class Test(unittest.TestCase):
def test_makeCompressedMatrix(self):
self.assertTrue(
np.array_equal(
makeCompressedMatrix(42, dims=(2, 3), byrow=True), np.full((2, 3), 42)
)
)
self.assertTrue(
np.array_equal(
makeCompressedMatrix(42, dims=(2, 3), byrow=False), np.full((2, 3), 42)
)
)
ref = np.array([[1, 2, 3] for i in range(2)])
self.assertTrue(
np.array_equal(
makeCompressedMatrix([1, 2, 3], dims=(2, 3), byrow=True), ref
)
)
self.assertTrue(
np.array_equal(
makeCompressedMatrix([1, 2, 3], dims=(3, 2), byrow=False), ref.T
)
)
with self.assertRaisesRegex(
ValueError, expected_regex="dims\[.\] should be equal to length of x"
):
makeCompressedMatrix([1, 2, 3], dims=(3, 2), byrow=True)
with self.assertRaisesRegex(
ValueError, expected_regex="dims\[.\] should be equal to length of x"
):
makeCompressedMatrix([1, 2, 3], dims=(2, 3), byrow=False)
with self.assertRaisesRegex(
ValueError, expected_regex="dims does not represent the shape of a matrix"
):
makeCompressedMatrix(42, dims=(5,))
with self.assertRaisesRegex(
ValueError, expected_regex="dims does not represent the shape of a matrix"
):
makeCompressedMatrix(42, dims=(1, 2, 3))
with self.assertRaisesRegex(
ValueError,
expected_regex="input has too many dimensions to be interpreted as a matrix",
):
makeCompressedMatrix(np.ones(shape=(1, 2, 3)), dims=(2, 3))
if __name__ == "__main__":
unittest.main()