Files
python/exercises/practice/matrix/matrix_test.py
BethanyG e7a6b0dc7d [JinJa2] Corrected the macro used for comments on the test file. (#3373)
* Corrected the macro for comments on the test file.
* Added current_date (utcnow()) variable available for template macros.
* Removed unnecessary datetime import from macros file.
* Regenerated all practice exercise test files to add timestamp.
* Changed `datetime.now(tz=timezone.utc)` to `datetime.now(tz=timezone.utc).date()`
* Second regeneration to remove `timestamp` and just keep `date` for test files.
[no important files changed]
2023-07-14 15:52:15 -07:00

48 lines
1.5 KiB
Python

import unittest
from matrix import (
Matrix,
)
# 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
class MatrixTest(unittest.TestCase):
def test_extract_row_from_one_number_matrix(self):
matrix = Matrix("1")
self.assertEqual(matrix.row(1), [1])
def test_can_extract_row(self):
matrix = Matrix("1 2\n3 4")
self.assertEqual(matrix.row(2), [3, 4])
def test_extract_row_where_numbers_have_different_widths(self):
matrix = Matrix("1 2\n10 20")
self.assertEqual(matrix.row(2), [10, 20])
def test_can_extract_row_from_non_square_matrix_with_no_corresponding_column(self):
matrix = Matrix("1 2 3\n4 5 6\n7 8 9\n8 7 6")
self.assertEqual(matrix.row(4), [8, 7, 6])
def test_extract_column_from_one_number_matrix(self):
matrix = Matrix("1")
self.assertEqual(matrix.column(1), [1])
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_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_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])
if __name__ == "__main__":
unittest.main()