4 Commits

  1. 6
      pom.xml
  2. 8
      src/main/java/com/ugsbo/complexnumcalc/ComplexNumber.java
  3. 7
      src/test/java/com/ugsbo/complexnumcalc/AddComplexNumbersTest.java
  4. 19
      src/test/java/com/ugsbo/complexnumcalc/conjugationOfComplexNumbersTest.java

6
pom.xml

@ -24,6 +24,12 @@
<version>4.11</version> <version>4.11</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-junit</artifactId>
<version>2.0.0.0</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.mockito/mockito-core --> <!-- https://mvnrepository.com/artifact/org.mockito/mockito-core -->
<dependency> <dependency>
<groupId>org.mockito</groupId> <groupId>org.mockito</groupId>

8
src/main/java/com/ugsbo/complexnumcalc/ComplexNumber.java

@ -48,9 +48,11 @@ public class ComplexNumber {
* @param complexNumber The number wich gets compared with this Instance * @param complexNumber The number wich gets compared with this Instance
* @return True if the complex Numbers are Equal * @return True if the complex Numbers are Equal
*/ */
public boolean equals(ComplexNumber complexNumber) {
if (this.realPart.equals(complexNumber.realPart) && this.imaginaryPart.equals(complexNumber.imaginaryPart)) {
return true;
@Override
public boolean equals(Object complexNumber) {
if (complexNumber instanceof ComplexNumber){
ComplexNumber that = (ComplexNumber) complexNumber;
return this.realPart.equals(that.realPart) && this.imaginaryPart.equals(that.imaginaryPart);
} else { } else {
return false; return false;
} }

7
src/test/java/com/ugsbo/complexnumcalc/AddComplexNumbersTest.java

@ -1,6 +1,7 @@
package com.ugsbo.complexnumcalc; package com.ugsbo.complexnumcalc;
import static org.junit.Assert.assertTrue;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import org.junit.Test; import org.junit.Test;
@ -14,7 +15,7 @@ public class AddComplexNumbersTest {
ComplexNumber sum = firstAddend.add(secoundAddend); ComplexNumber sum = firstAddend.add(secoundAddend);
assertTrue("Dont sum to the sum", sum.equals(expected));
assertThat("Dont sum to the sum", sum, equalTo(expected));
} }
@Test @Test
@ -25,6 +26,6 @@ public class AddComplexNumbersTest {
ComplexNumber sum = firstAddend.add(secoundAddend); ComplexNumber sum = firstAddend.add(secoundAddend);
assertTrue("Dont sum to the sum", sum.equals(expected));
assertThat("Dont sum to the sum", sum, equalTo(expected));
} }
} }

19
src/test/java/com/ugsbo/complexnumcalc/conjugationOfComplexNumbersTest.java

@ -1,6 +1,7 @@
package com.ugsbo.complexnumcalc; package com.ugsbo.complexnumcalc;
import static org.junit.Assert.assertTrue;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import org.junit.Test; import org.junit.Test;
@ -15,8 +16,18 @@ public class conjugationOfComplexNumbersTest {
ComplexNumber actual = complexNumber.conjugationOf(); ComplexNumber actual = complexNumber.conjugationOf();
assertTrue("TheConjugatedComplexNumberOfAComplexNumberWithOnlyARealPartIsTheRealPart", expected.equals(actual));
//TODO change equals to equalTo
//assertThat("TheConjugatedComplexNumberOfAComplexNumberWithOnlyARealPartIsTheRealPart", expected, equalsTo(actual));
assertThat("The conjugated complex Number of a complex number with only a real part is the real part", expected, equalTo(actual));
}
@Test
public void TheConjugatedComplexNumberOfAComplexNumberShouldBeTheComplexNumberWithSwapedSignImaginaryPart_ButItIsNot() {
Double realPart = Double.valueOf(4);
Double imaginaryPart = Double.valueOf(5);
ComplexNumber complexNumber = new ComplexNumber(realPart, imaginaryPart);
ComplexNumber expected = new ComplexNumber(realPart, -imaginaryPart);
ComplexNumber actual = complexNumber.conjugationOf();
assertThat("The conjugated complex number of a complex number is the complex number with swaped sign in the imaginary part", expected, equalTo(actual));
} }
} }
Loading…
Cancel
Save