this repo has no description
1var expect = require('chai').expect;
2var Day6 = require('../lib/day6');
3
4describe('Day6', function() {
5 var grid;
6
7 beforeEach(function() {
8 grid = Day6.buildGrid(2, 3);
9 });
10
11 describe('#buildGrid', function() {
12 it('builds a grid of booleans from specified dimensions', function() {
13 expect(grid).to.eql([
14 [0, 0],
15 [0, 0],
16 [0, 0]
17 ]);
18 });
19 });
20
21 describe('#turnOn', function() {
22 it('makes sure lights are ON in specified range', function() {
23 grid = Day6.turnOn(grid, [0,0], [1,1]);
24 expect(grid).to.eql([
25 [1, 1],
26 [1, 1],
27 [0, 0]
28 ]);
29 });
30 });
31
32 describe('#turnOff', function() {
33 it('makes sure lights are OFF in specified range', function() {
34 grid = Day6.turnOn(grid, [0,0], [1,1]);
35 grid = Day6.turnOff(grid, [0,1], [1,1]);
36
37 expect(grid).to.eql([
38 [1, 0],
39 [1, 0],
40 [0, 0]
41 ]);
42 });
43 });
44
45 describe('#toggle', function() {
46 it('TOGGLES the lights at specified range', function() {
47 grid = Day6.turnOn(grid, [0,0], [1,1]);
48 grid = Day6.toggle(grid, [0,1], [1,1]);
49
50 expect(grid).to.eql([
51 [1, 0],
52 [1, 0],
53 [0, 0]
54 ]);
55 });
56 });
57
58 describe('#reduceBrightness', function() {
59 it('reduces the brightness of specified range by 1, to a min of 0', function() {
60 grid = Day6.toggle(grid, [0,0], [2,1]);
61 grid = Day6.reduceBrightness(grid, [0,0], [0,1]);
62 grid = Day6.reduceBrightness(grid, [0,0], [0,1]);
63
64 expect(grid).to.eql([
65 [0, 0],
66 [1, 1],
67 [1, 1]
68 ]);
69 });
70 });
71
72 describe('#increaseBrightness', function() {
73 it('increase the brightness of a specified range by 1', function() {
74 grid = Day6.toggle(grid, [0,0], [2,1]);
75 grid = Day6.increaseBrightness(grid, [0,0], [0,1]);
76
77 expect(grid).to.eql([
78 [2, 2],
79 [1, 1],
80 [1, 1]
81 ]);
82 });
83 });
84
85 describe('#totalBrightness', function() {
86 it('calculates the total brightness of all lights in the grid', function() {
87 grid = Day6.toggle(grid, [0,0], [2,1]);
88
89 expect(grid).to.eql([
90 [1, 1],
91 [1, 1],
92 [1, 1]
93 ]);
94
95 expect(Day6.totalBrightness(grid)).to.equal(6);
96 });
97 });
98
99 describe('#processInstruction1', function() {
100 it('turns a text instruction into a command with to and from coords', function() {
101 var instructions = [
102 'turn on 0,0 through 1,1',
103 'turn off 0,1 through 1,1',
104 'toggle 0,0 through 2,0'
105 ];
106
107 instructions.forEach(function(instruction) {
108 grid = Day6.processInstruction1(grid, instruction);
109 });
110
111 expect(grid).to.eql([
112 [0, 0],
113 [0, 0],
114 [1, 0]
115 ]);
116 });
117 });
118
119 describe('#processInstruction2', function() {
120 it('turns a text instruction into a command with to and from coords', function() {
121 var instructions = [
122 'turn off 0,0 through 2,1',
123 'turn on 0,0 through 1,1',
124 'turn off 0,1 through 1,1',
125 'toggle 0,0 through 2,0'
126 ];
127
128 instructions.forEach(function(instruction) {
129 grid = Day6.processInstruction2(grid, instruction);
130 });
131
132 expect(grid).to.eql([
133 [3, 0],
134 [3, 0],
135 [2, 0]
136 ]);
137 });
138 });
139
140 describe('#countLightsOn', function() {
141 it('returns the number of lights that are on', function() {
142 grid = Day6.turnOn(grid, [0,0], [1,0]);
143 expect(Day6.countLightsOn(grid)).to.equal(2);
144 });
145 });
146});