forked from domachine/latexasq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
unittest.js
64 lines (49 loc) · 1.42 KB
/
unittest.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
54
55
56
57
58
59
60
61
62
63
64
// Unit testing
globalsN = require('./globals.js');
antN = require('./ant.js');
nodeN = require('./node.js');
graphvizN = require('./graphviz.js');
function assert (cond) {
if (! cond ())
error ("condition failed: " + cond);
}
function buildPathTest () {
var path = nodeN.buildPath (5);
var testNode = function (node, pathDepth) {
if (pathDepth == 0)
assert (function () {node.right === undefined});
else
assert (function () {node.right !== undefined});
};
}
function addAnts (root) {
var countAnts = Math.floor(Math.random() * globalsN.MAX_ANTS);
var ants = new Array(countAnts);
for(var i = 0; i < countAnts; i++){
ants[i] = antN.Ant();
ants[i].stepcount = root.stepcount;
}
root.ants = ants;
}
function main(){
root = nodeN.buildPath (5);
addAnts(root);
var id = (new Date()).getTime();
graphvizN.save(root, id);
var stdin = process.openStdin();
require('tty').setRawMode(true);
stdin.on('keypress', function (chunk, key) {
if(key && key.name == 's')
process.nextTick(function(){
console.log("step");
antN.step(root);
addAnts(root);
graphvizN.save(root, id);
});
if (key && key.ctrl && key.name == 'c') process.exit();
});
}
function runTests () {
buildPathTest ();
}
main ();