|
1 | 1 | /* eslint-env mocha */
|
2 | 2 | const { expect } = require('chai')
|
3 |
| -const { render, chartLine, parseLines } = require('./vents') |
| 3 | +const { render, chartLine, parseLines, countIntersections } = require('./vents') |
4 | 4 |
|
5 | 5 | const testData = `0,9 -> 5,9
|
6 | 6 | 8,0 -> 0,8
|
@@ -58,17 +58,30 @@ describe('--- Day 5: Hydrothermal Venture ---', () => {
|
58 | 58 | data = chartLine(data, 3, 4, 1, 4)
|
59 | 59 | expect(render(data)).to.equal(sampleMap)
|
60 | 60 | })
|
61 |
| - }) |
62 |
| - it('skips diagonal lines', () => { |
63 |
| - // 10x10 empty grid |
64 |
| - let data = [...new Array(10)].map(() => { |
65 |
| - return [...new Array(10)].map(() => 0) |
| 61 | + it('skips diagonal lines', () => { |
| 62 | + // 10x10 empty grid |
| 63 | + let data = [...new Array(10)].map(() => { |
| 64 | + return [...new Array(10)].map(() => 0) |
| 65 | + }) |
| 66 | + // Map some lines |
| 67 | + parsedTestData.forEach((row) => { |
| 68 | + data = chartLine(data, ...row) |
| 69 | + }) |
| 70 | + expect(render(data)).to.equal(sampleMap) |
66 | 71 | })
|
67 |
| - // Map some lines |
68 |
| - parsedTestData.forEach((row) => { |
69 |
| - data = chartLine(data, ...row) |
| 72 | + }) |
| 73 | + describe('countIntersections()', () => { |
| 74 | + it('counts how many intersections exist of (n) lines or more', () => { |
| 75 | + // 10x10 empty grid |
| 76 | + let data = [...new Array(10)].map(() => { |
| 77 | + return [...new Array(10)].map(() => 0) |
| 78 | + }) |
| 79 | + // Map some lines |
| 80 | + parsedTestData.forEach((row) => { |
| 81 | + data = chartLine(data, ...row) |
| 82 | + }) |
| 83 | + expect(countIntersections(data, 2)).to.equal(5) |
70 | 84 | })
|
71 |
| - expect(render(data)).to.equal(sampleMap) |
72 | 85 | })
|
73 | 86 | })
|
74 | 87 | })
|
0 commit comments