|
|
|
|
|
""" |
|
|
Quick test to verify the bounds checking fix. |
|
|
""" |
|
|
|
|
|
import sys |
|
|
from pathlib import Path |
|
|
|
|
|
|
|
|
project_root = Path(__file__).parent.parent |
|
|
sys.path.insert(0, str(project_root)) |
|
|
|
|
|
from src.services.crossword_generator_fixed import CrosswordGeneratorFixed |
|
|
|
|
|
def test_bounds_checking(): |
|
|
"""Test that placement score calculation doesn't crash with out-of-bounds access.""" |
|
|
print("π§ͺ Testing bounds checking fix...") |
|
|
|
|
|
generator = CrosswordGeneratorFixed() |
|
|
|
|
|
|
|
|
grid = [["." for _ in range(5)] for _ in range(5)] |
|
|
|
|
|
|
|
|
placement = { |
|
|
"row": 3, |
|
|
"col": 2, |
|
|
"direction": "vertical" |
|
|
} |
|
|
|
|
|
|
|
|
word = "ELEPHANT" |
|
|
|
|
|
try: |
|
|
|
|
|
score = generator._calculate_placement_score(grid, word, placement, []) |
|
|
print(f"β
Success! Placement score calculated: {score}") |
|
|
print("β
Bounds checking is working correctly") |
|
|
return True |
|
|
except IndexError as e: |
|
|
print(f"β IndexError still occurs: {e}") |
|
|
return False |
|
|
except Exception as e: |
|
|
print(f"β Other error: {e}") |
|
|
return False |
|
|
|
|
|
def test_valid_placement(): |
|
|
"""Test that valid placements still work correctly.""" |
|
|
print("\nπ§ͺ Testing valid placement scoring...") |
|
|
|
|
|
generator = CrosswordGeneratorFixed() |
|
|
|
|
|
|
|
|
grid = [["." for _ in range(8)] for _ in range(8)] |
|
|
grid[2][2] = "A" |
|
|
|
|
|
|
|
|
placement = { |
|
|
"row": 2, |
|
|
"col": 1, |
|
|
"direction": "horizontal" |
|
|
} |
|
|
|
|
|
word = "CAT" |
|
|
|
|
|
try: |
|
|
score = generator._calculate_placement_score(grid, word, placement, []) |
|
|
print(f"β
Valid placement score: {score}") |
|
|
|
|
|
|
|
|
if score > 300: |
|
|
print("β
Intersection detection working") |
|
|
else: |
|
|
print(f"β οΈ Expected intersection bonus, got score {score}") |
|
|
|
|
|
return True |
|
|
except Exception as e: |
|
|
print(f"β Error with valid placement: {e}") |
|
|
return False |
|
|
|
|
|
if __name__ == "__main__": |
|
|
print("π§ Testing crossword generator bounds fix\n") |
|
|
|
|
|
test1_pass = test_bounds_checking() |
|
|
test2_pass = test_valid_placement() |
|
|
|
|
|
if test1_pass and test2_pass: |
|
|
print("\nβ
All tests passed! The bounds checking fix is working.") |
|
|
else: |
|
|
print("\nβ Some tests failed. More work needed.") |