class MatrixTest(unittest.TestCase): # Tests def setUp(self): self.matrix = Matrix("9 8 7\n5 3 2\n6 6 7") # def test_extract_row_from_one_number_matrix(self): # matrix = Matrix("1") # self.assertEqual(matrix.row(1), [1]) def test_rows(self): self.assertEqual([[9, 8, 7], [5, 3, 2], [6, 6, 7]], self.matrix.row()) def test_columns__1(self): self.assertEqual([[9, 5, 6], [8, 3, 6], [7, 2, 7]], self.matrix.column()) def test_matrix(self): new_matrix = Matrix("9 8 7 3\n5 3 2 3\n6 6 7 3") self.assertEqual([[9, 8, 7, 3], [5, 3, 2, 3], [6, 6, 7, 3]], new_matrix.row()) self.assertEqual([[9, 5, 6], [8, 3, 6], [7, 2, 7], [3, 3, 3]], new_matrix.column())
def test_extract_column_where_numbers_have_different_widths(self): matrix = Matrix("89 1903 3\n18 3 1\n9 4 800") self.assertEqual(matrix.column(2), [1903, 3, 4])
def test_can_extract_column_from_non_square_matrix_with_no_corresponding_row( self): matrix = Matrix("1 2 3 4\n5 6 7 8\n9 8 7 6") self.assertEqual(matrix.column(4), [4, 8, 6])
def test_can_extract_column(self): matrix = Matrix("1 2 3\n4 5 6\n7 8 9") self.assertEqual(matrix.column(3), [3, 6, 9])
def test_extract_column_from_one_number_matrix(self): matrix = Matrix("1") self.assertEqual(matrix.column(1), [1])
def test_matrix(self): new_matrix = Matrix("9 8 7 3\n5 3 2 3\n6 6 7 3") self.assertEqual([[9, 8, 7, 3], [5, 3, 2, 3], [6, 6, 7, 3]], new_matrix.row()) self.assertEqual([[9, 5, 6], [8, 3, 6], [7, 2, 7], [3, 3, 3]], new_matrix.column())