Jumper测试报告

测试报告

测试目的

测试我们所写的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。

这里写图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值