Skip to content

Commit 020e93f

Browse files
test(2019-day-03): tests for closest wire intersection
1 parent 93a7aea commit 020e93f

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

2019/day-03/wires.test.js

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-env mocha */
22
const expect = require('chai').expect
3-
const { elfWireToSVGPath, findWireIntersections } = require('./wires')
3+
const { elfWireToSVGPath, findWireIntersections, getClosesetIntersection } = require('./wires')
44

55
describe('--- 2019 Day 3: Crossed Wires ---', () => {
66
describe('Part 1', () => {
@@ -16,15 +16,29 @@ describe('--- 2019 Day 3: Crossed Wires ---', () => {
1616
it('finds the intersection points of multiple wires', () => {
1717
const wires = [
1818
'R8,U5,L5,D3',
19-
'U7,R6,D4'
19+
'U7,R6,D4,L4'
2020
]
2121
const expected = [
22-
[3, 3],
23-
[6, 9]
22+
{ x: 0, y: 0, distance: 0 },
23+
{ x: 3, y: -3, distance: 6 },
24+
{ x: 6, y: -5, distance: 11 }
2425
]
2526
const actual = findWireIntersections(wires)
2627
expect(actual).to.deep.equal(expected)
2728
})
2829
})
30+
describe('getClosestIntersection()', () => {
31+
it('finds the closest intersection in a list of intersections', () => {
32+
const intersections = [
33+
{ x: 23, y: 45 },
34+
{ x: 48, y: -10 },
35+
{ x: 3, y: 3 },
36+
{ x: 3, y: 3 }
37+
]
38+
const expected = { x: 3, y: 3, distance: 6 }
39+
const actual = getClosesetIntersection(intersections)
40+
expect(actual).to.deep.equal(expected)
41+
})
42+
})
2943
})
3044
})

0 commit comments

Comments
 (0)