Files
RobotSimulator/src/test/java/au/com/seek/domain/RobotTest.java
T
2017-04-14 17:39:38 +08:00

83 lines
2.6 KiB
Java

package au.com.seek.domain;
import org.junit.Test;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.junit.Assert.assertThat;
public class RobotTest {
@Test
public void should_report_robot_location() throws Exception {
Coordinate coordinate = new Coordinate(0, 0);
Robot robot = new Robot(coordinate, Direction.EAST);
String report = robot.report();
assertThat(report, equalTo("0,0,EAST"));
}
@Test
public void should_report_robot_location_when_x_and_y_axis_is_not_zero() throws Exception {
Coordinate coordinate = new Coordinate(3, 5);
Robot robot = new Robot(coordinate, Direction.SOUTH);
String report = robot.report();
assertThat(report, equalTo("3,5,SOUTH"));
}
@Test
public void should_change_direction_when_do_turn_left() throws Exception {
Coordinate coordinate = new Coordinate(3, 3);
Robot robot = new Robot(coordinate, Direction.NORTH);
robot.turnLeft();
assertThat(robot.report(), equalTo("3,3,WEST"));
}
@Test
public void should_change_direction_when_do_turn_right() throws Exception {
Coordinate coordinate = new Coordinate(0, 1);
Robot robot = new Robot(coordinate, Direction.NORTH);
robot.turnRight();
assertThat(robot.report(), equalTo("0,1,EAST"));
}
@Test
public void should_change_coordinates_when_do_move_and_facing_north() throws Exception {
Coordinate coordinate = new Coordinate(0, 1);
Robot robot = new Robot(coordinate, Direction.NORTH);
robot.moveForward();
assertThat(robot.report(), equalTo("0,2,NORTH"));
}
@Test
public void should_change_coordinates_when_do_move_and_facing_east() throws Exception {
Coordinate coordinate = new Coordinate(0, 1);
Robot robot = new Robot(coordinate, Direction.EAST);
robot.moveForward();
assertThat(robot.report(), equalTo("1,1,EAST"));
}
@Test
public void should_remain_same_coordinates_if_robot_is_going_to_falling_in_x_axis() throws Exception {
Coordinate coordinate = new Coordinate(5, 0);
Robot robot = new Robot(coordinate, Direction.EAST);
robot.moveForward();
assertThat(robot.report(), equalTo("5,0,EAST"));
}
@Test
public void should_remain_same_coordinates_if_robot_is_going_to_falling_in_y_axis() throws Exception {
Coordinate coordinate = new Coordinate(0, 5);
Robot robot = new Robot(coordinate, Direction.NORTH);
robot.moveForward();
assertThat(robot.report(), equalTo("0,5,NORTH"));
}
}