-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathtest.js
More file actions
89 lines (77 loc) · 2.73 KB
/
Copy pathtest.js
File metadata and controls
89 lines (77 loc) · 2.73 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import { parseArgs } from 'util';
import { readFileSync } from 'fs';
import * as hexyModule from "./hexy.js"
import testcases from "./test/testcases.js"
const hexy = hexyModule
var testcase_id = [ 0, 0 ] // some tests have multiple variants (distinguished by the intput). To make the navigation easier, the tests are numbered as [line.subtest]
var failed = 0
var executed = 0
var iterations = 1
var first_testcase_to_exec = 0
var last_testcase_to_exec = testcases.length
const options = parseArgs({
args: process.argv.slice(2),
options: {
perf: { type: 'boolean', short: 'p' },
baseline: { type: 'boolean', short: 'b' },
single: { type: 'string', short: 't' },
verbose: { type: 'boolean', short: 'v' }
}
})
if (options.values.perf) {
iterations = 100000
}
if (options.values.single !== undefined ) {
first_testcase_to_exec = parseInt(options.values.single)
last_testcase_to_exec = first_testcase_to_exec + 1
}
if (options.values.baseline) { // baselining against version 0.3.2, which
last_testcase_to_exec = 29 // had 29 test lines (65 testcases total), that
} // are preserved at the top of the list of tests
function check(should, is) {
if (should !== is) {
console.log("\x1b[31m FAILED testcase # " + testcase_id + "\x1b[0m")
console.log(" EXPECTED")
console.log(should)
console.log(" ACTUALLY RETURNED")
console.log(is)
console.log("more detailed view of EXPECTED:")
console.log(hexy.hexy(should))
console.log("more detailed view of ACTUALLY RETURNED:")
console.log(hexy.hexy(is))
failed++
} else if (options.values.verbose) {
console.log("\x1b[32m SUCCEEDED testcase # " + testcase_id + "\x1b[0m")
console.log(is)
}
executed++
}
for (var rep = 0; rep < iterations; rep++) {
for (var tc = first_testcase_to_exec; tc < last_testcase_to_exec; tc++) {
if ('inputs' in testcases[tc]) {
for (var ii = 0; ii < testcases[tc].inputs.length; ii++) {
testcase_id = [tc, ii]
check(testcases[tc].result, hexy.hexy(testcases[tc].inputs[ii], testcases[tc].config))
}
} else {
testcase_id = tc
check(testcases[tc].result, hexy.hexy(testcases[tc].input, testcases[tc].config))
}
}
}
console.log("Executed: " + executed + ", Failed: " + failed)
if (iterations > 1) {
console.log("This was a perf run over " + iterations + " iterations")
}
function checkVersion () {
const pkg = readFileSync("package.json")
const version = JSON.parse(pkg).version
if (version !== hexy.Hexy.VERSION) {
console.log("\x1b[31m FAILED: the version in package.json and in the code do not match\x1b[0m")
failed++
}
}
checkVersion()
if (failed != 0) {
process.exit(1)
}