-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrunCmd.js
More file actions
41 lines (30 loc) · 977 Bytes
/
Copy pathrunCmd.js
File metadata and controls
41 lines (30 loc) · 977 Bytes
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
var Algo = require('./' + process.argv[2]);
var TestCases = require('./' + process.argv[3]);
var assert = require('assert');
var testCases = TestCases().input;
var results = TestCases().result;
var result;
var testCase;
var testResult;
var testPassed = testCases.length;
var printWrongAnswer = function() {
console.log('Wrong Answer at test case ', i+1, ':');
console.log('Expected Result: ', JSON.stringify(result));
console.log('Returned Result: ', JSON.stringify(testResult));
console.log('\n');
};
console.log('Running tests of ', process.argv[2],
' with test cases:', process.argv[3]);
for (var i = 0; i < testCases.length; i++) {
testCase = testCases[i];
result = results[i];
var testResult = Algo.apply(this, testCase);
try {
assert.deepEqual(testResult, result);
}
catch(e) {
testPassed--;
printWrongAnswer(i, testResult, result);
}
};
console.log(testPassed + '/' + testCases.length + ' test cases passed!');