中山大学中级实训--测试文档

测试文档

一、测试项目

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.

二、测试环境

JUnit version 4.10

java version 1.8.0_181

通过使用Junit进行测试,通过运行已经编写好的测试案例,每个案例都根据对应的测试内容进行编写。运行测试程序后,判断程序的输出是否与预期相同,一致就说明程序正确;不一致则是程序存在该测试范围内的错误。该测试中,通过创建不同种类、位置的actor来实现程序的测试。

三、 测试案例

1. 测试Jumper两格移动

初始化:

创建一个位置为(0, 0),方向向东(Location.EAST)的Jumper。

期望:

运行一个act()后Jumper的位置变为(0, 2)

代码:

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. 测试Jumper跳过障碍物

初始化:

创建一个位置为(0, 0),方向向东(Location.EAST)的Jumper。

创建一个位置为(0, 1) 的Rock。

期望:

运行一个act()后Jumper的位置变为(0, 2)

代码:

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. 测试Jumper被阻挡转向

初始化:

创建一个位置为(0, 0),方向向东(Location.EAST)的Jumper。

创建一个位置为(0, 2) 的Rock。

期望:

运行一个act()

Jumper的位置不变为(0, 0)

Jumperd的方向变为东南(Location.SOUTHEAST)

代码:

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. 测试Jumer面前为边界的转向

初始化:

创建一个位置为(0, 0),方向向西(Location.WEST)的Jumper。

期望:

运行一个act()

Jumper的位置不变为(0, 0)

Jumperd的方向变为西北(Location.NORTHWEST)

代码:

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. 测试Jumer移动一格后为边界的转向

初始化:

创建一个位置为(0, 1),方向向西(Location.WEST)的Jumper。

期望:

运行一个act()

Jumper的位置不变为(0, 1)

Jumperd的方向变为西北(Location.NORTHWEST)

代码:

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());
  }

四、实验结果

运行命令(以源文件为当前目录):

//编译
javac -classpath .:./../../gridworld.jar:./../../junit.jar JumperTest.java 
//运行测试
java -classpath .:./../../gridworld.jar:./../../junit.jar org.junit.runner.JUnitCore JumperTest

测试结果
在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值