sanket3280/code-execution
0
1/**2 * Test Unified Execution System3 * Quick test to verify the system works4 */5 6const UnifiedExecutionService = require('./services/execution/unified/UnifiedExecutionService');7 8async function testJavaScriptExecution() {9 console.log('\n๐งช Testing JavaScript Execution...\n');10 11 const service = new UnifiedExecutionService();12 13 // Test: Two Sum problem14 const sourceCode = `15function solution(nums, target) {16 const map = new Map();17 for (let i = 0; i < nums.length; i++) {18 const complement = target - nums[i];19 if (map.has(complement)) {20 return [map.get(complement), i];21 }22 map.set(nums[i], i);23 }24 return [];25}26`;27 28 const testCases = [29 { input: { nums: [2, 7, 11, 15], target: 9 }, expected: [0, 1] },30 { input: { nums: [3, 2, 4], target: 6 }, expected: [1, 2] },31 { input: { nums: [3, 3], target: 6 }, expected: [0, 1] }32 ];33 34 try {35 const result = await service.executeTestCases({36 sourceCode,37 language: 'JAVASCRIPT_NODE',38 testCases,39 metadata: {40 problemId: 'test-two-sum',41 category: 'array',42 timeLimit: 3,43 memoryLimit: 25644 },45 runAllTestCases: true46 });47 48 console.log('โ
Execution Result:');49 console.log(JSON.stringify(result, null, 2));50 51 if (result.summary.passed === result.summary.total) {52 console.log('\nโ
All tests passed!');53 return true;54 } else {55 console.log(`\nโ ๏ธ ${result.summary.passed}/${result.summary.total} tests passed`);56 return false;57 }58 } catch (error) {59 console.error('โ Test failed:', error.message);60 console.error(error.stack);61 return false;62 }63}64 65async function testPythonExecution() {66 console.log('\n๐งช Testing Python Execution...\n');67 68 const service = new UnifiedExecutionService();69 70 // Test: Palindrome check71 const sourceCode = `72def solution(s):73 cleaned = ''.join(c.lower() for c in s if c.isalnum())74 return cleaned == cleaned[::-1]75`;76 77 const testCases = [78 { input: { s: "A man, a plan, a canal: Panama" }, expected: true },79 { input: { s: "race a car" }, expected: false },80 { input: { s: " " }, expected: true }81 ];82 83 try {84 const result = await service.executeTestCases({85 sourceCode,86 language: 'PYTHON3',87 testCases,88 metadata: {89 problemId: 'test-palindrome',90 category: 'string',91 timeLimit: 3,92 memoryLimit: 25693 },94 runAllTestCases: true95 });96 97 console.log('โ
Execution Result:');98 console.log(JSON.stringify(result, null, 2));99 100 if (result.summary.passed === result.summary.total) {101 console.log('\nโ
All tests passed!');102 return true;103 } else {104 console.log(`\nโ ๏ธ ${result.summary.passed}/${result.summary.total} tests passed`);105 return false;106 }107 } catch (error) {108 console.error('โ Test failed:', error.message);109 console.error(error.stack);110 return false;111 }112}113 114async function runAllTests() {115 console.log('โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ');116 console.log('โ UNIFIED EXECUTION SYSTEM - TEST SUITE โ');117 console.log('โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ');118 119 const results = [];120 121 // Test JavaScript122 results.push(await testJavaScriptExecution());123 124 // Test Python125 results.push(await testPythonExecution());126 127 // Summary128 console.log('\nโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ');129 console.log('โ TEST SUMMARY โ');130 console.log('โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ\n');131 132 const passed = results.filter(r => r).length;133 const total = results.length;134 135 console.log(`Tests Passed: ${passed}/${total}`);136 137 if (passed === total) {138 console.log('\nโ
All tests passed! System is working correctly.\n');139 process.exit(0);140 } else {141 console.log('\nโ Some tests failed. Please check the errors above.\n');142 process.exit(1);143 }144}145 146// Run tests147runAllTests().catch(error => {148 console.error('Fatal error:', error);149 process.exit(1);150});151 