This repository has been archived by the owner on Nov 3, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathjudge.js
53 lines (44 loc) · 1.59 KB
/
judge.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
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
var page = require('webpage').create();
var tests = require('./tests.js').tests;
var runBeforeTests = require('./tests.js').runBeforeTests;
function equal(expected, received) {
return expected == received;
};
function equalDiff(expected, received, diff) {
return Math.abs(expected - received) <= diff;
};
function compare(functionName, expected, received, param) {
if (received === null && expected !== null) return false;
if (received === undefined && expected !== undefined) return false;
if (functionName == "equal")
return equal(expected, received);
if (functionName == "equalDiff")
return equalDiff(expected, received, param);
};
page.viewportSize = { width: 1024, height: 768 };
page.open('index.html', function (status) {
if (status !== 'success') {
console.log(status);
return;
}
if (runBeforeTests) page.evaluate(runBeforeTests);
page.render('image.png');
var points = 0;
var maxPoints = 0;
for (var i = 0; i < tests.length; i++) {
test = tests[i];
console.log(test.name);
var result = page.evaluate(test.func);
console.log("expected: " + test.expected + "\nreceived: " + result);
if (compare(test.compare, test.expected, result, test.compareParam)) {
points += test.points;
console.log("Correct! +" + test.points);
} else {
console.log("--- Wrong");
}
maxPoints += test.points;
console.log("==========================");
};
console.log("Total points: " + points + " / " + maxPoints);
phantom.exit();
});