mirror of
https://codeberg.org/cblanken/boggler.git
synced 2026-07-26 03:29:26 -04:00
Refactor 4x4 board test to use pytest fixtures
- Update missing symoblic link to boggler src files to access wordlists
This commit is contained in:
+1
-1
@@ -1 +1 @@
|
|||||||
../src/boggler
|
../boggler
|
||||||
@@ -5,15 +5,20 @@ from os import path
|
|||||||
import pytest
|
import pytest
|
||||||
from boggler.boggler_utils import BoggleBoard, build_full_boggle_tree
|
from boggler.boggler_utils import BoggleBoard, build_full_boggle_tree
|
||||||
|
|
||||||
wordlists_dir = path.abspath("./boggler/wordlists/dwyl/")
|
WORDLISTS_DIR = path.abspath("./boggler/wordlists/dwyl/")
|
||||||
letters = [
|
|
||||||
|
@pytest.fixture
|
||||||
|
def board_4x4():
|
||||||
|
return [
|
||||||
['u','n','r','e'],
|
['u','n','r','e'],
|
||||||
['qu','n','i','l'],
|
['qu','n','i','l'],
|
||||||
['i','s','h','a'],
|
['i','s','h','a'],
|
||||||
['s','e','l','b']
|
['s','e','l','b']
|
||||||
]
|
]
|
||||||
|
|
||||||
expected_words_max_4 = [
|
@pytest.fixture
|
||||||
|
def expected_words_max_4():
|
||||||
|
return [
|
||||||
"u", "un", "unn", "uns", "uni", "unie", "uni", "unie", "un", "unn", "uni",
|
"u", "un", "unn", "uns", "uni", "unie", "uni", "unie", "un", "unn", "uni",
|
||||||
"unie", "n", "ni", "nis", "nisi", "nil", "nile", "nu", "nun", "nuns", "nr", "r",
|
"unie", "n", "ni", "nis", "nisi", "nil", "nile", "nu", "nun", "nuns", "nr", "r",
|
||||||
"rin", "rie", "riel", "risqu", "rise", "riss", "ria", "rial", "rial", "rin",
|
"rin", "rie", "riel", "risqu", "rise", "riss", "ria", "rial", "rial", "rin",
|
||||||
@@ -44,9 +49,11 @@ expected_words_max_4 = [
|
|||||||
"les", "less", "lei", "leis", "leis", "lehi", "les", "less", "lb", "b", "ba",
|
"les", "less", "lei", "leis", "leis", "lehi", "les", "less", "lb", "b", "ba",
|
||||||
"bal", "bale", "balr", "bali", "bai", "bain", "bais", "bain", "bail", "bal",
|
"bal", "bale", "balr", "bali", "bai", "bain", "bais", "bain", "bail", "bal",
|
||||||
"bals", "bale", "bah", "bhil", "bl", "bls", "blah"
|
"bals", "bale", "bah", "bhil", "bl", "bls", "blah"
|
||||||
]
|
]
|
||||||
|
|
||||||
expected_words_max_20 = [
|
@pytest.fixture
|
||||||
|
def expected_words_max_20():
|
||||||
|
return [
|
||||||
"u","un","unn","unrelinquishable","unrelishable","unreliable","unrein","uns",
|
"u","un","unn","unrelinquishable","unrelishable","unreliable","unrein","uns",
|
||||||
"unsin","unslain","unshale","unshale","uni","unie","unhale","unhair","unhale",
|
"unsin","unslain","unshale","unshale","uni","unie","unhale","unhair","unhale",
|
||||||
"uni","unie","un","unn","uni","unie","unrelishable","unreliable",
|
"uni","unie","un","unn","uni","unie","unrelishable","unreliable",
|
||||||
@@ -102,33 +109,71 @@ expected_words_max_20 = [
|
|||||||
"bail","baile","bailer","bal","bals","bale","bales","balei","bales",
|
"bail","baile","bailer","bal","bals","bale","bales","balei","bales",
|
||||||
"bah","bhil","bl","bls","blair","blain","blain","blains","blah",
|
"bah","bhil","bl","bls","blair","blain","blain","blains","blah",
|
||||||
"blahs","bless","bless"
|
"blahs","bless","bless"
|
||||||
]
|
]
|
||||||
|
|
||||||
# Init for word tree (4 letters or less)
|
# -----------------------------------------------------
|
||||||
board_4 = BoggleBoard(letters, 4)
|
# Solved board max 4-letter words
|
||||||
tree_4 = build_full_boggle_tree(board_4, wordlists_dir)
|
# -----------------------------------------------------
|
||||||
found_words_4 = list(chain.from_iterable([x.word_paths for x in tree_4.values()]))
|
|
||||||
|
|
||||||
# Init for word tree (20 letters or less)
|
# Init for word tree (4 board_4x4 or less) and fixtures
|
||||||
board_20 = BoggleBoard(letters, 20)
|
@pytest.fixture
|
||||||
tree_20 = build_full_boggle_tree(board_20, wordlists_dir)
|
def board_4(board_4x4):
|
||||||
found_words_20 = list(chain.from_iterable([x.word_paths for x in tree_20.values()]))
|
return BoggleBoard(board_4x4, 4)
|
||||||
|
|
||||||
def test_word_count_4_letters_max():
|
@pytest.fixture
|
||||||
|
def tree_4(board_4):
|
||||||
|
return build_full_boggle_tree(board_4, WORDLISTS_DIR)
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def found_words_4(tree_4):
|
||||||
|
return list(chain.from_iterable([x.word_paths for x in tree_4.values()]))
|
||||||
|
|
||||||
|
# Tests for solved board with max of 4-letter words
|
||||||
|
def test_word_count_4_board_4x4_max(expected_words_max_4, tree_4):
|
||||||
assert len(expected_words_max_4) == sum(map(lambda x: len(x.word_paths), tree_4.values()))
|
assert len(expected_words_max_4) == sum(map(lambda x: len(x.word_paths), tree_4.values()))
|
||||||
|
|
||||||
def test_words_full_4_letters_max():
|
def test_words_full_4_board_4x4_max(expected_words_max_4, found_words_4, tree_4):
|
||||||
found_words = [x.word_paths for x in tree_4.values()]
|
found_words = [x.word_paths for x in tree_4.values()]
|
||||||
for letter, subtree in tree_4.items():
|
for letter, subtree in tree_4.items():
|
||||||
for i in range(0, min(len(expected_words_max_4), len(found_words_4))):
|
for i in range(0, min(len(expected_words_max_4), len(found_words_4))):
|
||||||
assert expected_words_max_4[i] == found_words_4[i][0]
|
assert expected_words_max_4[i] == found_words_4[i][0]
|
||||||
|
|
||||||
def test_word_count_20_letters_max():
|
def test_format_words_4_to_csv():
|
||||||
|
pass
|
||||||
|
|
||||||
|
def test_format_words_4_to_json():
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
# -----------------------------------------------------
|
||||||
|
# Solved board max 20-letter words
|
||||||
|
# -----------------------------------------------------
|
||||||
|
|
||||||
|
# Init for word tree (20 board_4x4 or less) and fixtures
|
||||||
|
@pytest.fixture
|
||||||
|
def board_20(board_4x4):
|
||||||
|
return BoggleBoard(board_4x4, 20)
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def tree_20(board_20):
|
||||||
|
return build_full_boggle_tree(board_20, WORDLISTS_DIR)
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def found_words_20(tree_20):
|
||||||
|
return list(chain.from_iterable([x.word_paths for x in tree_20.values()]))
|
||||||
|
|
||||||
|
# Tests for solved board with max of 20-letter words
|
||||||
|
def test_word_count_20_board_4x4_max(expected_words_max_20, tree_20):
|
||||||
assert len(expected_words_max_20) == sum(map(lambda x: len(x.word_paths), tree_20.values()))
|
assert len(expected_words_max_20) == sum(map(lambda x: len(x.word_paths), tree_20.values()))
|
||||||
|
|
||||||
def test_words_full_20_letters_max():
|
def test_words_full_20_board_4x4_max(expected_words_max_20, found_words_20, tree_20):
|
||||||
found_words = [x.word_paths for x in tree_20.values()]
|
found_words = [x.word_paths for x in tree_20.values()]
|
||||||
for letter, subtree in tree_20.items():
|
for letter, subtree in tree_20.items():
|
||||||
for i in range(0, min(len(expected_words_max_20), len(found_words_20))):
|
for i in range(0, min(len(expected_words_max_20), len(found_words_20))):
|
||||||
assert expected_words_max_20[i] == found_words_20[i][0]
|
assert expected_words_max_20[i] == found_words_20[i][0]
|
||||||
|
|
||||||
|
def test_format_words_20_to_csv():
|
||||||
|
pass
|
||||||
|
|
||||||
|
def test_format_words_20_to_json():
|
||||||
|
pass
|
||||||
|
|||||||
Reference in New Issue
Block a user