Skip to content

Commit f4c3651

Browse files
committed
[Test] Add new tests for python wrapper
- Add test for all methods for matrix (matrix.py) except of: - Matrix.empty() - Matrix.from_lists() - matrix.build() - matrix.to_string() - matrix.__str__() - matrix.__iter__() - matrix.__getitem__() - matrix.__init__() - matrix.__del__()
1 parent dc553ae commit f4c3651

12 files changed

+239
-161
lines changed

python/tests/test_duplicate.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import unittest
2+
import test_utils
3+
4+
5+
class TestMatrixDuplicate(unittest.TestCase):
6+
def test_duplicate(self):
7+
"""
8+
Unit test for duplicate of matrix
9+
"""
10+
first_matrix = test_utils.build_matrix_from_file("/matrices/duplicate.txt")
11+
12+
actual_matrix = first_matrix.dup()
13+
14+
self.assertTrue(test_utils.compare_matrix(first_matrix, actual_matrix))
15+
16+
17+
if __name__ == "__main__":
18+
unittest.main()

python/tests/test_extract_matrix.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import unittest
2+
import test_utils
3+
4+
5+
class TestMatrixExtractMatrix(unittest.TestCase):
6+
def test_extract_matrix(self):
7+
"""
8+
Unit test for extract submatrix from left-upper corner of matrix
9+
"""
10+
first_matrix = test_utils.build_matrix_from_file("/matrices/extract_matrix.txt")
11+
expected_matrix = test_utils.build_matrix_from_file("/matrices/extract_matrix_result.txt")
12+
13+
actual_matrix = first_matrix.extract_matrix(0, 0, expected_matrix.shape)
14+
15+
self.assertTrue(expected_matrix, actual_matrix)
16+
17+
18+
if __name__ == "__main__":
19+
unittest.main()

python/tests/test_kronecker.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import unittest
2+
import test_utils
3+
4+
5+
class TestMatrixKronecker(unittest.TestCase):
6+
def test_kronecker(self):
7+
"""
8+
Unit test for kronecker product of two matrices
9+
"""
10+
first_matrix = test_utils.build_matrix_from_file("/matrices/kronecker_4.txt")
11+
second_matrix = test_utils.build_matrix_from_file("/matrices/kronecker_5.txt")
12+
13+
actual_matrix = first_matrix.kronecker(second_matrix)
14+
expected_matrix = test_utils.build_matrix_from_file("/matrices/kronecker_result.txt")
15+
16+
self.assertTrue(test_utils.compare_matrix(expected_matrix, actual_matrix))
17+
18+
19+
if __name__ == "__main__":
20+
unittest.main()

python/tests/test_matrix_add.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import unittest
2+
import test_utils
3+
4+
5+
class TestMatrixAdd(unittest.TestCase):
6+
def test_add(self):
7+
"""
8+
Unit test for addition of two matrices
9+
"""
10+
first_matrix = test_utils.build_matrix_from_file("/matrices/add_1.txt")
11+
second_matrix = test_utils.build_matrix_from_file("/matrices/add_2.txt")
12+
13+
actual_matrix = first_matrix.ewiseadd(second_matrix)
14+
expected_matrix = test_utils.build_matrix_from_file("/matrices/add_result.txt")
15+
16+
self.assertTrue(test_utils.compare_matrix(expected_matrix, actual_matrix))
17+
18+
19+
if __name__ == "__main__":
20+
unittest.main()

python/tests/test_matrix_methods.py

Lines changed: 0 additions & 92 deletions
This file was deleted.

python/tests/test_matrix_mxm.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import unittest
2+
import test_utils
3+
4+
5+
class TestMatrixMxm(unittest.TestCase):
6+
def test_mxm(self):
7+
"""
8+
Unit test for multiplication of two matrices
9+
"""
10+
first_matrix = test_utils.build_matrix_from_file("/matrices/mxm_1.txt")
11+
second_matrix = test_utils.build_matrix_from_file("/matrices/mxm_2.txt")
12+
13+
actual_matrix = first_matrix.mxm(second_matrix)
14+
expected_matrix = test_utils.build_matrix_from_file("/matrices/mxm_result.txt")
15+
16+
self.assertTrue(test_utils.compare_matrix(expected_matrix, actual_matrix))
17+
18+
19+
if __name__ == "__main__":
20+
unittest.main()

python/tests/test_matrix_operation.py

Lines changed: 0 additions & 69 deletions
This file was deleted.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import unittest
2+
import test_utils
3+
4+
5+
class TestMatrixMethods(unittest.TestCase):
6+
7+
def setUp(self) -> None:
8+
self.matrix = test_utils.build_matrix_from_file("/matrices/property.txt")
9+
self.result_property = list()
10+
with open("/matrices/property_result.txt", 'r') as _file:
11+
line = list(map(int, _file.readline().split()))
12+
self.result_property.append(line)
13+
14+
def tearDown(self) -> None:
15+
"""
16+
Final actions
17+
Performed AFTER tests
18+
"""
19+
20+
pass
21+
22+
def test_nrows(self):
23+
self.assertEqual(self.result_property[0][0], self.matrix.nrows)
24+
25+
def test_ncols(self):
26+
self.assertEqual(self.result_property[1][0], self.matrix.ncols)
27+
28+
def test_nvals(self):
29+
self.assertEqual(self.result_property[2][0], self.matrix.nvals)
30+
31+
def test_shape(self):
32+
self.assertEqual(self.result_property[0], self.matrix.shape)
33+
34+
35+
if __name__ == "__main__":
36+
unittest.main()

python/tests/test_reduce.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import unittest
2+
import test_utils
3+
4+
5+
class TestMatrixReduce(unittest.TestCase):
6+
def test_reduce(self):
7+
"""
8+
Unit test for reduce of matrix
9+
"""
10+
first_matrix = test_utils.build_matrix_from_file("/matrices/reduce.txt")
11+
12+
actual_matrix = first_matrix.reduce()
13+
expected_matrix = test_utils.build_matrix_from_file("/matrices/reduce_result.txt")
14+
15+
self.assertTrue(test_utils.compare_matrix(expected_matrix, actual_matrix))
16+
17+
18+
if __name__ == "__main__":
19+
unittest.main()

python/tests/test_to_lists.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import unittest
2+
import test_utils
3+
4+
5+
class TestMatrixToLists(unittest.TestCase):
6+
def setUp(self) -> None:
7+
self.matrix = test_utils.build_matrix_from_file("/matrices/to_lists.txt")
8+
self.result_lists = list()
9+
with open("/matrices/to_lists_result.txt", 'r') as _file:
10+
line = list(map(int, _file.readline().split()))
11+
self.result_lists.append(line)
12+
13+
def test_to_lists(self):
14+
"""
15+
Unit test to extract a matrix as two lists
16+
"""
17+
18+
actual_rows, actual_cols = self.matrix.to_lists()
19+
20+
self.assertListEqual(self.result_lists[0], actual_rows)
21+
self.assertListEqual(self.result_lists[1], actual_cols)
22+
23+
24+
if __name__ == "__main__":
25+
unittest.main()

0 commit comments

Comments
 (0)