Skip to content

Commit a136ce7

Browse files
test(2020-day-12): stub out tests for moving the ferry
1 parent b801a24 commit a136ce7

File tree

2 files changed

+89
-0
lines changed

2 files changed

+89
-0
lines changed

2020/day-12/ferry.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
const move = () => {
2+
return
3+
}
4+
5+
const route = () => {
6+
return
7+
}
8+
9+
module.exports = {
10+
move,
11+
route
12+
}

2020/day-12/ferry.test.js

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/* eslint-env mocha */
2+
const { expect } = require('chai')
3+
const { distance } = require('../../2018/day-06')
4+
const { move, route } = require('./ferry')
5+
6+
describe('--- Day 11: Seating System ---', () => {
7+
describe('Part 1', () => {
8+
describe('move()', () => {
9+
let origin
10+
11+
beforeEach(() => {
12+
origin = {
13+
x: 0,
14+
y: 0,
15+
d: 90 // Starting direction is east
16+
}
17+
})
18+
it('can move North without turning', () => {
19+
const command = 'N5'
20+
expect(
21+
move({ position: origin, command })
22+
).to.deep.equal({ x: 0, y: 5, d: 90 })
23+
})
24+
it('can move South without turning', () => {
25+
const command = 'S5'
26+
expect(
27+
move({ position: origin, command })
28+
).to.deep.equal({ x: 0, y: -5, d: 90 })
29+
})
30+
it('can move East without turning', () => {
31+
const command = 'E5'
32+
expect(
33+
move({ position: origin, command })
34+
).to.deep.equal({ x: 5, y: 0, d: 90 })
35+
})
36+
it('can move West without turning', () => {
37+
const command = 'W5'
38+
expect(
39+
move({ position: origin, command })
40+
).to.deep.equal({ x: -5, y: 0, d: 90 })
41+
})
42+
it('can turn left (counterclockwise) without moving', () => {
43+
const command = 'L90'
44+
expect(
45+
move({ position: origin, command })
46+
).to.deep.equal({ x: 0, y: 0, d: 0 })
47+
})
48+
it('can turn right (clockwise) without moving', () => {
49+
const command = 'R90'
50+
expect(
51+
move({ position: origin, command })
52+
).to.deep.equal({ x: 0, y: 0, d: 180 })
53+
})
54+
it('can move forward', () => {
55+
const command = 'F10'
56+
expect(
57+
move({ position: origin, command })
58+
).to.deep.equal({ x: 10, y: 0, d: 90 })
59+
})
60+
})
61+
describe('route()', () => {
62+
it('can follow a list of instructions', () => {
63+
const instructions = [
64+
'F10',
65+
'N3',
66+
'F7',
67+
'R90',
68+
'F11'
69+
]
70+
const result = route({ instructions })
71+
expect(result)
72+
.to.deep.equal({ x: 17, y: -8, d: 180 })
73+
expect(distance(result.x, result.y)).to.equal(25)
74+
})
75+
})
76+
})
77+
})

0 commit comments

Comments
 (0)