Initial blacken reformat

This commit is contained in:
2023-08-22 16:56:59 -04:00
parent ab2869b858
commit a2630ed82e
9 changed files with 438 additions and 146 deletions
+15 -5
View File
@@ -4,19 +4,22 @@ from boggler.boggler_utils import read_boggle_file, BadBoardFormat
boards_path = Path(Path(__file__).parent.resolve())
@pytest.fixture(name="expected_board_4x4")
def fixture_expected_board_4x4():
return [
['u', 'n', 'r', 'e'],
['qu', 'n', 'i', 'l'],
['i', 's', 'h', 'a'],
['s', 'e', 'l', 'b']
["u", "n", "r", "e"],
["qu", "n", "i", "l"],
["i", "s", "h", "a"],
["s", "e", "l", "b"],
]
@pytest.fixture(name="clean_4x4_path")
def fixture_clean_4x4_path():
return Path(boards_path, "./boards/4x4_clean.board")
def test_clean_4x4_board(expected_board_4x4, clean_4x4_path):
"""Test 4x4 board with clean input"""
assert expected_board_4x4 == read_boggle_file(clean_4x4_path)
@@ -27,6 +30,7 @@ def test_clean_4x4_board(expected_board_4x4, clean_4x4_path):
def fixture_leading_whitespace_4x4_path():
return Path(boards_path, "./boards/4x4_leading_whitespace.board")
def test_leading_whitespace_4x4_board(expected_board_4x4, leading_whitespace_4x4_path):
"""Test 4x4 board with leading whitepace in rows"""
assert expected_board_4x4 == read_boggle_file(leading_whitespace_4x4_path)
@@ -37,6 +41,7 @@ def test_leading_whitespace_4x4_board(expected_board_4x4, leading_whitespace_4x4
def fixture_between_whitespace_4x4_path():
return Path(boards_path, "./boards/4x4_between_whitespace.board")
def test_between_whitespace_4x4_board(expected_board_4x4, between_whitespace_4x4_path):
"""Test 4x4 board with whitespace surrounding letters in block"""
assert expected_board_4x4 == read_boggle_file(between_whitespace_4x4_path)
@@ -47,7 +52,10 @@ def test_between_whitespace_4x4_board(expected_board_4x4, between_whitespace_4x4
def fixture_trailing_whitespace_4x4_path():
return Path(boards_path, "./boards/4x4_trailing_whitespace.board")
def test_trailing_whitespace_4x4_board(expected_board_4x4, trailing_whitespace_4x4_path):
def test_trailing_whitespace_4x4_board(
expected_board_4x4, trailing_whitespace_4x4_path
):
"""Test 4x4 board with trailing whitespace in rows"""
assert expected_board_4x4 == read_boggle_file(trailing_whitespace_4x4_path)
@@ -57,6 +65,7 @@ def test_trailing_whitespace_4x4_board(expected_board_4x4, trailing_whitespace_4
def fixture_blank_lines_4x4_path():
return Path(boards_path, "./boards/4x4_blank_lines.board")
def test_blank_lines_4x4_board(blank_lines_4x4_path):
"""Test 4x4 board with blank lines in board file"""
with pytest.raises(BadBoardFormat, match="must contain no blank lines"):
@@ -68,6 +77,7 @@ def test_blank_lines_4x4_board(blank_lines_4x4_path):
def fixture_inconsistent_width_4x4_path():
return Path(boards_path, "./boards/4x4_inconsistent_width.board")
def test_inconsistent_width_4x4_board(inconsistent_width_4x4_path):
"""Test board with irregular number of blocks per row"""
with pytest.raises(BadBoardFormat, match="length of each row must be the same"):
+185 -17
View File
@@ -5,15 +5,17 @@ from boggler.boggler_utils import BoggleBoard, build_full_boggle_tree
WORDLISTS_DIR = Path("./boggler/wordlists/dwyl/").absolute()
@pytest.fixture
def board_4x4():
return [
['u','n','r','e'],
['qu','n','i','l'],
['i','s','h','a'],
['s','e','l','b']
["u", "n", "r", "e"],
["qu", "n", "i", "l"],
["i", "s", "h", "a"],
["s", "e", "l", "b"],
]
@pytest.fixture
def expected_words_max_4():
return [
@@ -345,15 +347,65 @@ def expected_words_max_4():
("blah", [(3, 3), (3, 2), (2, 3), (2, 2)]),
]
@pytest.fixture
def expected_words_max_20():
return [
("u", [(0, 0)]),
("un", [(0, 0), (1, 1)]),
("unn", [(0, 0), (1, 1), (0, 1)]),
("unrelinquishable", [(0, 0), (1, 1), (0, 2), (0, 3), (1, 3), (1, 2), (0, 1), (1, 0), (2, 0), (2, 1), (2, 2), (2, 3), (3, 3), (3, 2), (3, 1)]),
("unrelishable", [(0, 0), (1, 1), (0, 2), (0, 3), (1, 3), (1, 2), (2, 1), (2, 2), (2, 3), (3, 3), (3, 2), (3, 1)]),
("unreliable", [(0, 0), (1, 1), (0, 2), (0, 3), (1, 3), (1, 2), (2, 3), (3, 3), (3, 2), (3, 1)]),
(
"unrelinquishable",
[
(0, 0),
(1, 1),
(0, 2),
(0, 3),
(1, 3),
(1, 2),
(0, 1),
(1, 0),
(2, 0),
(2, 1),
(2, 2),
(2, 3),
(3, 3),
(3, 2),
(3, 1),
],
),
(
"unrelishable",
[
(0, 0),
(1, 1),
(0, 2),
(0, 3),
(1, 3),
(1, 2),
(2, 1),
(2, 2),
(2, 3),
(3, 3),
(3, 2),
(3, 1),
],
),
(
"unreliable",
[
(0, 0),
(1, 1),
(0, 2),
(0, 3),
(1, 3),
(1, 2),
(2, 3),
(3, 3),
(3, 2),
(3, 1),
],
),
("unrein", [(0, 0), (1, 1), (0, 2), (0, 3), (1, 2), (0, 1)]),
("uns", [(0, 0), (1, 1), (2, 1)]),
("unsin", [(0, 0), (1, 1), (2, 1), (1, 2), (0, 1)]),
@@ -371,9 +423,58 @@ def expected_words_max_20():
("unn", [(0, 0), (0, 1), (1, 1)]),
("uni", [(0, 0), (0, 1), (1, 2)]),
("unie", [(0, 0), (0, 1), (1, 2), (0, 3)]),
("unrelishable", [(0, 0), (0, 1), (0, 2), (0, 3), (1, 3), (1, 2), (2, 1), (2, 2), (2, 3), (3, 3), (3, 2), (3, 1)]),
("unreliable", [(0, 0), (0, 1), (0, 2), (0, 3), (1, 3), (1, 2), (2, 3), (3, 3), (3, 2), (3, 1)]),
("unrelinquishable", [(0, 0), (0, 1), (0, 2), (0, 3), (1, 3), (1, 2), (1, 1), (1, 0), (2, 0), (2, 1), (2, 2), (2, 3), (3, 3), (3, 2), (3, 1)]),
(
"unrelishable",
[
(0, 0),
(0, 1),
(0, 2),
(0, 3),
(1, 3),
(1, 2),
(2, 1),
(2, 2),
(2, 3),
(3, 3),
(3, 2),
(3, 1),
],
),
(
"unreliable",
[
(0, 0),
(0, 1),
(0, 2),
(0, 3),
(1, 3),
(1, 2),
(2, 3),
(3, 3),
(3, 2),
(3, 1),
],
),
(
"unrelinquishable",
[
(0, 0),
(0, 1),
(0, 2),
(0, 3),
(1, 3),
(1, 2),
(1, 1),
(1, 0),
(2, 0),
(2, 1),
(2, 2),
(2, 3),
(3, 3),
(3, 2),
(3, 1),
],
),
("unrein", [(0, 0), (0, 1), (0, 2), (0, 3), (1, 2), (1, 1)]),
("n", [(0, 1)]),
("ni", [(0, 1), (1, 2)]),
@@ -414,14 +515,64 @@ def expected_words_max_20():
("re", [(0, 2), (0, 3)]),
("rel", [(0, 2), (0, 3), (1, 3)]),
("relais", [(0, 2), (0, 3), (1, 3), (2, 3), (1, 2), (2, 1)]),
("relinquish", [(0, 2), (0, 3), (1, 3), (1, 2), (0, 1), (1, 0), (2, 0), (2, 1), (2, 2)]),
("relinquishes", [(0, 2), (0, 3), (1, 3), (1, 2), (0, 1), (1, 0), (2, 0), (2, 1), (2, 2), (3, 1), (3, 0)]),
(
"relinquish",
[(0, 2), (0, 3), (1, 3), (1, 2), (0, 1), (1, 0), (2, 0), (2, 1), (2, 2)],
),
(
"relinquishes",
[
(0, 2),
(0, 3),
(1, 3),
(1, 2),
(0, 1),
(1, 0),
(2, 0),
(2, 1),
(2, 2),
(3, 1),
(3, 0),
],
),
("relish", [(0, 2), (0, 3), (1, 3), (1, 2), (2, 1), (2, 2)]),
("relishes", [(0, 2), (0, 3), (1, 3), (1, 2), (2, 1), (2, 2), (3, 1), (3, 0)]),
("relishable", [(0, 2), (0, 3), (1, 3), (1, 2), (2, 1), (2, 2), (2, 3), (3, 3), (3, 2), (3, 1)]),
(
"relishable",
[
(0, 2),
(0, 3),
(1, 3),
(1, 2),
(2, 1),
(2, 2),
(2, 3),
(3, 3),
(3, 2),
(3, 1),
],
),
("reliable", [(0, 2), (0, 3), (1, 3), (1, 2), (2, 3), (3, 3), (3, 2), (3, 1)]),
("relinquish", [(0, 2), (0, 3), (1, 3), (1, 2), (1, 1), (1, 0), (2, 0), (2, 1), (2, 2)]),
("relinquishes", [(0, 2), (0, 3), (1, 3), (1, 2), (1, 1), (1, 0), (2, 0), (2, 1), (2, 2), (3, 1), (3, 0)]),
(
"relinquish",
[(0, 2), (0, 3), (1, 3), (1, 2), (1, 1), (1, 0), (2, 0), (2, 1), (2, 2)],
),
(
"relinquishes",
[
(0, 2),
(0, 3),
(1, 3),
(1, 2),
(1, 1),
(1, 0),
(2, 0),
(2, 1),
(2, 2),
(3, 1),
(3, 0),
],
),
("rei", [(0, 2), (0, 3), (1, 2)]),
("rein", [(0, 2), (0, 3), (1, 2), (0, 1)]),
("reis", [(0, 2), (0, 3), (1, 2), (2, 1)]),
@@ -839,6 +990,7 @@ def expected_words_max_20():
("bless", [(3, 3), (3, 2), (3, 1), (3, 0), (2, 1)]),
]
# -----------------------------------------------------
# Solved board max 4-letter words
# -----------------------------------------------------
@@ -848,25 +1000,33 @@ def expected_words_max_20():
def board_4(board_4x4):
return BoggleBoard(board_4x4, 4)
@pytest.fixture
def tree_4(board_4):
return build_full_boggle_tree(board_4, Path(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_board_4x4_max(expected_words_max_4, found_words_4):
"""Verify words and paths match in exact order"""
assert found_words_4 == expected_words_max_4
def test_format_words_4_to_csv():
pass
def test_format_words_4_to_json():
pass
@@ -880,23 +1040,31 @@ def test_format_words_4_to_json():
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_board_4x4_max(expected_words_max_20, found_words_20):
assert found_words_20 == expected_words_max_20
def test_format_words_20_to_csv():
pass
def test_format_words_20_to_json():
pass