mtg_python_deckbuilder/test_fuzzy_logic.py
matt cfcc01db85 feat: complete M3 Web UI Enhancement milestone with include/exclude cards, fuzzy matching, mobile responsive design, and performance optimization
- Include/exclude cards feature complete with 300+ card knowledge base and intelligent fuzzy matching
- Enhanced visual validation with warning icons and performance benchmarks (100% pass rate)
- Mobile responsive design with bottom-floating controls, two-column layout, and horizontal scroll prevention
- Dark theme confirmation modal for fuzzy matches with card preview and alternatives
- Dual architecture support for web UI staging system and CLI direct build paths
- All M3 checklist items completed: fuzzy match modal, enhanced algorithm, summary panel, mobile responsive, Playwright tests
2025-09-09 18:15:30 -07:00

83 lines
2.6 KiB
Python

#!/usr/bin/env python3
"""
Direct test of fuzzy matching functionality.
"""
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'code'))
from deck_builder.include_exclude_utils import fuzzy_match_card_name
def test_fuzzy_matching_direct():
"""Test fuzzy matching directly."""
print("🔍 Testing fuzzy matching directly...")
# Create a small set of available cards
available_cards = {
'Lightning Bolt',
'Lightning Strike',
'Lightning Helix',
'Chain Lightning',
'Sol Ring',
'Mana Crypt'
}
# Test with typo that should trigger low confidence
result = fuzzy_match_card_name('Lighning', available_cards) # Worse typo
print("Input: 'Lighning'")
print(f"Matched name: {result.matched_name}")
print(f"Auto accepted: {result.auto_accepted}")
print(f"Confidence: {result.confidence:.2%}")
print(f"Suggestions: {result.suggestions}")
if result.matched_name is None and not result.auto_accepted and result.suggestions:
print("✅ Fuzzy matching correctly triggered confirmation!")
return True
else:
print("❌ Fuzzy matching should have triggered confirmation")
return False
def test_exact_match_direct():
"""Test exact matching directly."""
print("\n🎯 Testing exact match directly...")
available_cards = {
'Lightning Bolt',
'Lightning Strike',
'Lightning Helix',
'Sol Ring'
}
result = fuzzy_match_card_name('Lightning Bolt', available_cards)
print(f"Input: 'Lightning Bolt'")
print(f"Matched name: {result.matched_name}")
print(f"Auto accepted: {result.auto_accepted}")
print(f"Confidence: {result.confidence:.2%}")
if result.matched_name and result.auto_accepted:
print("✅ Exact match correctly auto-accepted!")
return True
else:
print("❌ Exact match should have been auto-accepted")
return False
if __name__ == "__main__":
print("🧪 Testing Fuzzy Matching Logic")
print("=" * 40)
test1_pass = test_fuzzy_matching_direct()
test2_pass = test_exact_match_direct()
print("\n📋 Test Summary:")
print(f" Fuzzy confirmation: {'✅ PASS' if test1_pass else '❌ FAIL'}")
print(f" Exact match: {'✅ PASS' if test2_pass else '❌ FAIL'}")
if test1_pass and test2_pass:
print("\n🎉 Fuzzy matching logic working correctly!")
else:
print("\n🔧 Issues found in fuzzy matching logic")
exit(0 if test1_pass and test2_pass else 1)