You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
box-o-sand/leetcode/test_spiral_matrix.py

47 lines
1.2 KiB

import pytest
import spiral_matrix
@pytest.mark.parametrize(
("matrix", "expected"),
[
(
[
["a", "b", "c"],
["d", "e", "f"],
["g", "h", "i"],
],
["a", "b", "c", "f", "i", "h", "g", "d", "e"],
),
(
[
[1, 2, 3, 4],
[5, 6, 7, 8],
[9, 10, 11, 12],
],
[1, 2, 3, 4, 8, 12, 11, 10, 9, 5, 6, 7],
),
(
[
[1, 2, 3, 4, 5, 6, 7, 8, 9],
[1, 2, 3, 4, 5, 6, 7, 8, 9],
[1, 2, 3, 4, 5, 6, 7, 8, 9],
[1, 2, 3, 4, 5, 6, 7, 8, 9],
[1, 2, 3, 4, 5, 6, 7, 8, 9],
],
[] # noqa
+ [1, 2, 3, 4, 5, 6, 7, 8, 9] # right
+ [9, 9, 9] # down
+ [9, 8, 7, 6, 5, 4, 3, 2, 1] # left
+ [1, 1] # up
+ [1, 2, 3, 4, 5, 6, 7, 8] # right
+ [8] # down
+ [8, 7, 6, 5, 4, 3, 2] # left
+ [2, 3, 4, 5, 6, 7], # right
),
],
)
def test_matrix_spiral(matrix, expected):
assert spiral_matrix.matrix_spiral(matrix) == expected