我收到错误:
java.lang.AssertionError: expected: learning.java.advancedoop2.MyComplex<(2.0+10.0i)> but was: learning.java.advancedoop2.MyComplex<(2.0+10.0i)>
Expected :learning.java.advancedoop2.MyComplex<(2.0+10.0i)>
Actual :learning.java.advancedoop2.MyComplex<(2.0+10.0i)>
我现在正在研究 MyComplex 类,如 3.1 所示:http: //www.ntu.edu.sg/home/ehchua/programming/java/J3f_OOPExercises.html#zz-2
这是相关的代码的一部分:
package learning.java.advancedoop2;
public class MyComplex {
private double real = 0.0;
private double imag = 0.0;
public MyComplex() {
}
public MyComplex add(MyComplex right) {
this.imag += right.imag;
this.real += right.real;
return this;
}
}
我试图进行测试,当我运行它们时,我遇到的错误是向上的,这是我的测试代码的一部分:
@Test
public void add() {
MyComplex myComplexFirst = new MyComplex(1, 5);
MyComplex myComplexSecond = new MyComplex(1, 5);
MyComplex myComplexThird = new MyComplex(myComplexFirst.getReal() + myComplexSecond.getReal(), myComplexFirst.getImag() + myComplexSecond.getImag());
myComplexFirst.add(myComplexSecond);
MyComplex newComplex = myComplexFirst;
assertEquals(newComplex, myComplexThird);
}