import initial
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
import pytest
|
||||
from logimage.domain.value_objects.grid import Grid
|
||||
|
||||
|
||||
def _make_cells(rows: int, cols: int, value: bool = False) -> list[list[bool]]:
|
||||
return [[value] * cols for _ in range(rows)]
|
||||
|
||||
|
||||
def test_grid_width_and_height() -> None:
|
||||
grid = Grid.from_list(_make_cells(10, 15))
|
||||
assert grid.width == 15
|
||||
assert grid.height == 10
|
||||
|
||||
|
||||
def test_grid_row_returns_correct_values() -> None:
|
||||
cells5 = [[True, False, True, False, True]] * 5
|
||||
grid = Grid.from_list(cells5)
|
||||
assert grid.row(0) == (True, False, True, False, True)
|
||||
|
||||
|
||||
def test_grid_col_returns_correct_values() -> None:
|
||||
cells = [[True, False, False, False, False]] * 5
|
||||
grid = Grid.from_list(cells)
|
||||
assert grid.col(0) == (True, True, True, True, True)
|
||||
assert grid.col(1) == (False, False, False, False, False)
|
||||
|
||||
|
||||
def test_grid_rejects_width_below_minimum() -> None:
|
||||
with pytest.raises(ValueError, match="width"):
|
||||
Grid.from_list([[True, False, True, False]] * 5)
|
||||
|
||||
|
||||
def test_grid_rejects_height_below_minimum() -> None:
|
||||
with pytest.raises(ValueError, match="height"):
|
||||
Grid.from_list([[True] * 5] * 4)
|
||||
|
||||
|
||||
def test_grid_rejects_width_above_maximum() -> None:
|
||||
with pytest.raises(ValueError, match="width"):
|
||||
Grid.from_list([[True] * 51] * 5)
|
||||
|
||||
|
||||
def test_grid_rejects_height_above_maximum() -> None:
|
||||
with pytest.raises(ValueError, match="height"):
|
||||
Grid.from_list([[True] * 5] * 51)
|
||||
|
||||
|
||||
def test_grid_is_immutable() -> None:
|
||||
grid = Grid.from_list(_make_cells(5, 5))
|
||||
with pytest.raises(AttributeError):
|
||||
grid.cells = () # type: ignore[misc]
|
||||
|
||||
|
||||
def test_grid_from_list_converts_to_tuples() -> None:
|
||||
grid = Grid.from_list(_make_cells(5, 5, True))
|
||||
assert isinstance(grid.cells, tuple)
|
||||
assert isinstance(grid.cells[0], tuple)
|
||||
Reference in New Issue
Block a user