Switch to unified view

a b/tests/edgepy/test_compressMatrix.py
1
import unittest
2
3
import numpy as np
4
5
from inmoose.edgepy.makeCompressedMatrix import makeCompressedMatrix
6
7
8
class Test(unittest.TestCase):
9
    def test_makeCompressedMatrix(self):
10
        self.assertTrue(
11
            np.array_equal(
12
                makeCompressedMatrix(42, dims=(2, 3), byrow=True), np.full((2, 3), 42)
13
            )
14
        )
15
        self.assertTrue(
16
            np.array_equal(
17
                makeCompressedMatrix(42, dims=(2, 3), byrow=False), np.full((2, 3), 42)
18
            )
19
        )
20
21
        ref = np.array([[1, 2, 3] for i in range(2)])
22
        self.assertTrue(
23
            np.array_equal(
24
                makeCompressedMatrix([1, 2, 3], dims=(2, 3), byrow=True), ref
25
            )
26
        )
27
        self.assertTrue(
28
            np.array_equal(
29
                makeCompressedMatrix([1, 2, 3], dims=(3, 2), byrow=False), ref.T
30
            )
31
        )
32
33
        with self.assertRaisesRegex(
34
            ValueError, expected_regex="dims\[.\] should be equal to length of x"
35
        ):
36
            makeCompressedMatrix([1, 2, 3], dims=(3, 2), byrow=True)
37
        with self.assertRaisesRegex(
38
            ValueError, expected_regex="dims\[.\] should be equal to length of x"
39
        ):
40
            makeCompressedMatrix([1, 2, 3], dims=(2, 3), byrow=False)
41
        with self.assertRaisesRegex(
42
            ValueError, expected_regex="dims does not represent the shape of a matrix"
43
        ):
44
            makeCompressedMatrix(42, dims=(5,))
45
        with self.assertRaisesRegex(
46
            ValueError, expected_regex="dims does not represent the shape of a matrix"
47
        ):
48
            makeCompressedMatrix(42, dims=(1, 2, 3))
49
        with self.assertRaisesRegex(
50
            ValueError,
51
            expected_regex="input has too many dimensions to be interpreted as a matrix",
52
        ):
53
            makeCompressedMatrix(np.ones(shape=(1, 2, 3)), dims=(2, 3))
54
55
56
if __name__ == "__main__":
57
    unittest.main()