Skip to content

Commit 9d9f402

Browse files
test(2018 day-15): setup unit tests
1 parent 8761287 commit 9d9f402

File tree

1 file changed

+41
-17
lines changed

1 file changed

+41
-17
lines changed

2018/day-15/caves.test.js

Lines changed: 41 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
/* eslint-env mocha */
22
const expect = require('chai').expect
33
const {
4-
Cave
5-
} = require('./recipes')
4+
Cave,
5+
Unit
6+
} = require('./caves')
67

78
describe('--- Day 15: Beverage Bandits ---', () => {
89
describe('Part 1:', () => {
@@ -18,51 +19,74 @@ describe('--- Day 15: Beverage Bandits ---', () => {
1819
const cave = new Cave(test)
1920
expect(cave.rounds).to.equal(0)
2021
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])
2528
expect(cave.map[4][4]).to.equal('#')
2629
expect(cave.map[3][4]).to.equal('.')
2730
})
2831
describe('advance()', () => {
29-
it('advances the cave combat cycle', () => {
32+
it.skip('advances the cave combat cycle', () => {
3033

3134
})
3235
})
3336
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', () => {
3538

3639
})
37-
it('returns null when the path is blocked by cave', () => {
40+
it.skip('returns null when the path is blocked by cave', () => {
3841

3942
})
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', () => {
4144

4245
})
4346
})
4447
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)
4759
})
4860
})
4961
})
50-
describe('new Unit()', () => {
62+
describe('new Unit(x, y, type)', () => {
5163
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')
5377
})
5478
describe('attack()', () => {
55-
it('attacks the closest oponent', () => {
79+
it.skip('attacks the closest oponent', () => {
5680

5781
})
5882
})
5983
describe('findClosestOponent()', () => {
60-
it('finds the unit\'s closest oponent', () => {
84+
it.skip('finds the unit\'s closest oponent', () => {
6185

6286
})
6387
})
6488
describe('move()', () => {
65-
it('moves the unit towards the closest oponent', () => {
89+
it.skip('moves the unit towards the closest oponent', () => {
6690
const test = `
6791
#######
6892
#.E...#

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy