Package br.com.ema.maze.factory

Source Code of br.com.ema.maze.factory.MazeParameterFactoryTest

package br.com.ema.maze.factory;

import static junit.framework.Assert.*;

import org.junit.Before;
import org.junit.Test;

import br.com.ema.maze.components.Coordinates;
import br.com.ema.maze.components.Maze;
import br.com.ema.maze.components.MazeSpace;
import br.com.ema.maze.components.MazeWall;
import br.com.ema.maze.enums.Direction;

/**
* @author Emanuel Cruz Rodrigues -> emanuelcruzrodrigues@gmail.com
*
*/
public class MazeParameterFactoryTest {
 
  private MazeParameterFactory factory;
 
  @Before
  public void setUp(){
    factory = new MazeParameterFactory();
  }
 
  @Test
  public void test_Build_Maze_With_Correct_Quantity(){
    int width = 10;
    int height = 5;
    int wallPercentage = 0;
    MazeParameters parameters = new MazeParameters(width, height, wallPercentage, 0, new Coordinates(0, 0), new Coordinates(0, 0));
   
    Maze maze = factory.buildMaze(parameters );
   
    for (int y = 0; y < height; y++) {
      for (int x = 0; x < width; x++) {
        MazeSpace mazeSpace = maze.getSpace(x, y);
        assertNotNull( mazeSpace );
      }
    }
  }
 
  @Test
  public void test_Build_Maze_With_Every_Space_Has_The_Correct_Nearby_Spaces(){
    int width = 3;
    int height = 2;
    int wallPercentage = 0;
    MazeParameters parameters = new MazeParameters(width, height, wallPercentage, 0, new Coordinates(0, 0), new Coordinates(0, 0));
   
    Maze maze = factory.buildMaze(parameters );

    MazeSpace space00 = maze.getSpace(0, 0);
    MazeSpace space01 = maze.getSpace(0, 1);
    MazeSpace space10 = maze.getSpace(1, 0);
    MazeSpace space11 = maze.getSpace(1, 1);
    MazeSpace space20 = maze.getSpace(2, 0);
    MazeSpace space21 = maze.getSpace(2, 1);
   
    /*
     * 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));


  }
 
  @Test
  public void test_Build_Maze_With_Correct_Walls_Percentage(){
    int width = 10;
    int height = 5;
    int wallPercentage = 25;
    MazeParameters parameters = new MazeParameters(width, height, wallPercentage, 0, new Coordinates(0, 0), new Coordinates(0, 0));
   
    Maze maze = factory.buildMaze(parameters );
   
    int walls = 0;
    for (int y = 0; y < height; y++) {
      for (int x = 0; x < width; x++) {
        MazeSpace mazeSpace = maze.getSpace(x, y);
        if (mazeSpace.getDecoration() != null && mazeSpace.getDecoration() instanceof MazeWall){
          walls ++;
        }
      }
    }
   
    assertEquals(12, walls);//25% of 5o = 12.5
  }

}
TOP

Related Classes of br.com.ema.maze.factory.MazeParameterFactoryTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.