Skip to content

Commit 7f80d94

Browse files
committed
[Test] Add some tests
- Added test for addition of matrices - Added test for multiply of matrices
1 parent cafdf13 commit 7f80d94

File tree

4 files changed

+90
-0
lines changed

4 files changed

+90
-0
lines changed

python/.idea/.gitignore

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

python/.idea/inspectionProfiles/Project_Default.xml

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

python/.idea/inspectionProfiles/profiles_settings.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

python/tests/test_matrix_operation.py

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import unittest
2+
import pycubool
3+
4+
5+
class TestMatrixOperations(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_add(self):
24+
"""
25+
Unit test for addition of two matrix
26+
"""
27+
28+
a = pycubool.Matrix.empty([4, 4])
29+
a_rows = [0, 1, 2, 3, 3, 3, 3]
30+
a_cols = [0, 1, 2, 0, 1, 2, 3]
31+
a.build(a_rows, a_cols, nvals=7)
32+
33+
b = pycubool.Matrix.empty([4, 4])
34+
b_rows = []
35+
b_cols = []
36+
b.build(b_rows, b_cols, nvals=0)
37+
38+
pycubool.add(b, a)
39+
rows, cols = b.to_lists()
40+
41+
self.assertEqual(b.nvals, 7)
42+
self.assertListEqual(rows, a_rows)
43+
self.assertListEqual(cols, a_cols)
44+
45+
def test_mxm(self):
46+
"""
47+
Unit test for multiplication of two matrix
48+
"""
49+
50+
a = pycubool.Matrix.empty([4, 4])
51+
a_rows = [0, 1, 2, 3, 3, 3, 3]
52+
a_cols = [0, 1, 2, 0, 1, 2, 3]
53+
a.build(a_rows, a_cols, nvals=7)
54+
55+
b = pycubool.Matrix.empty([4, 4])
56+
b_rows = [0, 1]
57+
b_cols = [0, 1]
58+
b.build(b_rows, b_cols, nvals=2)
59+
60+
pycubool.mxm(b, b, a)
61+
rows, cols = b.to_lists()
62+
63+
self.assertEqual(b.nvals, 2)
64+
self.assertListEqual(rows, b_rows)
65+
self.assertListEqual(cols, b_cols)
66+
67+
68+
if __name__ == "__main__":
69+
unittest.main()

0 commit comments

Comments
 (0)