This repository was archived by the owner on Jan 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
43 lines (35 loc) · 1.62 KB
/
test.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
const fs = require('fs');
const logicsim = require('./index');
var args = process.argv;
for (let fileIndex = 2; fileIndex < args.length; fileIndex++) {
process.stdout.write("Running test '" + args[fileIndex] + "'.. ");
let config = JSON.parse(fs.readFileSync(args[fileIndex]));
logicsim.newBoard("testBoard_" + fileIndex, config.board);
for (let i = 0; i < config.inputTriggers.length; i++) {
logicsim.triggerInput('testBoard_' + fileIndex, config.inputTriggers[i], 0, 0);
}
logicsim.startBoard('testBoard_' + fileIndex, config.ticks);
while (logicsim.getBoardStatus('testBoard_' + fileIndex).currentState != 1) {}
let boardState = logicsim.getBoard('testBoard_' + fileIndex);
let errorOccurred = false;
for (let i = 0; i < config.expected.components.length; i++) {
for (let j = 0; j < config.expected.components[i].length; j++) {
if (boardState.components[i][j] !== config.expected.components[i][j]) {
if (!errorOccurred)
console.log('\x1b[31m%s\x1b[0m', "failed!");
console.error('\x1b[31m%s\x1b[0m', 'Component[' + i + '][' + j + '] failed (expected: ' + config.expected.components[i] + ', actual: ' + boardState.components[i] + ')');
errorOccurred = true;
}
}
}
for (let i = 0; i < config.expected.links.length; i++) {
if (boardState.links[i] !== config.expected.links[i]) {
if (!errorOccurred)
console.log('\x1b[31m%s\x1b[0m', "failed!");
console.error('\x1b[31m%s\x1b[0m', 'Link[' + i + '] failed (expected: ' + config.expected.links[i] + ', actual: ' + boardState.links[i] + ')');
errorOccurred = true;
}
}
if(!errorOccurred)
console.log('\x1b[32m%s\x1b[0m', 'passed!');
}