|
| 1 | +/** |
| 2 | + * Test script to verify batch selection extraction |
| 3 | + * Tests that conversational inputs like "my batch is 23" extract "23" |
| 4 | + */ |
| 5 | + |
| 6 | +console.log('🧪 Testing Batch Selection Extraction\n'); |
| 7 | +console.log('━'.repeat(80)); |
| 8 | + |
| 9 | +// Batch extraction phrases |
| 10 | +const BATCH_PHRASES = [ |
| 11 | + 'my batch is', 'our batch is', 'batch is', 'the batch is', |
| 12 | + 'we are batch', 'we are from batch', 'i am from batch', 'i am in batch', |
| 13 | + 'our batch', 'my batch', 'batch', 'we are in batch', 'from batch' |
| 14 | +]; |
| 15 | + |
| 16 | +// Extraction function |
| 17 | +function extractFromConversational(input: string, phrases: string[]): string { |
| 18 | + let result = input.trim(); |
| 19 | + const lowerInput = result.toLowerCase(); |
| 20 | + |
| 21 | + for (const phrase of phrases) { |
| 22 | + if (lowerInput.includes(phrase)) { |
| 23 | + const phraseIndex = lowerInput.indexOf(phrase); |
| 24 | + const afterPhrase = result.substring(phraseIndex + phrase.length).trim(); |
| 25 | + |
| 26 | + if (afterPhrase.length >= 1) { |
| 27 | + result = afterPhrase; |
| 28 | + console.log(` 🔍 Detected phrase "${phrase}" → Extracting...`); |
| 29 | + break; |
| 30 | + } |
| 31 | + } |
| 32 | + } |
| 33 | + |
| 34 | + return result; |
| 35 | +} |
| 36 | + |
| 37 | +// Batch validator (must be "23" or "24") |
| 38 | +function validateBatch(batch: string): boolean { |
| 39 | + return /^(23|24)$/.test(batch); |
| 40 | +} |
| 41 | + |
| 42 | +// Test cases for batch extraction |
| 43 | +const testCases = [ |
| 44 | + // Conversational inputs with "is" |
| 45 | + { input: 'my batch is 23', expected: '23', description: 'Conversational: "my batch is 23"' }, |
| 46 | + { input: 'our batch is 24', expected: '24', description: 'Conversational: "our batch is 24"' }, |
| 47 | + { input: 'batch is 23', expected: '23', description: 'Conversational: "batch is 23"' }, |
| 48 | + { input: 'the batch is 24', expected: '24', description: 'Conversational: "the batch is 24"' }, |
| 49 | + |
| 50 | + // Conversational inputs without "is" |
| 51 | + { input: 'our batch 23', expected: '23', description: 'Short: "our batch 23"' }, |
| 52 | + { input: 'my batch 24', expected: '24', description: 'Short: "my batch 24"' }, |
| 53 | + |
| 54 | + // "We are" patterns |
| 55 | + { input: 'we are batch 23', expected: '23', description: 'We are: "we are batch 23"' }, |
| 56 | + { input: 'we are from batch 24', expected: '24', description: 'We are from: "we are from batch 24"' }, |
| 57 | + { input: 'we are in batch 23', expected: '23', description: 'We are in: "we are in batch 23"' }, |
| 58 | + |
| 59 | + // "I am" patterns |
| 60 | + { input: 'i am from batch 24', expected: '24', description: 'I am from: "i am from batch 24"' }, |
| 61 | + { input: 'i am in batch 23', expected: '23', description: 'I am in: "i am in batch 23"' }, |
| 62 | + |
| 63 | + // "from batch" pattern |
| 64 | + { input: 'from batch 24', expected: '24', description: 'From batch: "from batch 24"' }, |
| 65 | + |
| 66 | + // Direct input (no extraction needed) |
| 67 | + { input: '23', expected: '23', description: 'Direct: "23"' }, |
| 68 | + { input: '24', expected: '24', description: 'Direct: "24"' }, |
| 69 | + |
| 70 | + // Edge cases with capitalization |
| 71 | + { input: 'My Batch Is 23', expected: '23', description: 'Capitalized: "My Batch Is 23"' }, |
| 72 | + { input: 'OUR BATCH IS 24', expected: '24', description: 'Uppercase: "OUR BATCH IS 24"' }, |
| 73 | +]; |
| 74 | + |
| 75 | +console.log('\n📝 Running Test Cases:\n'); |
| 76 | + |
| 77 | +let passed = 0; |
| 78 | +let failed = 0; |
| 79 | + |
| 80 | +testCases.forEach((testCase, index) => { |
| 81 | + const extracted = extractFromConversational(testCase.input, BATCH_PHRASES); |
| 82 | + const result = extracted.trim(); |
| 83 | + const isValid = validateBatch(result); |
| 84 | + const testPassed = result === testCase.expected && isValid; |
| 85 | + |
| 86 | + if (testPassed) { |
| 87 | + console.log(`✅ Test ${index + 1}: PASS`); |
| 88 | + console.log(` Description: ${testCase.description}`); |
| 89 | + console.log(` Input: "${testCase.input}"`); |
| 90 | + console.log(` Expected: "${testCase.expected}" | Got: "${result}" | Valid: ${isValid}\n`); |
| 91 | + passed++; |
| 92 | + } else { |
| 93 | + console.log(`❌ Test ${index + 1}: FAIL`); |
| 94 | + console.log(` Description: ${testCase.description}`); |
| 95 | + console.log(` Input: "${testCase.input}"`); |
| 96 | + console.log(` Expected: "${testCase.expected}" | Got: "${result}" | Valid: ${isValid}\n`); |
| 97 | + failed++; |
| 98 | + } |
| 99 | +}); |
| 100 | + |
| 101 | +console.log('━'.repeat(80)); |
| 102 | +console.log(`\n📊 Results: ${passed}/${testCases.length} passed`); |
| 103 | +console.log(` ✅ Passed: ${passed}`); |
| 104 | +console.log(` ❌ Failed: ${failed}`); |
| 105 | +console.log(` Success Rate: ${Math.round((passed / testCases.length) * 100)}%\n`); |
| 106 | + |
| 107 | +if (failed === 0) { |
| 108 | + console.log('🎉 All tests passed! Batch extraction working perfectly!\n'); |
| 109 | + process.exit(0); |
| 110 | +} else { |
| 111 | + console.log('⚠️ Some tests failed. Please review the implementation.\n'); |
| 112 | + process.exit(1); |
| 113 | +} |
0 commit comments