Skip to content
Prev Previous commit
Next Next commit
test(2020-day-11): stub in tests for visibility search logic
  • Loading branch information
developher-net committed Dec 21, 2020
commit e9c58f3fc1d259b45f8f3aa80ed0ea669b9c37c0
7 changes: 6 additions & 1 deletion 2020/day-11/seating.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ const format = (seatMap) => {
return seatMap.map((row) => row.join('')).join('\n')
}

const occupiedLineOfSite = ({ x, y, seatMap }) => {

}

const occupiedNearby = ({ x, y, seatMap }) => {
let temp = ''

Expand Down Expand Up @@ -68,5 +72,6 @@ const update = ({ x, y, seatMap }) => {
module.exports = {
format,
parse,
advance
advance,
occupiedLineOfSite
}
117 changes: 116 additions & 1 deletion 2020/day-11/seating.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-env mocha */
const { expect } = require('chai')
const { format, parse, advance } = require('./seating')
const { format, parse, advance, occupiedLineOfSite } = require('./seating')

const testData = [
`L.LL.LL.LL
Expand Down Expand Up @@ -75,6 +75,68 @@ L.#.L..#..
#.#L#L#.##`
)

const testDataPart2 = testData.slice(0, 2)
testDataPart2.push(
`#.LL.LL.L#
#LLLLLL.LL
L.L.L..L..
LLLL.LL.LL
L.LL.LL.LL
L.LLLLL.LL
..L.L.....
LLLLLLLLL#
#.LLLLLL.L
#.LLLLL.L#`
)
testDataPart2.push(
`#.L#.##.L#
#L#####.LL
L.#.#..#..
##L#.##.##
#.##.#L.##
#.#####.#L
..#.#.....
LLL####LL#
#.L#####.L
#.L####.L#`
)
testDataPart2.push(
`#.L#.L#.L#
#LLLLLL.LL
L.L.L..#..
##LL.LL.L#
L.LL.LL.L#
#.LLLLL.LL
..L.L.....
LLLLLLLLL#
#.LLLLL#.L
#.L#LL#.L#`
)
testDataPart2.push(
`#.L#.L#.L#
#LLLLLL.LL
L.L.L..#..
##L#.#L.L#
L.L#.#L.L#
#.L####.LL
..#.#.....
LLL###LLL#
#.LLLLL#.L
#.L#LL#.L#`
)
testDataPart2.push(
`#.L#.L#.L#
#LLLLLL.LL
L.L.L..#..
##L#.#L.L#
L.L#.LL.L#
#.LLLL#.LL
..#.L.....
LLL###LLL#
#.LLLLL#.L
#.L#LL#.L#`
)

describe('--- Day 11: Seating System ---', () => {
describe('Part 1', () => {
describe('advance()', () => {
Expand All @@ -96,4 +158,57 @@ describe('--- Day 11: Seating System ---', () => {
})
})
})
describe('Part 2', () => {
describe('occupiedLineOfSite()', () => {
it('counts the occupied seats visible in each direction', () => {
const data =
`.......#.
...#.....
.#.......
.........
..#L....#
....#....
.........
#........
...#.....`
expect(occupiedLineOfSite({ x: 1, y: 1, seatMap: data })).to.equal(8)
})
it('cannot see occupied seats past an available seat', () => {
const data =
`.............
.L.L.#.#.#.#.
.............`
expect(occupiedLineOfSite({ x: 3, y: 4, seatMap: data })).to.equal(0)
})
it('can look in all compass directions', () => {
const data =
`.##.##.
#.#.#.#
##...##
...L...
##...##
#.#.#.#
.##.##.`
expect(occupiedLineOfSite({ x: 3, y: 3, seatMap: data })).to.equal(0)
})
})
describe('advance()', () => {
it('accepts visibility rules instead of proximity', () => {
const results = testDataPart2.map((data) => {
return format(
advance(
parse(data), 'visible'
)
)
})

for (let x = 1; x < testDataPart2.length; x++) {
console.debug('Step', x)
expect(results[x - 1]).to.equal(testDataPart2[x])
}
const finalOccupancy = (results[results.length - 1].match(/#/g) || []).length
expect(finalOccupancy).to.equal(26)
})
})
})
})