exercism

Exercism solutions.
git clone git://code.dwrz.net/exercism
Log | Files | Refs

matrix_test.py (1465B)


      1 import unittest
      2 
      3 from matrix import (
      4     Matrix,
      5 )
      6 
      7 # Tests adapted from `problem-specifications//canonical-data.json`
      8 
      9 
     10 class MatrixTest(unittest.TestCase):
     11     def test_extract_row_from_one_number_matrix(self):
     12         matrix = Matrix("1")
     13         self.assertEqual(matrix.row(1), [1])
     14 
     15     def test_can_extract_row(self):
     16         matrix = Matrix("1 2\n3 4")
     17         self.assertEqual(matrix.row(2), [3, 4])
     18 
     19     def test_extract_row_where_numbers_have_different_widths(self):
     20         matrix = Matrix("1 2\n10 20")
     21         self.assertEqual(matrix.row(2), [10, 20])
     22 
     23     def test_can_extract_row_from_non_square_matrix_with_no_corresponding_column(self):
     24         matrix = Matrix("1 2 3\n4 5 6\n7 8 9\n8 7 6")
     25         self.assertEqual(matrix.row(4), [8, 7, 6])
     26 
     27     def test_extract_column_from_one_number_matrix(self):
     28         matrix = Matrix("1")
     29         self.assertEqual(matrix.column(1), [1])
     30 
     31     def test_can_extract_column(self):
     32         matrix = Matrix("1 2 3\n4 5 6\n7 8 9")
     33         self.assertEqual(matrix.column(3), [3, 6, 9])
     34 
     35     def test_can_extract_column_from_non_square_matrix_with_no_corresponding_row(self):
     36         matrix = Matrix("1 2 3 4\n5 6 7 8\n9 8 7 6")
     37         self.assertEqual(matrix.column(4), [4, 8, 6])
     38 
     39     def test_extract_column_where_numbers_have_different_widths(self):
     40         matrix = Matrix("89 1903 3\n18 3 1\n9 4 800")
     41         self.assertEqual(matrix.column(2), [1903, 3, 4])
     42 
     43 
     44 if __name__ == "__main__":
     45     unittest.main()