Skip to content

Commit e9c58f3

Browse files
test(2020-day-11): stub in tests for visibility search logic
1 parent dca1eb7 commit e9c58f3

File tree

2 files changed

+122
-2
lines changed

2 files changed

+122
-2
lines changed

2020/day-11/seating.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ const format = (seatMap) => {
99
return seatMap.map((row) => row.join('')).join('\n')
1010
}
1111

12+
const occupiedLineOfSite = ({ x, y, seatMap }) => {
13+
14+
}
15+
1216
const occupiedNearby = ({ x, y, seatMap }) => {
1317
let temp = ''
1418

@@ -68,5 +72,6 @@ const update = ({ x, y, seatMap }) => {
6872
module.exports = {
6973
format,
7074
parse,
71-
advance
75+
advance,
76+
occupiedLineOfSite
7277
}

2020/day-11/seating.test.js

Lines changed: 116 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-env mocha */
22
const { expect } = require('chai')
3-
const { format, parse, advance } = require('./seating')
3+
const { format, parse, advance, occupiedLineOfSite } = require('./seating')
44

55
const testData = [
66
`L.LL.LL.LL
@@ -75,6 +75,68 @@ L.#.L..#..
7575
#.#L#L#.##`
7676
)
7777

78+
const testDataPart2 = testData.slice(0, 2)
79+
testDataPart2.push(
80+
`#.LL.LL.L#
81+
#LLLLLL.LL
82+
L.L.L..L..
83+
LLLL.LL.LL
84+
L.LL.LL.LL
85+
L.LLLLL.LL
86+
..L.L.....
87+
LLLLLLLLL#
88+
#.LLLLLL.L
89+
#.LLLLL.L#`
90+
)
91+
testDataPart2.push(
92+
`#.L#.##.L#
93+
#L#####.LL
94+
L.#.#..#..
95+
##L#.##.##
96+
#.##.#L.##
97+
#.#####.#L
98+
..#.#.....
99+
LLL####LL#
100+
#.L#####.L
101+
#.L####.L#`
102+
)
103+
testDataPart2.push(
104+
`#.L#.L#.L#
105+
#LLLLLL.LL
106+
L.L.L..#..
107+
##LL.LL.L#
108+
L.LL.LL.L#
109+
#.LLLLL.LL
110+
..L.L.....
111+
LLLLLLLLL#
112+
#.LLLLL#.L
113+
#.L#LL#.L#`
114+
)
115+
testDataPart2.push(
116+
`#.L#.L#.L#
117+
#LLLLLL.LL
118+
L.L.L..#..
119+
##L#.#L.L#
120+
L.L#.#L.L#
121+
#.L####.LL
122+
..#.#.....
123+
LLL###LLL#
124+
#.LLLLL#.L
125+
#.L#LL#.L#`
126+
)
127+
testDataPart2.push(
128+
`#.L#.L#.L#
129+
#LLLLLL.LL
130+
L.L.L..#..
131+
##L#.#L.L#
132+
L.L#.LL.L#
133+
#.LLLL#.LL
134+
..#.L.....
135+
LLL###LLL#
136+
#.LLLLL#.L
137+
#.L#LL#.L#`
138+
)
139+
78140
describe('--- Day 11: Seating System ---', () => {
79141
describe('Part 1', () => {
80142
describe('advance()', () => {
@@ -96,4 +158,57 @@ describe('--- Day 11: Seating System ---', () => {
96158
})
97159
})
98160
})
161+
describe('Part 2', () => {
162+
describe('occupiedLineOfSite()', () => {
163+
it('counts the occupied seats visible in each direction', () => {
164+
const data =
165+
`.......#.
166+
...#.....
167+
.#.......
168+
.........
169+
..#L....#
170+
....#....
171+
.........
172+
#........
173+
...#.....`
174+
expect(occupiedLineOfSite({ x: 1, y: 1, seatMap: data })).to.equal(8)
175+
})
176+
it('cannot see occupied seats past an available seat', () => {
177+
const data =
178+
`.............
179+
.L.L.#.#.#.#.
180+
.............`
181+
expect(occupiedLineOfSite({ x: 3, y: 4, seatMap: data })).to.equal(0)
182+
})
183+
it('can look in all compass directions', () => {
184+
const data =
185+
`.##.##.
186+
#.#.#.#
187+
##...##
188+
...L...
189+
##...##
190+
#.#.#.#
191+
.##.##.`
192+
expect(occupiedLineOfSite({ x: 3, y: 3, seatMap: data })).to.equal(0)
193+
})
194+
})
195+
describe('advance()', () => {
196+
it('accepts visibility rules instead of proximity', () => {
197+
const results = testDataPart2.map((data) => {
198+
return format(
199+
advance(
200+
parse(data), 'visible'
201+
)
202+
)
203+
})
204+
205+
for (let x = 1; x < testDataPart2.length; x++) {
206+
console.debug('Step', x)
207+
expect(results[x - 1]).to.equal(testDataPart2[x])
208+
}
209+
const finalOccupancy = (results[results.length - 1].match(/#/g) || []).length
210+
expect(finalOccupancy).to.equal(26)
211+
})
212+
})
213+
})
99214
})

0 commit comments

Comments
 (0)