大二实训(二)Part3测试文档

大二实训(二)Part3测试文档

@author: SYSUcarey
@date: 2018-04-22
@Talk is cheap, Show you my code
@本人学院
目录:

1.Test turn() method

We expected the jumper turn right for 90 degrees after a turn operation.
Use the direction of the jumper to test if it turn right of 90 degrees after a turn() operation.
Test Code:

//@file: JumperTest.java
//@TestFunction: testTurn()
//注:alice is a jumper
int direction = (alice.getDirection() + Location.RIGHT)%360;
alice.turn();
assertEquals(alice.getDirection(), direction);

2.Test jump() method

We expected the jumper jump two cells for each jump() operation
Use the location before and after of the jumper to test
Test Code:

//@file: JumperTest.java
//@TestFunction: testJump()
world.add(new Location(6, 6), alice);
alice.jump();
assertEquals(new Location(4, 6), alice.getLocation());

3.Test canJump() method

In three cases:
The next location in front is a rock.
And the two cells location in front is empty、a flower、a rock.

We expected the answer of the empty and flower cases is true.
The answer of the rock case is false;

Test Code:

//@file: JumperTest.java
//@TestFunction: testCanJump()
world.add(new Location(6, 1), alice);
world.add(new Location(5, 1), new Rock());
assertEquals(true, alice.canJump());
alice.moveTo(new Location(6, 2));
world.add(new Location(5, 2), new Rock());
world.add(new Location(4, 2), new Flower());
assertEquals(true, alice.canJump());
alice.moveTo(new Location(6, 3));
world.add(new Location(5, 3), new Rock());
world.add(new Location(4, 3), new Rock());
assertEquals(false, alice.canJump());

4.Test act() method in case1

(1)What will a jumper do if the location in front of it is empty, but the location two cells in front contains a flower or a rock?
Answer:
(A)If the location two cells in front contains a flower, we expected the jumper will jump to this location and the flower will be moved away.
(B)If the location two cells in front contains a rock, we expected the jumper can’t not jump and will turn right of 90 degrees.

Test Code:

//@file: JumperTest.java
//@TestFunction: testActOne()
//alice and bob are both jumpers
world.add(new Location(3, 1), alice);
world.add(new Location(6, 1), bob);
world.add(new Location(1, 1), new Rock());
world.add(new Location(4, 1), new Flower());
int direction = (alice.getDirection() + Location.RIGHT)%360;
alice.act();
bob.act();
assertEquals(direction, alice.getDirection());
assertEquals(new Location(4, 1), bob.getLocation());

5.Test act() method in case2

(2)What will a jumper do if the location two cells in front of the jumper is out of the grid?
Answer:
We expected the jumper will not jump but turn right of 90 degrees.

Test Code:

//@file: JumperTest.java
//@TestFunction: testActTwo()
world.add(new Location(1, 1), alice);
int direction = (alice.getDirection() + Location.RIGHT)%360;
alice.act();
assertEquals(direction, alice.getDirection());

6.Test act() method in case3

(3)What will a jumper do if it is facing an edge of the grid?
Answer:
We excepted the jumper will not jump but turn right of 90 degrees.

Test Code:

//@file: JumperTest.java
//@TestFunction: testActThree()
world.add(new Location(0, 1), alice);
int direction = (alice.getDirection() + Location.RIGHT)%360;
alice.act();
assertEquals(direction, alice.getDirection());

7.Test act() method in case4

(4)What will a jumper do if another actor (not a flower or a rock) is in the cell that is two cells in front of the jumper?
Answer:
We excepted the jumper will turn right of 90 degrees.

Test Code:

//@file: JumperTest.java
//@TestFunction: testActFour()
world.add(new Location(6, 6), alice);
world.add(new Location(2, 0), bob);
world.add(new Location(4, 6), new Actor());
world.add(new Location(0, 0), new Jumper());
int direction = (alice.getDirection() + Location.RIGHT)%360;
int directionB = (bob.getDirection() + Location.RIGHT)%360;
alice.act();
bob.act();
assertEquals(direction, alice.getDirection());
assertEquals(directionB, bob.getDirection());   

8.Test act() method in case5

(5)What will a jumper do if it encounters another jumper in its path?
Answer:
(A) If the two jumpers jump for the same location, we excepted that the first jumper will take the location and the other one turn right of 90 degrees.
(B)If the two jumpers just jump by, which means they don’t jump to the same location, we excepted that they can both jump to their own locations.

Test Code:

//@file: JumperTest.java
//@TestFunction: testActFive()

//jump for same location:
world.add(new Location(6, 4), alice);
world.add(new Location(3, 4), bob);
bob.setDirection(Location.SOUTH);
alice.act();
bob.act();
assertEquals(new Location(4, 4), alice.getLocation());
assertEquals(new Location(5, 4), bob.getLocation());

//jump by
bob.moveTo(new Location(0, 4));
int direction = (alice.getDirection() + Location.RIGHT)%360;
bob.act();
alice.act();
assertEquals(new Location(2, 4), bob.getLocation());
assertEquals(direction, alice.getDirection());

Result(Using Junit):

For 8 Test Functions:
这里写图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值