1
1
/* eslint-env mocha */
2
2
const expect = require ( 'chai' ) . expect
3
- const { elfWireToSVGPath, findWireIntersections } = require ( './wires' )
3
+ const { elfWireToSVGPath, findWireIntersections, getClosesetIntersection } = require ( './wires' )
4
4
5
5
describe ( '--- 2019 Day 3: Crossed Wires ---' , ( ) => {
6
6
describe ( 'Part 1' , ( ) => {
@@ -16,15 +16,29 @@ describe('--- 2019 Day 3: Crossed Wires ---', () => {
16
16
it ( 'finds the intersection points of multiple wires' , ( ) => {
17
17
const wires = [
18
18
'R8,U5,L5,D3' ,
19
- 'U7,R6,D4'
19
+ 'U7,R6,D4,L4 '
20
20
]
21
21
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 }
24
25
]
25
26
const actual = findWireIntersections ( wires )
26
27
expect ( actual ) . to . deep . equal ( expected )
27
28
} )
28
29
} )
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
+ } )
29
43
} )
30
44
} )
0 commit comments