Ultra Geile Studenten Benutzer Oberfläche (UGSBO)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

70 lines
3.2 KiB

  1. package com.ugsbo.complexnumcalc;
  2. import static org.junit.Assert.assertEquals;
  3. import org.junit.Test;
  4. public class AbsoluteValueOfComplexNumbersTest {
  5. @Test
  6. public void TheAbsoluteValueOfAComplexNumberWithOnlyARealPart_IsNotTheAbsoluteValueOfTheRealPart() {
  7. ComplexNumber complexNumber = new ComplexNumber(Double.valueOf(4), Double.valueOf(0));
  8. Double expected = Double.valueOf(4);
  9. Double actual = complexNumber.absolutValueOf();
  10. assertEquals("The absolute value of an complex number with only an real part should be the absolute value of that real part", expected, actual);
  11. }
  12. @Test
  13. public void TheAbsoluteValueOfAComplexNumberWithOnlyANegativeRealPart_IsNotTheAbsoluteValueOfTheRealPart() {
  14. ComplexNumber complexNumber = new ComplexNumber(Double.valueOf(-4), Double.valueOf(0));
  15. Double expected = Double.valueOf(4);
  16. Double actual = complexNumber.absolutValueOf();
  17. assertEquals("The absolute value of an complex number with only an negative real part should be the absolute value of that real part", expected, actual);
  18. }
  19. @Test
  20. public void TheAbsoluteValueOfAComplexNumber_IsNotTheAbsoluteValueOfIt() {
  21. ComplexNumber complexNumber = new ComplexNumber(Double.valueOf(4), Double.valueOf(3));
  22. Double expected = Double.valueOf(5);
  23. Double actual = complexNumber.absolutValueOf();
  24. assertEquals("The absolute value of an complex number should be the square root of the sum of real " +
  25. "part times real part and imaginary part times imaginary part ", expected, actual);
  26. }
  27. @Test
  28. public void TheAbsoluteValueOfAComplexNumberWithNegativRealPart_IsNotTheAbsoluteValueOfIt() {
  29. ComplexNumber complexNumber = new ComplexNumber(Double.valueOf(-4), Double.valueOf(3));
  30. Double expected = Double.valueOf(5);
  31. Double actual = complexNumber.absolutValueOf();
  32. assertEquals("The absolute value of an complex number with negative real part should be the square root of the sum of real " +
  33. "part times real part and imaginary part times imaginary part ", expected, actual);
  34. }
  35. @Test
  36. public void TheAbsoluteValueOfAComplexNumberWithNegativImaginaryPart_IsNotTheAbsoluteValueOfIt() {
  37. ComplexNumber complexNumber = new ComplexNumber(Double.valueOf(4), Double.valueOf(-3));
  38. Double expected = Double.valueOf(5);
  39. Double actual = complexNumber.absolutValueOf();
  40. assertEquals("The absolute value of an complex number with negative imaginary part should be the square root of the sum of real " +
  41. "part times real part and imaginary part times imaginary part ", expected, actual);
  42. }
  43. @Test
  44. public void TheAbsoluteValueOfAComplexNumberWithNegativParts_IsNotTheAbsoluteValueOfIt() {
  45. ComplexNumber complexNumber = new ComplexNumber(Double.valueOf(-4), Double.valueOf(-3));
  46. Double expected = Double.valueOf(5);
  47. Double actual = complexNumber.absolutValueOf();
  48. assertEquals("The absolute value of an complex number with negative parts should be the square root of the sum of real " +
  49. "part times real part and imaginary part times imaginary part ", expected, actual);
  50. }
  51. }