File size: 3,233 Bytes
93c4f75
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import os
import sys
import time

# Add the parent directory to the path so we can import our modules
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

from models.braille_translator import text_to_braille, get_braille_metadata

def test_braille_translation(text):
    """
    Test Braille translation on a given text.
    
    Args:
        text: Text to translate to Braille
        
    Returns:
        Dictionary with test results
    """
    start_time = time.time()
    
    # Translate to Braille
    try:
        result = text_to_braille(text, use_context=True)
        success = result['success']
        braille_text = result.get('formatted_braille', '')
        error = result.get('error', None)
    except Exception as e:
        success = False
        braille_text = ''
        error = str(e)
    
    end_time = time.time()
    
    # Get metadata
    metadata = get_braille_metadata(text)
    
    # Compile results
    test_results = {
        'original_text': text,
        'success': success,
        'processing_time': end_time - start_time,
        'braille_text': braille_text[:100] + '...' if len(braille_text) > 100 else braille_text,
        'word_count': metadata['word_count'],
        'character_count': metadata['character_count'],
        'line_count': metadata['line_count']
    }
    
    if not success:
        test_results['error'] = error
        
    return test_results

def run_braille_tests():
    """
    Run tests on sample menu texts.
    
    Returns:
        List of test results
    """
    # Sample menu texts
    sample_texts = [
        # Simple menu item
        "Cheeseburger - $10.99\nServed with fries and a pickle.",
        
        # Menu section
        "APPETIZERS\n-----------\nMozzarella Sticks - $7.99\nLoaded Nachos - $9.99\nBuffalo Wings - $12.99",
        
        # Complex menu with formatting
        """MAIN COURSE
        -------------
        Grilled Salmon - $18.99
        Fresh Atlantic salmon served with seasonal vegetables and rice pilaf.
        
        Filet Mignon - $24.99
        8oz center-cut filet served with mashed potatoes and asparagus.
        
        Vegetable Pasta - $14.99
        Penne pasta with seasonal vegetables in a creamy garlic sauce."""
    ]
    
    results = []
    
    for i, text in enumerate(sample_texts):
        print(f"\nTesting sample {i+1}...")
        result = test_braille_translation(text)
        results.append(result)
        
        # Print progress
        status = "SUCCESS" if result['success'] else "FAILED"
        print(f"Sample {i+1}: {status}")
        print(f"Words: {result['word_count']}, Time: {result['processing_time']:.2f}s")
        print(f"Braille sample: {result['braille_text'][:50]}...")
            
    return results

if __name__ == "__main__":
    print("Testing Braille translation functionality...")
    results = run_braille_tests()
    
    # Print summary
    success_count = sum(1 for r in results if r['success'])
    print(f"\nSummary: {success_count}/{len(results)} tests passed")
    
    if results:
        avg_time = sum(r['processing_time'] for r in results) / len(results)
        print(f"Average processing time: {avg_time:.2f} seconds")