Browse Source

Added conjugationOf to the ComplexNumber object

featureKomplexNumberCalculator
Lukas Reichwein 5 years ago
parent
commit
e8dfdfd5c9
  1. 14
      src/main/java/com/ugsbo/complexnumcalc/ComplexNumber.java
  2. 22
      src/test/java/com/ugsbo/complexnumcalc/conjugationOfComplexNumbersTest.java

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

@ -137,4 +137,18 @@ public class ComplexNumber {
return absoluteValue; return absoluteValue;
} }
/**
* Calucates the absolute value of this complex number
* @return the absolute value
*/
public ComplexNumber conjugationOf(){
if(this.imaginaryPart.equals(Double.valueOf(0))){
return this;
} else {
this.imaginaryPart *= (-1);
return this;
}
}
} }

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

@ -0,0 +1,22 @@
package com.ugsbo.complexnumcalc;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
public class conjugationOfComplexNumbersTest {
@Test
public void TheConjugatedComplexNumberOfAComplexNumberWithOnlyARealPartShouldBeTheRealPart_ButItIsNot() {
Double realPart = Double.valueOf(4);
Double imaginaryPart = Double.valueOf(0);
ComplexNumber complexNumber = new ComplexNumber(realPart, imaginaryPart);
ComplexNumber expected = new ComplexNumber(realPart, imaginaryPart);
ComplexNumber actual = complexNumber.conjugationOf();
assertTrue("TheConjugatedComplexNumberOfAComplexNumberWithOnlyARealPartIsTheRealPart", expected.equals(actual));
//TODO change equals to equalTo
//assertThat("TheConjugatedComplexNumberOfAComplexNumberWithOnlyARealPartIsTheRealPart", expected, equalsTo(actual));
}
}
Loading…
Cancel
Save