[英]assertEquals fails on two Vectors
I want to write accelerate method for Ship
class so I have written 我想为Ship
类编写加速方法,所以我写了
public void accelerate(double fo){
double newSpeedMag = speed.magnitude() + fo;
speed = new Vector(Math.cos(facing) * newSpeedMag , Math.sin(facing) * newSpeedMag );
}
Where facing
is facing angle and currently facing == Math.PI
. facing
面对角度,当前facing == Math.PI
In testAccelerate()
test case: 在testAccelerate()
测试案例中:
testAccelerate(){
s.facing = Math.PI/2;
s.accelerate(4);
assertEquals("wrong vector",new Vector(-3,4),s.speed);
}
assertEquals
is failing. assertEquals
失败。
It sounds like you most likely did not override equals for your class. 听起来您很可能没有覆盖班级的等于。 Without this, there is no way for assertEquals to know if the classes are equal (well it tries, but will only return true if the point to the same memory address). 没有这个,assertEquals就无法知道类是否相等(它会尽力而为,但是只有当指向相同的内存地址时才会返回true)。
See this link for overriding equals on your class - http://users.csc.calpoly.edu/~kmammen/documents/java/howToOverrideEquals.html . 请参阅此链接以了解您的课程上的等式-http://users.csc.calpoly.edu/~kmammen/documents/java/howToOverrideEquals.html 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.