Skip to content

Commit cb1c13b

Browse files
committed
[Test] Add new tests
- Add tests for matrix methods (e.g. matrix.transpose)
1 parent 7f80d94 commit cb1c13b

File tree

2 files changed

+95
-3
lines changed

2 files changed

+95
-3
lines changed

python/tests/test_matrix_methods.py

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
import unittest
2+
import pycubool
3+
4+
5+
class TestMatrixMethods(unittest.TestCase):
6+
7+
def setUp(self) -> None:
8+
"""
9+
Preparatory actions
10+
Performed BEFORE tests
11+
"""
12+
13+
pass
14+
15+
def tearDown(self) -> None:
16+
"""
17+
Final actions
18+
Performed AFTER tests
19+
"""
20+
21+
pass
22+
23+
def test_fill(self):
24+
"""
25+
Unit test for creation and filling a matrix
26+
"""
27+
a = pycubool.Matrix.empty([4, 4])
28+
a_rows = [0, 1, 2, 3, 3, 3, 3]
29+
a_cols = [0, 1, 2, 0, 1, 2, 3]
30+
a.build(a_rows, a_cols, nvals=7)
31+
32+
dim = a.shape()
33+
rows, cols = a.to_lists()
34+
self.assertEqual(b.nvals, 7)
35+
self.assertListEqual([4, 4], dim)
36+
self.assertListEqual(rows, a_rows)
37+
self.assertListEqual(cols, a_cols)
38+
39+
def test_resize(self):
40+
"""
41+
Unit test for resizing a matrix
42+
"""
43+
a = pycubool.Matrix.empty([4, 4])
44+
a_rows = []
45+
a_cols = []
46+
a.build(a_rows, a_cols, nvals=0)
47+
48+
a.resize(5, 5)
49+
dim = a.shape()
50+
self.assertListEqual([5, 5], dim)
51+
52+
def test_duplicate(self):
53+
"""
54+
Unit test for duplication a matrix
55+
"""
56+
57+
a = pycubool.Matrix.empty([4, 4])
58+
a_rows = [0, 1, 2, 3, 3, 3, 3]
59+
a_cols = [0, 1, 2, 0, 1, 2, 3]
60+
a.build(a_rows, a_cols, nvals=7)
61+
62+
b = a.duplicate()
63+
64+
dim = b.shape()
65+
b_rows, b_cols = b.to_lists()
66+
self.assertEqual(b.nvals, 7)
67+
self.assertListEqual([4, 4], dim)
68+
self.assertListEqual(b_rows, a_rows)
69+
self.assertListEqual(b_cols, a_cols)
70+
71+
def test_transpose(self):
72+
"""
73+
Unit test for transposing a matrix
74+
"""
75+
76+
a = pycubool.Matrix.empty([2, 3])
77+
a_rows = [1, 0]
78+
a_cols = [0, 1]
79+
a.build(a_rows, a_cols, nvals=2)
80+
81+
b = a.transpose()
82+
83+
dim = b.shape()
84+
b_rows, b_cols = b.to_lists()
85+
self.assertEqual(b.nvals, 2)
86+
self.assertListEqual([3, 2], dim)
87+
self.assertListEqual(b_cols, a_rows)
88+
self.assertListEqual(b_rows, a_cols)
89+
90+
91+
if __name__ == "__main__":
92+
unittest.main()

python/tests/test_matrix_operation.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ def tearDown(self) -> None:
2222

2323
def test_add(self):
2424
"""
25-
Unit test for addition of two matrix
26-
"""
25+
Unit test for addition of two matrices
26+
"""
2727

2828
a = pycubool.Matrix.empty([4, 4])
2929
a_rows = [0, 1, 2, 3, 3, 3, 3]
@@ -44,7 +44,7 @@ def test_add(self):
4444

4545
def test_mxm(self):
4646
"""
47-
Unit test for multiplication of two matrix
47+
Unit test for multiplication of two matrices
4848
"""
4949

5050
a = pycubool.Matrix.empty([4, 4])

0 commit comments

Comments
 (0)