1 | import chai from 'chai';
|
2 | import chaiOutOfBounds from './helpers/chaiOutOfBounds';
|
3 | import Floor from '../src/Floor';
|
4 | import Space from '../src/Space';
|
5 | import Unit from '../src/units/Unit';
|
6 | import Warrior from '../src/units/Warrior';
|
7 |
|
8 | chai.should();
|
9 | chai.use(chaiOutOfBounds);
|
10 |
|
11 | describe('Floor', function () {
|
12 | describe('2x3', function () {
|
13 | beforeEach(function () {
|
14 | this.floor = new Floor(2, 3);
|
15 | });
|
16 |
|
17 | it('should be able to add a unit and fetch it at that position', function () {
|
18 | const unit = new Unit();
|
19 | this.floor.addUnit(unit, 0, 1, 'north');
|
20 | this.floor.getUnitAt(0, 1).should.equal(unit);
|
21 | });
|
22 |
|
23 | it('should not consider unit on floor if no position', function () {
|
24 | const unit = new Unit();
|
25 | this.floor.addUnit(unit, 0, 1, 'north');
|
26 | unit.position = null;
|
27 | this.floor.units.should.not.include(unit);
|
28 | });
|
29 |
|
30 | it('should fetch other units not warrior', function () {
|
31 | const unit = new Unit();
|
32 | const warrior = new Warrior();
|
33 | this.floor.addUnit(unit, 0, 0, 'north');
|
34 | this.floor.addUnit(warrior, 1, 0, 'north');
|
35 | this.floor.otherUnits.should.include(unit);
|
36 | this.floor.otherUnits.should.not.include(warrior);
|
37 | });
|
38 |
|
39 | it('should not consider corners out of bounds', function () {
|
40 | this.floor.should.not.be.outOfBounds(0, 0);
|
41 | this.floor.should.not.be.outOfBounds(1, 0);
|
42 | this.floor.should.not.be.outOfBounds(1, 2);
|
43 | this.floor.should.not.be.outOfBounds(0, 2);
|
44 | });
|
45 |
|
46 | it('should consider out of bounds when going beyond sides', function () {
|
47 | this.floor.should.be.outOfBounds(-1, 0);
|
48 | this.floor.should.be.outOfBounds(0, -1);
|
49 | this.floor.should.be.outOfBounds(0, 3);
|
50 | this.floor.should.be.outOfBounds(2, 0);
|
51 | });
|
52 |
|
53 | it('should return space at the specified location', function () {
|
54 | this.floor.getSpaceAt(0, 0).should.be.instanceOf(Space);
|
55 | });
|
56 |
|
57 | it('should place stairs and be able to fetch the location', function () {
|
58 | this.floor.placeStairs(1, 2);
|
59 | this.floor.stairsLocation.should.eql([1, 2]);
|
60 | });
|
61 | });
|
62 |
|
63 | describe('3x1', function () {
|
64 | beforeEach(function () {
|
65 | this.floor = new Floor(3, 1);
|
66 | });
|
67 |
|
68 | it('should return unique units', function () {
|
69 | const unit = new Unit();
|
70 | this.floor.addUnit(unit, 0, 0);
|
71 | this.floor.addUnit(new Unit(), 1, 0);
|
72 | this.floor.uniqueUnits.should.eql([unit]);
|
73 | });
|
74 | });
|
75 | });
|