Text report

testreport

The functionality of my test jumper revolves around two aspects, the correctness of the steering and the correctness of the movement.

  1. Test whether the jumper can turn correctly
public void testTurn() {
        ActorWorld world = new ActorWorld();
        Jumper jumper = new Jumper();
        world.add(new Location(2, 2), jumper);
        //初始方向为东边
        jumper.setDirection(Location.EAST);
        assertEquals(Location.EAST, jumper.getDirection());
        jumper.turn();
        jumper.turn();
        //两次转向后的方向应该为南边
        assertEquals(Location.SOUTH, jumper.getDirection());
        jumper.turn();
        jumper.turn();
        //再两次转向后的方向应该为西边
        assertEquals(Location.WEST, jumper.getDirection());
        jumper.turn();
        jumper.turn();
        //再两次转向后的方向应该为北边
        assertEquals(Location.NORTH, jumper.getDirection());
    }

2. The movement of the test jumper is divided into multiple parts.

  • When the first grid in the forward direction of the jumper is empty, classify and test the things in the second grid respectively.

    • The second grid is a stone
      "`java
      //Check that the first grid is empty, the second grid is a rock, whether to turn to
      jumper.moveTo(new Location(6,6));
      jumper.setDirection(NORTH);
      world.add(new Location(4,6),new Rock());
      assertEquals(Location.NORTHEAST, jumper.getDirection());
      + 第二个格子为花朵
      ```java
      //检查第一个网格为空,第二个网格为花朵,是否继续前进
      jumper.moveTo(new Location(6,6));
      jumper.setDirection(NORTH);
      world.add(new Location(4,6),new Flower());
      assertEquals("(4, 6)", jumper.getLocation().toString());
  • When the first grid in the jumper's forward direction is not empty, classify and test the contents in it

    • The first square is stone

      //检查石头在中间情况
      jumper.moveTo(new Location(5,5));
      world.add(new Location(4, 5),new Rock());
      jumper.act();
      assertEquals("(3, 5)", jumper.getLocation().toString());
    • The first square is flowers or insects

      //检查花朵在中间情况
      jumper.moveTo(new Location(5,5));
      world.add(new Location(4, 5),new Flower());
      jumper.act();
      assertEquals("(3, 5)", jumper.getLocation().toString());
      //检查昆虫在中间的情况
      jumper.moveTo(new Location(5,5));
      world.add(new Location(4, 5),new Bug());
      jumper.act();
      assertEquals("(3, 5)", jumper.getLocation().toString());
    • The first grid is another jumper

      //检查跳跃路径上有jumper,是否转方向
      jumper.moveTo(new Location(5,5));
      jumper2 = new Jumper();
      world.add(new Location(4, 5),jumper2);
      jumper.act();
      assertEquals(Location.NORTHEAST, jumper.getDirection());
  • The boundary problem of the jumper's forward direction
    • The jumper's second square goes out of bounds
      java
      //检查前进第二个网格超出边缘,是否转向
      jumper.moveTo(new Location(1,1));
      jumper.setDirection(NORTH);
      assertEquals(Location.NORTHEAST, jumper.getDirection());
    • Jumper's first square goes out of bounds
      java
      //检查前进第一个网格为边缘,是否转向
      jumper.moveTo(new Location(1,0));
      jumper.setDirection(NORTH);
      assertEquals(Location.NORTHEAST, jumper.getDirection());

The test effect is shown in the figure:
the test results are all correct, and the jumper function is correctly implemented!
show

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324625153&siteId=291194637