1
1
/* eslint-env mocha */
2
2
const { expect } = require ( 'chai' )
3
- const { format, parse, advance } = require ( './seating' )
3
+ const { format, parse, advance, occupiedLineOfSite } = require ( './seating' )
4
4
5
5
const testData = [
6
6
`L.LL.LL.LL
@@ -75,6 +75,68 @@ L.#.L..#..
75
75
#.#L#L#.##`
76
76
)
77
77
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
+
78
140
describe ( '--- Day 11: Seating System ---' , ( ) => {
79
141
describe ( 'Part 1' , ( ) => {
80
142
describe ( 'advance()' , ( ) => {
@@ -96,4 +158,57 @@ describe('--- Day 11: Seating System ---', () => {
96
158
} )
97
159
} )
98
160
} )
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
+ } )
99
214
} )
0 commit comments