Skip to content

Commit aa83c0b

Browse files
test(20190-day-03): specs for finding closest wire intersection by wire distance
1 parent 5df7932 commit aa83c0b

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

2019/day-03/wires.test.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,37 @@ describe('--- 2019 Day 3: Crossed Wires ---', () => {
5555
expect(getClosesetIntersection(findWireIntersections(wires)).distance).to.equal(distances[idx])
5656
})
5757
})
58+
describe('getIntersectionWireDistance()', () => {
59+
it('calculates the summed total wire length to reach the specified intersection', () => {
60+
const wires = [
61+
'R8,U5,L5,D3',
62+
'U7,R6,D4,L4'
63+
]
64+
const expected = [
65+
40, 30
66+
]
67+
const intersections = findWireIntersections(...wires)
68+
const actual = intersections.map((inter) => getIntersectionWireDistance({wires, intersection:inter}))
69+
expect(actual).to.deep.equal(expected)
70+
})
71+
})
72+
describe('getClosestIntersectionByWire()', () => {
73+
it('can be used to find the wire distance to the closest intersection', () => {
74+
const wiresets = [
75+
[
76+
'R75,D30,R83,U83,L12,D49,R71,U7,L72',
77+
'U62,R66,U55,R34,D71,R55,D58,R83'
78+
], [
79+
'R98,U47,R26,D63,R33,U87,L62,D20,R33,U53,R51',
80+
'U98,R91,D20,R16,D67,R40,U7,R15,U6,R7'
81+
]
82+
]
83+
const distances = [610, 410]
84+
wiresets.forEach((wires, idx) => {
85+
const intersections = findWireIntersections(wires)
86+
expect(getClosesetIntersectionByWire({ intersections, wires }).distance).to.equal(distances[idx])
87+
})
88+
})
89+
})
5890
})
5991
})

0 commit comments

Comments
 (0)