Why does this fail the JUnit Test. I have a class called Complex for Complex Numbers with the Constructor accepting 2 parameters real and imaginary which looks like this
Public Complex(double real, double imaginary) { this.real=real; this.imagine=imagine; } And then I have a method for adding to it called add like this
Public Complex add (Complex other) { double temporaryReal = real + other.real; double temporaryImagine = Imagine + other.Imagine; return new Complex(temporaryReal, tempImagine); } I have a test class set up for testing the method. It looks like this
public void testAdd() { Complex other = new Complex(15, 30); Complex newComplex = new Complex(15, 30); assertTrue( myComplex.add(other) == newComplex ); } If I put in the correct parameters, the JUnit test should pass. Where am I going wrong?
Imaginespelled with uppercaseIwhen you add? and in the constructor you passimaginarybut the variable isimagine. And what ismyComplex? unless it is zero your assert will be false. And comparison of objects is not done with==. So many potential problems here...