|
| 1 | +try: |
| 2 | + from matrix import Matrix |
| 3 | +except ImportError: |
| 4 | + raise SystemExit('Could not find matrix.py. Does it exist?') |
| 5 | + |
| 6 | +import unittest |
| 7 | + |
| 8 | + |
| 9 | +class MatrixTest(unittest.TestCase): |
| 10 | + def test_extract_a_row(self): |
| 11 | + matrix = Matrix("1 2\n10 20") |
| 12 | + self.assertEqual([1, 2], matrix.rows[0]) |
| 13 | + |
| 14 | + def test_extract_same_row_again(self): |
| 15 | + matrix = Matrix("9 7\n8 6") |
| 16 | + self.assertEqual([9, 7], matrix.rows[0]) |
| 17 | + |
| 18 | + def test_extract_other_row(self): |
| 19 | + matrix = Matrix("9 8 7\n19 18 17") |
| 20 | + self.assertEqual([19, 18, 17], matrix.rows[1]) |
| 21 | + |
| 22 | + def test_extract_other_row_again(self): |
| 23 | + matrix = Matrix("1 4 9\n16 25 36") |
| 24 | + self.assertEqual([16, 25, 36], matrix.rows[1]) |
| 25 | + |
| 26 | + def test_extract_a_column(self): |
| 27 | + matrix = Matrix("1 2 3\n4 5 6\n7 8 9\n 8 7 6") |
| 28 | + self.assertEqual([1, 4, 7, 8], matrix.columns[0]) |
| 29 | + |
| 30 | + def test_extract_another_column(self): |
| 31 | + matrix = Matrix("89 1903 3\n18 3 1\n9 4 800") |
| 32 | + self.assertEqual([1903, 3, 4], matrix.columns[1]) |
| 33 | + |
| 34 | + |
| 35 | +if __name__ == '__main__': |
| 36 | + unittest.main() |
0 commit comments