2014-03-18 05:34:18 +01:00
|
|
|
import unittest
|
|
|
|
|
|
2021-01-31 16:49:12 -05:00
|
|
|
from matrix import (
|
|
|
|
|
Matrix,
|
|
|
|
|
)
|
2014-06-11 15:06:22 +02:00
|
|
|
|
2023-07-14 15:52:15 -07:00
|
|
|
# These tests are auto-generated with test data from:
|
|
|
|
|
# https://github.com/exercism/problem-specifications/tree/main/exercises/matrix/canonical-data.json
|
|
|
|
|
# File last updated on 2023-07-14
|
2018-02-17 04:03:08 +08:00
|
|
|
|
2019-07-30 11:09:49 -05:00
|
|
|
|
2014-03-18 05:34:18 +01:00
|
|
|
class MatrixTest(unittest.TestCase):
|
2018-02-17 04:03:08 +08:00
|
|
|
def test_extract_row_from_one_number_matrix(self):
|
|
|
|
|
matrix = Matrix("1")
|
2019-01-14 10:22:45 -06:00
|
|
|
self.assertEqual(matrix.row(1), [1])
|
2018-02-17 04:03:08 +08:00
|
|
|
|
|
|
|
|
def test_can_extract_row(self):
|
|
|
|
|
matrix = Matrix("1 2\n3 4")
|
2019-01-14 10:22:45 -06:00
|
|
|
self.assertEqual(matrix.row(2), [3, 4])
|
2018-02-17 04:03:08 +08:00
|
|
|
|
|
|
|
|
def test_extract_row_where_numbers_have_different_widths(self):
|
2014-03-18 05:34:18 +01:00
|
|
|
matrix = Matrix("1 2\n10 20")
|
2019-01-14 10:22:45 -06:00
|
|
|
self.assertEqual(matrix.row(2), [10, 20])
|
2014-03-18 05:34:18 +01:00
|
|
|
|
2019-09-19 11:01:22 -04:00
|
|
|
def test_can_extract_row_from_non_square_matrix_with_no_corresponding_column(self):
|
2018-02-17 04:03:08 +08:00
|
|
|
matrix = Matrix("1 2 3\n4 5 6\n7 8 9\n8 7 6")
|
2019-09-19 11:01:22 -04:00
|
|
|
self.assertEqual(matrix.row(4), [8, 7, 6])
|
2014-03-18 05:34:18 +01:00
|
|
|
|
2018-02-17 04:03:08 +08:00
|
|
|
def test_extract_column_from_one_number_matrix(self):
|
|
|
|
|
matrix = Matrix("1")
|
2019-01-14 10:22:45 -06:00
|
|
|
self.assertEqual(matrix.column(1), [1])
|
2014-03-18 05:34:18 +01:00
|
|
|
|
2018-02-17 04:03:08 +08:00
|
|
|
def test_can_extract_column(self):
|
|
|
|
|
matrix = Matrix("1 2 3\n4 5 6\n7 8 9")
|
2019-01-14 10:22:45 -06:00
|
|
|
self.assertEqual(matrix.column(3), [3, 6, 9])
|
2014-03-18 05:34:18 +01:00
|
|
|
|
2019-09-19 11:01:22 -04:00
|
|
|
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])
|
2014-03-18 05:34:18 +01:00
|
|
|
|
2018-02-17 04:03:08 +08:00
|
|
|
def test_extract_column_where_numbers_have_different_widths(self):
|
2014-03-18 05:34:18 +01:00
|
|
|
matrix = Matrix("89 1903 3\n18 3 1\n9 4 800")
|
2019-01-14 10:22:45 -06:00
|
|
|
self.assertEqual(matrix.column(2), [1903, 3, 4])
|
2014-03-18 05:34:18 +01:00
|
|
|
|
|
|
|
|
|
2019-07-30 11:09:49 -05:00
|
|
|
if __name__ == "__main__":
|
2014-03-18 05:34:18 +01:00
|
|
|
unittest.main()
|