测试报告
测试目的
测试我们所写的Jumper函数是否符合预期,以及是否会出现一些意外错误。
测试思路
1、首先测试 Jumper 在面对墙的时候的行为
2、然后测试 Jumper 在面对岩石时的行为
3、再测试 Jumper 面对花的行为
4、最后测试两个 Jumper 互相面对时的行为
测试过程
测试面对墙时行为
- 测试与墙相隔两个空格
测试代码为:
@Test
public void testJump() {
//new a jumper
Jumper a = new Jumper(Color.RED);
world.add(new Location(2,0), a);
//test initial location
assertEquals(2, a.getLocation().getRow());
assertEquals(0, a.getLocation().getCol());
assertEquals(Location.NORTH, a.getDirection());
a.act();
//test result location
assertEquals(0, a.getLocation().getRow());
assertEquals(0, a.getLocation().getCol());
assertEquals(Location.NORTH, a.getDirection());
}
初始位置
跳跃后
- 测试与墙相隔一个空格
测试代码为:
@Test
public void testMove() {
//face the wall
Jumper ab = new Jumper(Color.RED);
world.add(new Location(1,1), ab);
assertEquals(1, ab.getLocation().getRow());
assertEquals(1, ab.getLocation().getCol());
assertEquals(Location.NORTH, ab.getDirection());
ab.act();
assertEquals(0, ab.getLocation().getRow());
assertEquals(1, ab.getLocation().getCol());
assertEquals(Location.NORTH, ab.getDirection());
}
初始位置
移动后
- 测试转向(与墙壁相邻)
测试代码为:
@Test
public void testMove() {
//face the wall
Jumper ab = new Jumper(Color.RED);
world.add(new Location(1,1), ab);
assertEquals(1, ab.getLocation().getRow());
assertEquals(1, ab.getLocation().getCol());
assertEquals(Location.NORTH, ab.getDirection());
ab.act();
assertEquals(0, ab.getLocation().getRow());
assertEquals(1, ab.getLocation().getCol());
assertEquals(Location.NORTH, ab.getDirection());
}
初始位置
第一次转向
第二次转向
- 测试与岩石相邻一格
测试代码为:
@Test
public void testRock()
{
Jumper a = new Jumper(Color.RED);
Rock r=new Rock(Color.GREEN);
world.add(new Location(3,3), a);
world.add(new Location(2,3), r);
a.act();
assertEquals(1, a.getLocation().getRow());
assertEquals(3, a.getLocation().getCol());
assertEquals(Location.NORTH, a.getDirection());
}
初始
向前移动一格
跳过岩石
- 测试与花相邻一格
测试代码为:
@Test
public void testFlower()
{
Jumper a = new Jumper(Color.RED);
Flower r=new Flower(Color.GREEN);
world.add(new Location(3,3), a);
world.add(new Location(1,3), r);
a.act();
assertEquals(1, a.getLocation().getRow());
assertEquals(3, a.getLocation().getCol());
assertEquals(Location.NORTH, a.getDirection());
}
初始情况
Jumper行动后到了花的位置,花消失了
- 测试两个Jumper面对面
测试代码为:
@Test
public void jumperface()
{
Jumper a = new Jumper(Color.RED);
Jumper b = new Jumper(Color.ORANGE);
a.setDirection(180);
world.add(new Location(1,3), a);
world.add(new Location(3,3), b);
a.act();
assertEquals(2, a.getLocation().getRow());
assertEquals(3, a.getLocation().getCol());
assertEquals(Location.SOUTH, a.getDirection());
b.act();
assertEquals(1, b.getLocation().getRow());
assertEquals(3, b.getLocation().getCol());
assertEquals(Location.NORTH, b.getDirection());
}
初始
一个Jumper向前移动一步,一个跳一次
测试结果
经过运行JUnit测试类,程序成功执行,failures为0。