import initial
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
import pytest
|
||||
from logimage.domain.value_objects.clue import Clue
|
||||
|
||||
|
||||
def test_clue_from_consecutive_cells() -> None:
|
||||
cells = (True, True, False, True, False, False, True, True, True)
|
||||
clue = Clue.from_row(cells)
|
||||
assert clue.values == (2, 1, 3)
|
||||
|
||||
|
||||
def test_clue_from_empty_row() -> None:
|
||||
clue = Clue.from_row((False, False, False))
|
||||
assert clue.values == ()
|
||||
|
||||
|
||||
def test_clue_from_single_true_cell() -> None:
|
||||
clue = Clue.from_row((False, True, False))
|
||||
assert clue.values == (1,)
|
||||
|
||||
|
||||
def test_clue_from_all_true_row() -> None:
|
||||
clue = Clue.from_row((True, True, True))
|
||||
assert clue.values == (3,)
|
||||
|
||||
|
||||
def test_clue_is_immutable() -> None:
|
||||
clue = Clue.from_row((True, False, True))
|
||||
with pytest.raises(AttributeError):
|
||||
clue.values = (99,) # type: ignore[misc]
|
||||
|
||||
|
||||
def test_clue_trailing_true() -> None:
|
||||
clue = Clue.from_row((False, True, True))
|
||||
assert clue.values == (2,)
|
||||
@@ -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)
|
||||
@@ -0,0 +1,59 @@
|
||||
from logimage.domain.value_objects.grid import Grid
|
||||
from logimage.domain.value_objects.clue import Clue
|
||||
from logimage.domain.entities.puzzle import NonogramPuzzle
|
||||
|
||||
|
||||
def _simple_grid() -> Grid:
|
||||
return Grid.from_list([
|
||||
[True, False, True, False, True ],
|
||||
[False, True, False, True, False],
|
||||
[True, True, False, False, True ],
|
||||
[False, False, True, True, False],
|
||||
[True, False, False, True, True ],
|
||||
])
|
||||
|
||||
|
||||
def test_puzzle_row_clues_computed_correctly() -> None:
|
||||
puzzle = NonogramPuzzle.from_grid(_simple_grid(), "Test")
|
||||
assert puzzle.row_clues[0] == Clue(values=(1, 1, 1))
|
||||
assert puzzle.row_clues[1] == Clue(values=(1, 1))
|
||||
assert puzzle.row_clues[2] == Clue(values=(2, 1))
|
||||
|
||||
|
||||
def test_puzzle_col_clues_computed_correctly() -> None:
|
||||
puzzle = NonogramPuzzle.from_grid(_simple_grid(), "Test")
|
||||
assert puzzle.col_clues[0] == Clue(values=(1, 1, 1))
|
||||
assert puzzle.col_clues[1] == Clue(values=(2,))
|
||||
|
||||
|
||||
def test_puzzle_title_stored() -> None:
|
||||
puzzle = NonogramPuzzle.from_grid(_simple_grid(), "Mountains")
|
||||
assert puzzle.title == "Mountains"
|
||||
|
||||
|
||||
def test_puzzle_has_correct_grid() -> None:
|
||||
grid = _simple_grid()
|
||||
puzzle = NonogramPuzzle.from_grid(grid, "Test")
|
||||
assert puzzle.grid is grid
|
||||
|
||||
|
||||
def test_puzzle_row_clue_count_matches_grid_height() -> None:
|
||||
grid = _simple_grid()
|
||||
puzzle = NonogramPuzzle.from_grid(grid, "Test")
|
||||
assert len(puzzle.row_clues) == grid.height
|
||||
|
||||
|
||||
def test_puzzle_col_clue_count_matches_grid_width() -> None:
|
||||
grid = _simple_grid()
|
||||
puzzle = NonogramPuzzle.from_grid(grid, "Test")
|
||||
assert len(puzzle.col_clues) == grid.width
|
||||
|
||||
|
||||
def test_puzzle_image_bytes_defaults_to_none() -> None:
|
||||
puzzle = NonogramPuzzle.from_grid(_simple_grid(), "Test")
|
||||
assert puzzle.image_bytes is None
|
||||
|
||||
|
||||
def test_puzzle_image_bytes_stored() -> None:
|
||||
puzzle = NonogramPuzzle.from_grid(_simple_grid(), "Test", b"fake-image-bytes")
|
||||
assert puzzle.image_bytes == b"fake-image-bytes"
|
||||
Reference in New Issue
Block a user