60 lines
1.9 KiB
Python
60 lines
1.9 KiB
Python
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"
|