/**
*
*/
package br.com.ema.maze.factory;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNull;
import org.junit.Test;
import br.com.ema.maze.components.Maze;
import br.com.ema.maze.components.MazeSpace;
import br.com.ema.maze.enums.Direction;
/**
* @author Emanuel Cruz Rodrigues -> emanuelcruzrodrigues@gmail.com
*
*/
public class MazeNearbyUpdaterTest {
@Test
public void test_Build_Maze_With_Every_Space_Has_The_Correct_Nearby_Spaces(){
MazeSpace space00 = new MazeSpace(0, 0);
MazeSpace space01 = new MazeSpace(0, 1);
MazeSpace space10 = new MazeSpace(1, 0);
MazeSpace space11 = new MazeSpace(1, 1);
MazeSpace space20 = new MazeSpace(2, 0);
MazeSpace space21 = new MazeSpace(2, 1);
Maze maze = new Maze();
maze.addSpace(space00);
maze.addSpace(space01);
maze.addSpace(space10);
maze.addSpace(space11);
maze.addSpace(space20);
maze.addSpace(space21);
MazeNearbyUpdater updater = new MazeNearbyUpdater();
updater.updateNearby(maze);
/*
* 00 | 10 | 20
* 01 | 11 | 21
*/
//00 tests
assertEquals( space10, space00.getNearbySpace(Direction.EAST));
assertEquals( space01, space00.getNearbySpace(Direction.SOUTH));
assertNull( space00.getNearbySpace(Direction.WEST));
assertNull( space00.getNearbySpace(Direction.NORTH));
//10 tests
assertEquals( space00, space10.getNearbySpace(Direction.WEST));
assertEquals( space11, space10.getNearbySpace(Direction.SOUTH));
assertEquals( space20, space10.getNearbySpace(Direction.EAST));
assertNull( space10.getNearbySpace(Direction.NORTH));
//01 tests
assertEquals( space11, space01.getNearbySpace(Direction.EAST));
assertEquals( space00, space01.getNearbySpace(Direction.NORTH));
assertNull( space01.getNearbySpace(Direction.WEST));
assertNull( space01.getNearbySpace(Direction.SOUTH));
//11 tests
assertEquals( space01, space11.getNearbySpace(Direction.WEST));
assertEquals( space10, space11.getNearbySpace(Direction.NORTH));
assertEquals( space21, space11.getNearbySpace(Direction.EAST));
assertNull( space11.getNearbySpace(Direction.SOUTH));
//20 tests
assertEquals(space10, space20.getNearbySpace(Direction.WEST));
assertEquals(space21, space20.getNearbySpace(Direction.SOUTH));
assertNull(space20.getNearbySpace(Direction.NORTH));
assertNull(space20.getNearbySpace(Direction.EAST));
}
}