Sha256: 999ddeacd85b97cec1792673b3cead3b5777ebb3733a4d8b8c11c211b96d36e7

Contents?: true

Size: 1.38 KB

Versions: 73

Compression:

Stored size: 1.38 KB

Contents

import unittest

from matrix import Matrix


# Tests adapted from `problem-specifications//canonical-data.json` @ v1.0.0

class MatrixTest(unittest.TestCase):
    def test_extract_row_from_one_number_matrix(self):
        matrix = Matrix("1")
        self.assertEqual(matrix.row(0), [1])

    def test_can_extract_row(self):
        matrix = Matrix("1 2\n3 4")
        self.assertEqual(matrix.row(1), [3, 4])

    def test_extract_row_where_numbers_have_different_widths(self):
        matrix = Matrix("1 2\n10 20")
        self.assertEqual(matrix.row(1), [10, 20])

    def test_can_extract_row_from_non_square_matrix(self):
        matrix = Matrix("1 2 3\n4 5 6\n7 8 9\n8 7 6")
        self.assertEqual(matrix.row(2), [7, 8, 9])

    def test_extract_column_from_one_number_matrix(self):
        matrix = Matrix("1")
        self.assertEqual(matrix.column(0), [1])

    def test_can_extract_column(self):
        matrix = Matrix("1 2 3\n4 5 6\n7 8 9")
        self.assertEqual(matrix.column(2), [3, 6, 9])

    def test_can_extract_column_from_non_square_matrix(self):
        matrix = Matrix("1 2 3\n4 5 6\n7 8 9\n8 7 6")
        self.assertEqual(matrix.column(2), [3, 6, 9, 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(1), [1903, 3, 4])


if __name__ == '__main__':
    unittest.main()

Version data entries

73 entries across 73 versions & 1 rubygems

Version Path
trackler-2.2.1.159 tracks/python/exercises/matrix/matrix_test.py
trackler-2.2.1.158 tracks/python/exercises/matrix/matrix_test.py
trackler-2.2.1.157 tracks/python/exercises/matrix/matrix_test.py
trackler-2.2.1.156 tracks/python/exercises/matrix/matrix_test.py
trackler-2.2.1.155 tracks/python/exercises/matrix/matrix_test.py
trackler-2.2.1.154 tracks/python/exercises/matrix/matrix_test.py
trackler-2.2.1.153 tracks/python/exercises/matrix/matrix_test.py
trackler-2.2.1.152 tracks/python/exercises/matrix/matrix_test.py
trackler-2.2.1.151 tracks/python/exercises/matrix/matrix_test.py
trackler-2.2.1.150 tracks/python/exercises/matrix/matrix_test.py
trackler-2.2.1.149 tracks/python/exercises/matrix/matrix_test.py
trackler-2.2.1.148 tracks/python/exercises/matrix/matrix_test.py
trackler-2.2.1.147 tracks/python/exercises/matrix/matrix_test.py
trackler-2.2.1.146 tracks/python/exercises/matrix/matrix_test.py
trackler-2.2.1.145 tracks/python/exercises/matrix/matrix_test.py
trackler-2.2.1.144 tracks/python/exercises/matrix/matrix_test.py
trackler-2.2.1.143 tracks/python/exercises/matrix/matrix_test.py
trackler-2.2.1.142 tracks/python/exercises/matrix/matrix_test.py
trackler-2.2.1.141 tracks/python/exercises/matrix/matrix_test.py
trackler-2.2.1.140 tracks/python/exercises/matrix/matrix_test.py