|
|
""" |
|
|
Test validation of word files for MIN_REQUIRED threshold compliance. |
|
|
""" |
|
|
|
|
|
import os |
|
|
import tempfile |
|
|
import shutil |
|
|
from wrdler.word_loader_ai import _save_ai_words_to_file |
|
|
from wrdler.word_loader import MIN_REQUIRED |
|
|
|
|
|
|
|
|
def test_save_ai_words_validates_min_required(): |
|
|
"""Test that _save_ai_words_to_file returns insufficiency info.""" |
|
|
|
|
|
test_dir = tempfile.mkdtemp() |
|
|
|
|
|
try: |
|
|
|
|
|
import wrdler.word_loader_ai as wl_ai |
|
|
original_dirname = wl_ai.os.path.dirname |
|
|
|
|
|
def mock_dirname(path): |
|
|
if "word_loader_ai.py" in path: |
|
|
return test_dir |
|
|
return original_dirname(path) |
|
|
|
|
|
wl_ai.os.path.dirname = mock_dirname |
|
|
|
|
|
|
|
|
insufficient_words = [ |
|
|
"COOK", "BAKE", "HEAT", |
|
|
"ROAST", "GRILL", "STEAM", |
|
|
"SIMMER", "BRAISE", |
|
|
] |
|
|
|
|
|
filename, insufficient = _save_ai_words_to_file("test_topic", insufficient_words) |
|
|
|
|
|
assert filename == "test_topic.txt", f"Expected 'test_topic.txt', got '{filename}'" |
|
|
assert len(insufficient) > 0, "Expected insufficient_lengths to be non-empty" |
|
|
assert 4 in insufficient, "Expected 4-letter words to be insufficient" |
|
|
assert 5 in insufficient, "Expected 5-letter words to be insufficient" |
|
|
assert 6 in insufficient, "Expected 6-letter words to be insufficient" |
|
|
|
|
|
|
|
|
sufficient_words = [] |
|
|
for length in [4, 5, 6]: |
|
|
for i in range(MIN_REQUIRED): |
|
|
|
|
|
word = chr(65 + (i % 26)) * length + str(i).zfill(length - 1) |
|
|
sufficient_words.append(word[:length].upper()) |
|
|
|
|
|
filename2, insufficient2 = _save_ai_words_to_file("test_sufficient", sufficient_words) |
|
|
|
|
|
assert filename2 == "test_sufficient.txt", f"Expected 'test_sufficient.txt', got '{filename2}'" |
|
|
assert len(insufficient2) == 0, f"Expected empty insufficient_lengths, got {insufficient2}" |
|
|
|
|
|
print("? All validation tests passed!") |
|
|
|
|
|
finally: |
|
|
|
|
|
wl_ai.os.path.dirname = original_dirname |
|
|
|
|
|
shutil.rmtree(test_dir, ignore_errors=True) |
|
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
|
test_save_ai_words_validates_min_required() |
|
|
|