@@ -55,5 +55,37 @@ describe('--- 2019 Day 3: Crossed Wires ---', () => {
55
55
expect ( getClosesetIntersection ( findWireIntersections ( wires ) ) . distance ) . to . equal ( distances [ idx ] )
56
56
} )
57
57
} )
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
+ } )
58
90
} )
59
91
} )
0 commit comments