Converted all mscript tests to Qunit tests.

This commit is contained in:
mmcw-dev 2018-03-16 12:22:34 -04:00
parent 1373d1d690
commit a6a910c909
3 changed files with 87 additions and 117 deletions

View File

@ -3,87 +3,109 @@
const mscript = require('../lib/mscript'); const mscript = require('../lib/mscript');
QUnit.test(`Basic functions`, (assert) => { QUnit.test(`Basic functions`, (assert) => {
const script = 'CF\nPF\nCB\nPB\nBF\nBB'; const script1 = 'CF\nPF\nCB\nPB\nBF\nBB';
let pass = false; const script2 = `CF 3\nPF 3`
mscript.interpret(script, (obj) => { assert.expect( 2 );
mscript.interpret(script1, (obj) => {
let pass = false;
if (obj.success === true if (obj.success === true
&& obj.cam === 0 && obj.cam === 0
&& obj.proj === 0 && obj.proj === 0
&& obj.arr.length === 6) { && obj.arr.length === 6) {
pass = true; pass = true;
} }
assert.ok(pass, `Simple script compiles`) assert.ok(pass, `Simple script1 compiles`)
});
mscript.interpret(script2, (obj) => {
let pass = false;
if (obj.success === true
&& obj.cam === 3
&& obj.proj === 3
&& obj.arr.length === 6) {
pass = true;
}
assert.ok(pass, `Simple script2 compiles`)
});
});
QUnit.test(`Commands with integers`, (assert) => {
const script = 'CF 5\nPF 5\nCB 5\nPB 5\nBF 3\nBB 3';
assert.expect( 1 );
mscript.interpret(script, (obj) => {
let pass = false;
if (obj.success === true
&& obj.cam === 0
&& obj.proj === 0
&& obj.arr.length === 26) {
pass = true;
}
assert.ok(pass, `Script with integers cancels out count, but generates list of commands`)
}); });
}) })
/*
console.log('Basic function test...');
mscript.interpret(script, function (obj) {
if (obj.success === true
&& obj.cam === 0
&& obj.proj === 0
&& obj.arr.length === 6) {
console.log('...Passed!');
} else {
fail(script, obj);
}
});
var script = 'CF\nPF\nCB\nPB\nBF\nBB';
console.log('Functions with integers test...');
mscript.interpret(script, function (obj) {
if (obj.success === true
&& obj.cam === 0
&& obj.proj === 0
&& obj.arr.length === 6) {
console.log('...Passed!');
} else {
fail(script, obj);
}
});
script = 'CF 1000\nCB 1000\nSET PROJ 200\nPB 200'; QUnit.test('State', (assert) => {
console.log('Basic state test...'); const script = 'CF 1000\nCB 1000\nSET PROJ 200\nPB 200';
mscript.interpret(script, function (obj) { assert.expect(1);
mscript.interpret(script, (obj) => {
let pass = false;
if (obj.success === true if (obj.success === true
&& obj.cam === 0 && obj.cam === 0
&& obj.proj === 0) { && obj.proj === 0) {
console.log('...Passed!'); pass = true;
} else {
fail(script, obj);
} }
assert.ok(pass, `Basic state test`);
}); });
});
script = 'LOOP 10\nCF 3\nPF 1\nEND LOOP'; QUnit.test('Loop', (assert) => {
console.log('Basic loop test...'); const script1 = 'LOOP 10\nCF 3\nPF 1\nEND LOOP';
mscript.interpret(script, function (obj) { assert.expect(3);
mscript.interpret(script1, (obj) => {
let pass = false;
if (obj.success === true if (obj.success === true
&& obj.cam === 30 && obj.cam === 30
&& obj.proj === 10 && obj.proj === 10
&& obj.arr.length === 40) { && obj.arr.length === 40) {
console.log('...Passed!'); pass = true;
} else {
fail(script, obj);
} }
}); assert.ok(pass, 'Basic loop');
script = 'LOOP 4\nLOOP 4\nPF\nBF\nEND LOOP\nEND LOOP'; });
console.log('Recursive loop test...'); const script2 = 'LOOP 4\nLOOP 4\nPF\nBF\nEND LOOP\nEND LOOP';
mscript.interpret(script, function (obj) { mscript.interpret(script2, (obj) => {
let pass = false;
if (obj.success === true if (obj.success === true
&& obj.cam === 16 && obj.cam === 16
&& obj.proj === 16 && obj.proj === 16
&& obj.arr.length === 32) { && obj.arr.length === 32) {
console.log('...Passed!'); pass = true;
} else {
fail(script, obj);
} }
assert.ok(pass, 'Recursive loop');
}); });
//LOOP W/ CAM and PROJ
const script3 = 'LOOP 2\nCAM 4\nPROJ 4\nEND';
mscript.interpret(script3, (obj) => {
let pass = false;
if (obj.success === true
&& obj.cam === 8
&& obj.proj === 8
&& obj.arr.length === 16
&& obj.light.length === 16
&& obj.light[0] === mscript.black) {
pass = true;
}
assert.ok(pass, 'Basic cam/proj loop');
});
});
QUnit.test('Light', (assert) => {
//Lighting tests //Lighting tests
script = 'L 255,255,255\nCF\nPF'; const script1 = 'L 255,255,255\nCF\nPF';
console.log('Basic light test...'); assert.expect(3);
mscript.interpret(script, function (obj) { mscript.interpret(script1, (obj) => {
let pass = false;
if (obj.success === true if (obj.success === true
&& obj.cam === 1 && obj.cam === 1
&& obj.proj === 1 && obj.proj === 1
@ -91,14 +113,14 @@ QUnit.test(`Basic functions`, (assert) => {
&& obj.light.length === 2 && obj.light.length === 2
&& obj.light[0] === '255,255,255' && obj.light[0] === '255,255,255'
&& obj.light[1] === '') { && obj.light[1] === '') {
console.log('...Passed!'); pass = true;
} else {
fail(script, obj);
} }
assert.ok(pass, 'Basic light');
}); });
script = 'L 255,255,255\nCF\nPF\nBF';
console.log('Basic black test...'); const script2 = 'L 255,255,255\nCF\nPF\nBF';
mscript.interpret(script, function (obj) { mscript.interpret(script2, (obj) => {
let pass = false;
if (obj.success === true if (obj.success === true
&& obj.cam === 2 && obj.cam === 2
&& obj.proj === 1 && obj.proj === 1
@ -107,14 +129,13 @@ QUnit.test(`Basic functions`, (assert) => {
&& obj.light[0] === '255,255,255' && obj.light[0] === '255,255,255'
&& obj.light[1] === '' && obj.light[1] === ''
&& obj.light[2] === mscript.black) { && obj.light[2] === mscript.black) {
console.log('...Passed!'); pass = true;
} else {
fail(script, obj);
} }
assert.ok(pass, 'Basic black');
}); });
script = 'LOOP 2\nL 1,1,1\nCF\nL 2,2,2\nCF\nEND'; const script3 = 'LOOP 2\nL 1,1,1\nCF\nL 2,2,2\nCF\nEND';
console.log('Basic light loop test...'); mscript.interpret(script3, (obj) => {
mscript.interpret(script, function (obj) { let pass = false;
if (obj.success === true if (obj.success === true
&& obj.cam === 4 && obj.cam === 4
&& obj.proj === 0 && obj.proj === 0
@ -122,25 +143,8 @@ QUnit.test(`Basic functions`, (assert) => {
&& obj.light.length === 4 && obj.light.length === 4
&& obj.light[0] === '1,1,1' && obj.light[0] === '1,1,1'
&& obj.light[3] === '2,2,2') { && obj.light[3] === '2,2,2') {
console.log('...Passed!'); pass = true;
} else {
fail(script, obj);
} }
assert.ok(pass, 'Basic light');
}); });
});
//LOOP W/ CAM and PROJ
script = 'LOOP 2\nCAM 4\nPROJ 4\nEND';
console.log('Basic cam/proj loop test...');
mscript.interpret(script, function (obj) {
if (obj.success === true
&& obj.cam === 8
&& obj.proj === 8
&& obj.arr.length === 16
&& obj.light.length === 16
&& obj.light[0] === mscript.black) {
console.log('...Passed!');
} else {
fail(script, obj);
}
});
*/

View File

@ -1,31 +0,0 @@
var fs = require('fs'),
mcopy = {};
mcopy.cfg = JSON.parse(fs.readFileSync('./cfg.json', 'utf8'));
mcopy.arduino = require('../lib/mcopy-arduino.js')(mcopy.cfg);
mcopy.arduino.colorTest = function (color, cb) {
mcopy.arduino.send(mcopy.cfg.arduino.cmd.light, function () {
console.log('Light set to ' + color);
if (cb) setTimeout(cb, 20);
});
mcopy.arduino.string(color);
};
mcopy.arduino.init(function (success) {
mcopy.arduino.connect(function () {
/*
mcopy.arduino.colorTest('255,140,70', function () {
mcopy.arduino.colorTest('5,0,0', function () {
mcopy.arduino.colorTest('255,255,255', function () {
mcopy.arduino.colorTest('160,14,250', function () {
mcopy.arduino.colorTest('5,32,200', function () {
});//5
});//4
});//3
});//2
});//1
*/
});
});

View File

@ -1,3 +0,0 @@
var mscript = require('../lib/mscript.js');
mscript.tests();