|
@@ 97-123 (lines=27) @@
|
| 94 |
|
}); |
| 95 |
|
|
| 96 |
|
}); |
| 97 |
|
describe('goForward', function() { |
| 98 |
|
var grid = new Grid(new Position({x:5,y:5}, 'N')), |
| 99 |
|
position = new Position({x:2,y:2}, 'E'), |
| 100 |
|
mower = new Mower(0, grid, position, ['A']), |
| 101 |
|
move = new Move(mower, grid); |
| 102 |
|
|
| 103 |
|
it('should move mower to 1 cell forward with cardinal ’E’ and change mower’s position to: x+1', function () { |
| 104 |
|
move.goForward(); |
| 105 |
|
expect(move.mower.position.x).to.equal(position.x+1); |
| 106 |
|
}); |
| 107 |
|
it('should move mower to 1 cell forward with cardinal ’W’ and change mower’s position to: x-1', function () { |
| 108 |
|
move.mower.position = new Position({x:2,y:2}, 'W'); |
| 109 |
|
move.goForward(); |
| 110 |
|
expect(move.mower.position.x).to.equal(position.x-1); |
| 111 |
|
}); |
| 112 |
|
it('should move mower to 1 cell forward with cardinal ’N’ and change mower’s position to: y+1', function () { |
| 113 |
|
move.mower.position = new Position({x:2,y:2}, 'N'); |
| 114 |
|
move.goForward(); |
| 115 |
|
expect(move.mower.position.y).to.equal(position.y+1); |
| 116 |
|
}); |
| 117 |
|
it('should move mower to 1 cell forward with cardinal ’S’ and change mower’s position to: y-1', function () { |
| 118 |
|
move.mower.position = new Position({x:2,y:2}, 'S'); |
| 119 |
|
move.goForward(); |
| 120 |
|
expect(move.mower.position.y).to.equal(position.y-1); |
| 121 |
|
}); |
| 122 |
|
|
| 123 |
|
}); |
| 124 |
|
describe('turn', function() { |
| 125 |
|
var grid = new Grid(new Position({x:10,y:10}, 'N')), |
| 126 |
|
position = new Position({x:2,y:2}, 'E'), |
|
@@ 76-96 (lines=21) @@
|
| 73 |
|
}); |
| 74 |
|
}); |
| 75 |
|
}); |
| 76 |
|
describe('updatePosition', function() { |
| 77 |
|
var grid = new Grid(new Position({x:5,y:5}, 'N')), |
| 78 |
|
position = new Position({x:2,y:2}, 'E'), |
| 79 |
|
mower = new Mower(0, grid, position, ['A']), |
| 80 |
|
move = new Move(mower, grid); |
| 81 |
|
|
| 82 |
|
it('should update a position when the target position is not occupied', function () { |
| 83 |
|
var newPosition = new Position({x:position.x+1,y:position.y}, 'E'); |
| 84 |
|
move.updatePosition(newPosition); |
| 85 |
|
expect(move.mower.position.x).to.equal(position.x+1); |
| 86 |
|
}); |
| 87 |
|
it('should not update a position when the target position is occupied', function () { |
| 88 |
|
move.mower.position = new Position({x:2,y:2}, 'E'); // set mower's position |
| 89 |
|
move.grid.occupation[move.mower.id] = move.mower.position; // set current mower's occupation |
| 90 |
|
move.grid.occupation[1] = new Position({x:3,y:2}, 'E'); // add fake item in object grid.occupation |
| 91 |
|
var newPosition = new Position({x:position.x+1,y:position.y}, 'E'); // position to try |
| 92 |
|
move.updatePosition(newPosition); // prevent moving if the target cell is occupied by another item by excluding this item from the comparision |
| 93 |
|
expect(move.mower.position.x).to.equal(position.x); // X still unchanged |
| 94 |
|
}); |
| 95 |
|
|
| 96 |
|
}); |
| 97 |
|
describe('goForward', function() { |
| 98 |
|
var grid = new Grid(new Position({x:5,y:5}, 'N')), |
| 99 |
|
position = new Position({x:2,y:2}, 'E'), |