|
| 1 | +const assert = require('assert').strict; |
| 2 | +const gameController=require("../GameController/gameController.js"); |
| 3 | +const letters=require("../GameController/letters.js"); |
| 4 | +const position=require("../GameController/position.js") |
| 5 | + |
| 6 | +describe('checkIsHitTests', function() { |
| 7 | + |
| 8 | + it('should return true if there is a ship at the shooting position', function() { |
| 9 | + var ships = gameController.InitializeShips(); |
| 10 | + counter=1; |
| 11 | + ships.forEach(ship => { |
| 12 | + for(var i = 1; i <= ship.size; i++) { |
| 13 | + column = letters.get(counter); |
| 14 | + ship.addPosition(new position(letters.get(counter), i)) |
| 15 | + } |
| 16 | + counter++; |
| 17 | + }) |
| 18 | + var actual = gameController.CheckIsHit(ships, new position(letters.B,3)); |
| 19 | + assert.ok(actual); |
| 20 | + }); |
| 21 | + |
| 22 | + it('should return false if there is no ship at the shooting position', function() { |
| 23 | + var ships = gameController.InitializeShips(); |
| 24 | + counter=1; |
| 25 | + ships.forEach(ship => { |
| 26 | + for(var i = 1; i <= ship.size; i++) { |
| 27 | + ship.addPosition(new position(letters.get(counter), i)) |
| 28 | + } |
| 29 | + counter++; |
| 30 | + }) |
| 31 | + var actual = gameController.CheckIsHit(ships, new position(letters.G,1)); |
| 32 | + assert.strictEqual(actual, false ); |
| 33 | + }); |
| 34 | + |
| 35 | + it('should throw an exception if positstion is undefined', function() { |
| 36 | + var ships = gameController.InitializeShips(); |
| 37 | + assert.throws( |
| 38 | + () => { |
| 39 | + var actual = gameController.CheckIsHit(ships, undefined); |
| 40 | + } |
| 41 | + ) |
| 42 | + }); |
| 43 | + |
| 44 | + it('should throw an exception if ship is undefined', function() { |
| 45 | + assert.throws( |
| 46 | + () => { |
| 47 | + var actual = gameController.CheckIsHit(undefined, new position(letters.G,1)); |
| 48 | + } |
| 49 | + ) |
| 50 | + }); |
| 51 | +}); |
| 52 | + |
0 commit comments