Skip to content

Commit a40b56a

Browse files
test(2020-day-12): stub tests for part 2
1 parent 826d38d commit a40b56a

File tree

1 file changed

+104
-0
lines changed

1 file changed

+104
-0
lines changed

2020/day-12/ferry.test.js

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,108 @@ describe('--- Day 11: Seating System ---', () => {
9999
})
100100
})
101101
})
102+
describe('Part 2', () => {
103+
describe('move()', () => {
104+
let origin
105+
let waypoint
106+
let mode
107+
108+
beforeEach(() => {
109+
mode = 'waypoint'
110+
origin = {
111+
x: 0,
112+
y: 0,
113+
d: 90 // Starting direction is east
114+
}
115+
waypoint = {
116+
x: 10,
117+
y: 1
118+
}
119+
})
120+
it('waypoint: can move North without turning', () => {
121+
const command = 'N5'
122+
expect(
123+
move({ position: origin, waypoint, command, mode })
124+
).to.deep.equal({
125+
position: { x: 0, y: 0, d: 90 },
126+
waypoint: { x: 10, y: 6 }
127+
})
128+
})
129+
it('waypoint: can move South without turning', () => {
130+
const command = 'S5'
131+
expect(
132+
move({ position: origin, waypoint, command, mode })
133+
).to.deep.equal({
134+
position: { x: 0, y: 0, d: 90 },
135+
waypoint: { x: 10, y: -4 }
136+
})
137+
})
138+
it('waypoint: can move East without turning', () => {
139+
const command = 'E5'
140+
expect(
141+
move({ position: origin, waypoint, command, mode })
142+
).to.deep.equal({
143+
position: { x: 0, y: 0, d: 90 },
144+
waypoint: { x: 15, y: 1 }
145+
})
146+
})
147+
it('waypoint: can move West without turning', () => {
148+
const command = 'W5'
149+
expect(
150+
move({ position: origin, waypoint, command, mode })
151+
).to.deep.equal({
152+
position: { x: 0, y: 0, d: 90 },
153+
waypoint: { x: 5, y: 1 }
154+
})
155+
})
156+
it('waypoint: can turn left (counterclockwise) without moving', () => {
157+
const command = 'L90'
158+
expect(
159+
move({ position: origin, waypoint, command, mode })
160+
).to.deep.equal({
161+
position: { x: 0, y: 0, d: 90 },
162+
waypoint: { x: -1, y: 10 }
163+
})
164+
})
165+
it('waypoint: can turn right (clockwise) without moving', () => {
166+
const command = 'R90'
167+
expect(
168+
move({ position: origin, waypoint, command, mode })
169+
).to.deep.equal({
170+
position: { x: 0, y: 0, d: 90 },
171+
waypoint: { x: 1, y: 10 }
172+
})
173+
})
174+
it('waypoint: can move forward in the direction it is pointing', () => {
175+
const command = 'F10'
176+
expect(
177+
move({ position: origin, waypoint, command, mode })
178+
).to.deep.equal({
179+
position: { x: 100, y: 10, d: 90 },
180+
waypoint: { x: 110, y: 11 }
181+
})
182+
})
183+
})
184+
describe('route()', () => {
185+
let mode
186+
187+
beforeEach(() => {
188+
mode = 'waypoint'
189+
})
190+
it('waypoint: can follow a list of instructions', () => {
191+
const instructions = [
192+
'F10',
193+
'N3',
194+
'F7',
195+
'R90',
196+
'F11'
197+
]
198+
const result = route({ instructions, mode })
199+
expect(result)
200+
.to.deep.equal({ x: 214, y: 72, d: 90 })
201+
// manhattan distance from origin
202+
expect(distance({ x: 0, y: 0 }, result)).to.equal(72)
203+
})
204+
})
205+
})
102206
})

0 commit comments

Comments
 (0)