b***g 发帖数: 4 | 1 如何给INFINITE LOOP做UNIT TEST? 还是我理解的有偏差?
1. There is an infinite tunnel which has left and right turns.
2. The tunnel never has a 'T'. That means it's going to have either a left
turn or a right turn but there will never be a situation that both left and
right turns are present.
3. You have only 3 methods
void GoStraight() //Keeps going straight until it hits a wall
bool IsWall() //Returns a yes if there is a wall
void TurnLeft() //Turns left 90 degrees
Write code to keep going forward on this infinite tunnel without moving
backwards at all.
Write it so it can be Unit Tested. |
b***g 发帖数: 4 | 2 望大牛指点
and
【在 b***g 的大作中提到】 : 如何给INFINITE LOOP做UNIT TEST? 还是我理解的有偏差? : 1. There is an infinite tunnel which has left and right turns. : 2. The tunnel never has a 'T'. That means it's going to have either a left : turn or a right turn but there will never be a situation that both left and : right turns are present. : 3. You have only 3 methods : void GoStraight() //Keeps going straight until it hits a wall : bool IsWall() //Returns a yes if there is a wall : void TurnLeft() //Turns left 90 degrees : Write code to keep going forward on this infinite tunnel without moving
|
h*d 发帖数: 19309 | 3 抛砖引玉一下,题目说的是inifite tunnel,只有单一走法,连T连接都没有,应该没
有loop吧,感觉就是:
if (!IsWall()) {
GoStraight();
}
else {
TurnLeft();
if (IsWall()){
TurnLeft();
TurnLeft();
}
GoStraight();
}
UnitTest就是给出3种情况:直行,左转,右转就可以了吧。
【在 b***g 的大作中提到】 : 望大牛指点 : : and
|