-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathindex.js
27 lines (24 loc) · 871 Bytes
/
index.js
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
function runAdditionTest(studentAddFunction) {
const testCases = [
{ input: [1, 2], output: 3 },
{ input: [4, 5], output: 9 },
{ input: [10, -5], output: 5 },
];
for (let i = 0; i < testCases.length; i++) {
const testCase = testCases[i];
const input = testCase.input;
const expectedOutput = testCase.output;
let studentOutput;
try {
studentOutput = studentAddFunction(...input);
} catch (error) {
console.error(`Error executing student's code for test case ${i + 1}:`, error);
continue;
}
if (studentOutput === expectedOutput) {
console.log(`Test case ${i + 1} passed!`);
} else {
console.log(`Test case ${i + 1} failed. Expected ${expectedOutput}, but received ${studentOutput}.`);
}
}
}