-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
71 lines (63 loc) · 1.73 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
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
'use strict';
var FindEasterBunnyHQ = require("./gobunny.js").FindEasterBunnyHQ;
/**
* Test EasterBunnyHQ using the provided examples from http://adventofcode.com/2016/day/1
*/
/**
*
* @param {Array} testInput - array of objects with test input and expected result
* @constructor
*/
function Test(testInput) {
this.testInput = testInput;
}
/**
* Execute running the EasterBunnyHQ app and checks results
*/
Test.prototype.runTest = function () {
console.log('\n****** Running FindEasterBunnyHQ Tests ******\n');
var bunnyTrip;
this.testInput.forEach(function (input) {
console.log('\nTest', input.id, '_______________');
console.log(' input sequence', input.sequence);
bunnyTrip = new FindEasterBunnyHQ(input.sequence);
bunnyTrip.go();
console.log(' Expected Blocks:', input.expectedBlocksAway, ' Actual Blocks:', bunnyTrip.minimumBlocksAway);
if (bunnyTrip.minimumBlocksAway === input.expectedBlocksAway) {
console.log(' Yipee! Test passed!');
} else {
console.log(' UhOh. Test failed. :( ');
}
});
};
var testInput = [
{
id: 1,
sequence: ['R2', 'L3'],
expectedBlocksAway: 5
},
{
id: 2,
sequence: ['R2', 'R2', 'R2'],
expectedBlocksAway: 2
},
{
id: 3,
sequence: ['R5', 'L5', 'R5', 'R3'],
expectedBlocksAway: 12
},
{
id: 4,
sequence: ['L2', 'L1', 'L4', 'R1', 'R6', 'R5', 'R6'],
expectedBlocksAway: 5
}
];
/**
* Export function to call via npm script command using make-runnable module
*/
function run() {
var test = new Test(testInput);
test.runTest();
}
module.exports = run;
require('make-runnable');