test documentation
1. Test items
A class called Jumper. This actor can move forward two cells in each move. It “jumps” over rocks and flowers. It does not leave anything behind it when it jumps.
2. Test environment
JUnit version 4.10
java version 1.8.0_181
By using Junit for testing, by running the test cases that have been written, each case is written according to the corresponding test content. After running the test program, judge whether the output of the program is the same as expected. If it is consistent, it means that the program is correct; if it is inconsistent, it means that the program has errors within the scope of the test. In this test, the program is tested by creating actors of different types and locations.
3. Test cases
1. Test Jumper’s two-space movement
initialization:
Create a Jumper with location (0, 0) and direction east (Location.EAST).
expect:
After running one act()
, the position of Jumper becomes (0, 2)
Code:
public void testJumperMove() {
ActorWorld world = new ActorWorld();
Jumper jumper = new Jumper();
//set direction to east
jumper.setDirection(Location.EAST);
world.add(new Location(0, 0), jumper);
jumper.act();
assertEquals(0, jumper.getLocation().getRow());
assertEquals(2, jumper.getLocation().getCol());
}
2. Test Jumper to jump over obstacles
initialization:
Create a Jumper with location (0, 0) and direction east (Location.EAST).
Create a Rock at position (0, 1).
expect:
After running one act()
, the position of Jumper becomes (0, 2)
Code:
public void testJumperTurn() {
ActorWorld world = new ActorWorld();
Jumper jumper = new Jumper();
Rock rock = new Rock();
jumper.setDirection(Location.EAST);
world.add(new Location(0, 0), jumper);
world.add(new Location(0, 2), rock);
jumper.act();
rock.act();
assertEquals(Location.SOUTHEAST, jumper.getDirection());
}
3. Test Jumper to turn when blocked
initialization:
Create a Jumper with location (0, 0) and direction east (Location.EAST).
Create a Rock at position (0, 2).
expect:
act()
After running a
The position of Jumper does not change to (0, 0)
Jumperd's direction changes to southeast (Location.SOUTHEAST)
Code:
public void testJumperTurn() {
ActorWorld world = new ActorWorld();
Jumper jumper = new Jumper();
Rock rock = new Rock();
jumper.setDirection(Location.EAST);
world.add(new Location(0, 0), jumper);
world.add(new Location(0, 2), rock);
jumper.act();
rock.act();
assertEquals(Location.SOUTHEAST, jumper.getDirection());
assertEquals(0, jumper.getLocation().getRow());
assertEquals(0, jumper.getLocation().getCol());
}
4. Test the steering of the boundary in front of Jumer
initialization:
Create a Jumper with location (0, 0) and direction west (Location.WEST).
expect:
act()
After running a
The position of Jumper does not change to (0, 0)
Jumperd's direction changes to northwest (Location.NORTHWEST)
Code:
public void testJumperEdge() {
ActorWorld world = new ActorWorld();
Jumper jumper = new Jumper();
world.add(new Location(0, 0), jumper);
jumper.setDirection(Location.WEST);
jumper.act();
assertEquals(Location.NORTHWEST, jumper.getDirection());
assertEquals(0, jumper.getLocation().getRow());
assertEquals(0, jumper.getLocation().getCol());
}
5. Test Jumer’s turn to the boundary after moving one space
initialization:
Create a Jumper with location (0, 1) and direction west (Location.WEST).
expect:
act()
After running a
The position of Jumper does not change to (0, 1)
Jumperd's direction changes to northwest (Location.NORTHWEST)
Code:
public void testJumperOut() {
ActorWorld world = new ActorWorld();
Jumper jumper = new Jumper();
world.add(new Location(0, 1), jumper);
jumper.setDirection(Location.WEST);
jumper.act();
assertEquals(Location.NORTHWEST, jumper.getDirection());
assertEquals(0, jumper.getLocation().getRow());
assertEquals(1, jumper.getLocation().getCol());
}
4. Experimental results
Run the command (with the source file as the current directory):
//编译
javac -classpath .:./../../gridworld.jar:./../../junit.jar JumperTest.java
//运行测试
java -classpath .:./../../gridworld.jar:./../../junit.jar org.junit.runner.JUnitCore JumperTest
Test Results