【发布时间】:2010-10-16 02:17:22
【问题描述】:
这真是一个愚蠢的问题,但我一直盯着这个问题太久了,我就是不知道问题是什么:
/**
* public boolean overlap(int targetX, int targetY) {
* Returns true if the target position is sufficient close to this ghost
* If target position is 16 pixels or less in the x direction
* and similarly in y direction, return true. Otherwise return false
*
* @param targetX
* @param targetY
* @return
*/
public boolean overlap(int targetX, int targetY){
double x=this.getX();
double y=this.getY();
double deltaX=targetX-x;
double deltaY=targetY-y;
if(deltaX<=16 && deltaX>=0 && deltaY<=16 && deltaY>=0)
return true;
else
return false;
}
这应该可以正常工作吗?但它没有。如果我运行这个测试,它会失败 assertTrue。 (g1.x=100 和 g1.y=1000)
double theta = 2 * Math.PI * Math.random();
int x = 100 + (int) (16 * Math.cos(theta));
int y = 1000 + (int) (16 * Math.sin(theta));
assertTrue(g1.overlap(x, y));
有人看到我看不到的东西吗?
【问题讨论】:
-
这个测试用例中g1.getX()和g1.getY()的值是多少?
-
哦,对不起,x=100 和 y=1000