1
1
/* eslint-env mocha */
2
2
const expect = require ( 'chai' ) . expect
3
3
const {
4
- Cave
5
- } = require ( './recipes' )
4
+ Cave,
5
+ Unit
6
+ } = require ( './caves' )
6
7
7
8
describe ( '--- Day 15: Beverage Bandits ---' , ( ) => {
8
9
describe ( 'Part 1:' , ( ) => {
@@ -18,51 +19,74 @@ describe('--- Day 15: Beverage Bandits ---', () => {
18
19
const cave = new Cave ( test )
19
20
expect ( cave . rounds ) . to . equal ( 0 )
20
21
expect ( cave . outcome ) . to . equal ( null )
21
- expect ( cave . filter ( ( unit ) => unit . type === 'elves' ) . length ) . to . equal ( 4 )
22
- expect ( cave . filter ( ( unit ) => unit . type === 'goblins' ) . length ) . to . equal ( 3 )
23
- expect ( cave . filter ( ( unit ) => unit . type === 'elves' ) [ 0 ] . location ) . to . deep . equal ( [ 5 , 1 ] )
24
- expect ( cave . filter ( ( unit ) => unit . type === 'goblins' ) [ 3 ] . location ) . to . deep . equal ( [ 2 , 3 ] )
22
+ expect ( cave . map . length ) . to . equal ( 5 ) // 5 rows
23
+ expect ( cave . map [ 4 ] . length ) . to . equal ( 7 ) // 7 columns
24
+ expect ( cave . units . filter ( ( unit ) => unit . type === 'elves' ) . length ) . to . equal ( 4 )
25
+ expect ( cave . units . filter ( ( unit ) => unit . type === 'goblins' ) . length ) . to . equal ( 3 )
26
+ expect ( cave . units . filter ( ( unit ) => unit . type === 'elves' ) [ 0 ] . location ) . to . deep . equal ( [ 4 , 1 ] )
27
+ expect ( cave . units . filter ( ( unit ) => unit . type === 'goblins' ) [ 2 ] . location ) . to . deep . equal ( [ 2 , 3 ] )
25
28
expect ( cave . map [ 4 ] [ 4 ] ) . to . equal ( '#' )
26
29
expect ( cave . map [ 3 ] [ 4 ] ) . to . equal ( '.' )
27
30
} )
28
31
describe ( 'advance()' , ( ) => {
29
- it ( 'advances the cave combat cycle' , ( ) => {
32
+ it . skip ( 'advances the cave combat cycle' , ( ) => {
30
33
31
34
} )
32
35
} )
33
36
describe ( 'findPath(origin, target)' , ( ) => {
34
- it ( 'determines a path from the origin to the target' , ( ) => {
37
+ it . skip ( 'determines a path from the origin to the target' , ( ) => {
35
38
36
39
} )
37
- it ( 'returns null when the path is blocked by cave' , ( ) => {
40
+ it . skip ( 'returns null when the path is blocked by cave' , ( ) => {
38
41
39
42
} )
40
- it ( 'returns null when the path is blocked by other units' , ( ) => {
43
+ it . skip ( 'returns null when the path is blocked by other units' , ( ) => {
41
44
42
45
} )
43
46
} )
44
47
describe ( 'display()' , ( ) => {
45
- it ( 'renders the current cave state' , ( ) => {
46
-
48
+ it . skip ( 'renders the current cave state' , ( ) => {
49
+ const test = `
50
+ #######
51
+ #.G.E.#
52
+ #E.G.E#
53
+ #.G.E.#
54
+ #######
55
+ `
56
+ const expected = test . split ( '\n' ) . map ( ( row ) => row . trim ( ) ) . join ( '\n' ) . trim ( )
57
+ const actual = new Cave ( test ) . display ( )
58
+ expect ( actual ) . to . equal ( expected )
47
59
} )
48
60
} )
49
61
} )
50
- describe ( 'new Unit()' , ( ) => {
62
+ describe ( 'new Unit(x, y, type )' , ( ) => {
51
63
it ( 'initializes an elf or a goblin' , ( ) => {
52
- const expected = { hp : 200 , ap : 3 , location : [ 3 , 4 ] }
64
+ const expected = {
65
+ ap : 3 ,
66
+ hp : 200 ,
67
+ location : [ 3 , 4 ] ,
68
+ type : 'elves'
69
+ }
70
+ const actual = new Unit ( 3 , 4 , 'elves' )
71
+ expect ( actual . ap ) . to . equal ( expected . ap )
72
+ expect ( actual . hp ) . to . equal ( expected . hp )
73
+ expect ( actual . location ) . to . deep . equal ( expected . location )
74
+ expect ( actual . type ) . to . equal ( expected . type )
75
+ expect ( typeof actual . attack ) . to . equal ( 'function' )
76
+ expect ( typeof actual . move ) . to . equal ( 'function' )
53
77
} )
54
78
describe ( 'attack()' , ( ) => {
55
- it ( 'attacks the closest oponent' , ( ) => {
79
+ it . skip ( 'attacks the closest oponent' , ( ) => {
56
80
57
81
} )
58
82
} )
59
83
describe ( 'findClosestOponent()' , ( ) => {
60
- it ( 'finds the unit\'s closest oponent' , ( ) => {
84
+ it . skip ( 'finds the unit\'s closest oponent' , ( ) => {
61
85
62
86
} )
63
87
} )
64
88
describe ( 'move()' , ( ) => {
65
- it ( 'moves the unit towards the closest oponent' , ( ) => {
89
+ it . skip ( 'moves the unit towards the closest oponent' , ( ) => {
66
90
const test = `
67
91
#######
68
92
#.E...#
0 commit comments