UNPKG

warriorjs-engine

Version:
80 lines (70 loc) 1.75 kB
import playLevel from '../src/Engine'; describe('Engine', function () { beforeEach(function () { this.levelConfig = { timeBonus: 15, floor: { size: { width: 8, height: 1, }, stairs: { x: 7, y: 0, }, warrior: { name: 'Spartacus', x: 0, y: 0, facing: 'east', abilities: [ { name: 'walk', args: [], }, ], }, units: [], }, }; }); describe('with a winner player code', function () { this.slow(500); beforeEach(function () { this.playerCode = ` class Player { playTurn(warrior) { warrior.walk(); } } `; this.requiredTurns = 7; }); it('should pass level when max turns are enough', function () { const maxTurns = this.requiredTurns; const { passed } = playLevel(this.levelConfig, this.playerCode, maxTurns); passed.should.be.true; }); it('should not pass level when max turns are not enough', function () { const maxTurns = this.requiredTurns - 1; const { passed } = playLevel(this.levelConfig, this.playerCode, maxTurns); passed.should.be.false; }); }); describe('with a loser player code', function () { this.slow(500); beforeEach(function () { this.playerCode = ` class Player { playTurn(warrior) { // Cool code goes here } } `; }); it('should not pass level', function () { const { passed } = playLevel(this.levelConfig, this.playerCode); passed.should.be.false; }); }); });