WIP
This commit is contained in:
@ -84,4 +84,16 @@ def test_placed_words_tracking():
|
||||
assert placed.word == word
|
||||
assert placed.row == 1
|
||||
assert placed.col == 1
|
||||
assert placed.orientation == Orientation.VERTICAL
|
||||
assert placed.orientation == Orientation.VERTICAL
|
||||
|
||||
def test_valid_hello_world_crossword():
|
||||
cw = make_crossword()
|
||||
assert cw.add_word(DummyWord("HELLO"), 1, 0, Orientation.HORIZONTAL)
|
||||
assert cw.add_word(DummyWord("WORLD"), 0, 4, Orientation.VERTICAL)
|
||||
assert str(cw).count('H') == 1
|
||||
assert str(cw).count('E') == 1
|
||||
assert str(cw).count('L') == 3
|
||||
assert str(cw).count('O') == 1
|
||||
assert str(cw).count('W') == 1
|
||||
assert str(cw).count('R') == 1
|
||||
assert str(cw).count('D') == 1
|
||||
49
tests/test_crossword_generators.py
Normal file
49
tests/test_crossword_generators.py
Normal file
@ -0,0 +1,49 @@
|
||||
import pytest
|
||||
from multiplayer_crosswords.crossword_generators import extract_slots, slot_pattern, Slot
|
||||
from multiplayer_crosswords.crossword import Orientation
|
||||
|
||||
def test_extract_slots_simple():
|
||||
grid = [
|
||||
['', '', '', '#', ''],
|
||||
['', '#', '', '', ''],
|
||||
['', '', '', '', ''],
|
||||
['#', '', '#', '', ''],
|
||||
['', '', '', '', ''],
|
||||
]
|
||||
slots = extract_slots(grid, min_length=2)
|
||||
# Should find horizontal and vertical slots of length >= 2
|
||||
assert any(s.orientation == Orientation.HORIZONTAL and s.length == 3 for s in slots)
|
||||
assert any(s.orientation == Orientation.VERTICAL and s.length == 3 for s in slots)
|
||||
# No slot should start at a '#' cell
|
||||
for slot in slots:
|
||||
r, c = slot.row, slot.col
|
||||
assert grid[r][c] != '#'
|
||||
|
||||
assert len(slots) == 10 # Total slots found
|
||||
|
||||
def test_slot_pattern():
|
||||
grid = [
|
||||
['a', '', '', '#', ''],
|
||||
['', '#', '', '', ''],
|
||||
['', '', '', '', ''],
|
||||
['#', '', '#', '', ''],
|
||||
['', '', '', '', ''],
|
||||
]
|
||||
slot = Slot(0, 0, Orientation.HORIZONTAL, 3)
|
||||
pattern = slot_pattern(grid, slot)
|
||||
assert pattern == 'a**'
|
||||
|
||||
slot2 = Slot(2, 1, Orientation.VERTICAL, 3)
|
||||
pattern2 = slot_pattern(grid, slot2)
|
||||
assert pattern2 == '***' # All empty cells in this slot
|
||||
|
||||
def test_extract_slots_min_length():
|
||||
grid = [
|
||||
['#', '', '', '#'],
|
||||
['', '', '', ''],
|
||||
['#', '', '', '#'],
|
||||
]
|
||||
slots = extract_slots(grid, min_length=3)
|
||||
# Only slots of length 3 or more
|
||||
assert all(slot.length >= 3 for slot in slots)
|
||||
assert len(slots) == 3
|
||||
Reference in New Issue
Block a user