Package org.jamesii.core.math.complex

Examples of org.jamesii.core.math.complex.Complex


        -503d / 25, -43d / 10, 20.57436269, -2.931042466);
  }

  /** Tests the {@link Complex#divide(double)} method. */
  public void testDivideReal() {
    checkFields(new Complex(1, 2).divide(2), .5, 1, 1.118033989, 1.107148718);
  }
View Full Code Here


    checkFields(new Complex(1, 2).divide(2), .5, 1, 1.118033989, 1.107148718);
  }

  /** Tests the {@link Complex#divide(Complex)} method. */
  public void testDivideComplex() {
    checkFields(new Complex(5, 4).divide(new Complex(-1, 2)), 3d / 5, -14d / 5,
        2.863564213, -1.359702994);
  }
View Full Code Here

        2.863564213, -1.359702994);
  }

  /** Tests the {@link Complex#isReal()} method. */
  public void testIsReal() {
    assertTrue(new Complex(1, 0).isReal());
    assertFalse(new Complex(0, 1).isReal());
    assertFalse(new Complex(1, 1).isReal());
  }
View Full Code Here

    assertFalse(new Complex(1, 1).isReal());
  }

  /** Tests the {@link Complex#isImaginary()} method. */
  public void testIsImaginary() {
    assertTrue(new Complex(0, 1).isImaginary());
    assertFalse(new Complex(1, 0).isImaginary());
    assertFalse(new Complex(1, 1).isImaginary());
  }
View Full Code Here

   * @param b
   *          A second complex number.
   */
  private void checkProperties(Complex a, Complex b) {
    // tests for absolute value
    if (a.equals(new Complex(0, 0))) {
      assertTrue(a.getModulus() == 0);
    }
    if (a.getModulus() == 0) {
      assertTrue(a.equals(new Complex(0, 0)));
    }
    assertTrue(a.add(b).getModulus() <= a.getModulus() + b.getModulus());
    assertTrue(Double.compare(a.multiply(b).getModulus(),
        a.getModulus() * b.getModulus()) == 0);

    // complex conjugates
    assertTrue(approximatelyEqual(a.add(b).conjugate(),
        a.conjugate().add(b.conjugate())));
    assertTrue(approximatelyEqual(a.multiply(b).conjugate(), a.conjugate()
        .multiply(b.conjugate())));
    if (!b.equals(new Complex(0, 0))) {
      assertTrue(approximatelyEqual(a.divide(b).conjugate(), a.conjugate()
          .divide(b.conjugate())));
    }
    assertTrue(a.conjugate().conjugate().equals(a));
    if (a.isReal()) {
      assertTrue(a.conjugate().equals(a));
    }
    if (a.conjugate().equals(a)) {
      assertTrue(a.isReal());
    }
    if (a.isImaginary()) {
      assertTrue(a.conjugate().equals(a.negate()));
    }
    if (a.conjugate().equals(a.negate())) {
      assertTrue(a.isImaginary());
    }
    assertTrue(a.getModulus() == a.conjugate().getModulus());
    assertTrue(a.multiply(a.conjugate()).isReal());
    assertTrue(a.multiply(a.conjugate()).getReal() - pow(a.getModulus(), 2) < 1e-10);
    if (!a.equals(new Complex(0, 0))) {
      assertTrue(approximatelyEqual(ComplexMath.pow(a, -1), a.conjugate()
          .multiply(pow(a.getModulus(), -2))));
    }
  }
View Full Code Here

  public void testProperties() {
    // Tests various properties of calculations with complex numbers. Some
    // special cases are tested here.

    // both numbers are 0.
    checkProperties(new Complex(0, 0), new Complex(0, 0));
    // one number is zero, the other an arbitrary real number
    checkProperties(new Complex(15, 0), new Complex(0, 0));
    checkProperties(new Complex(0, 0), new Complex(2, 0));
    // one number is zero, the other an arbitrary imaginary number
    checkProperties(new Complex(0, 0), new Complex(0, 3));
    checkProperties(new Complex(0, 5), new Complex(0, 0));
    // one number is zero, the other an arbitrary complex number
    checkProperties(new Complex(0, 0), new Complex(2, 6));
    checkProperties(new Complex(8, 13), new Complex(0, 0));
    // one number is one, the other zero
    checkProperties(new Complex(1, 0), new Complex(0, 0));
    checkProperties(new Complex(0, 0), new Complex(1, 0));
    // both numbers are one
    checkProperties(new Complex(1, 0), new Complex(1, 0));
    checkProperties(new Complex(1, 0), new Complex(1, 0));
    // one number is one, the other an arbitrary real number
    checkProperties(new Complex(1, 0), new Complex(46, 0));
    checkProperties(new Complex(-98, 0), new Complex(1, 0));
    // one number is one, the other an arbitrary imaginary number
    checkProperties(new Complex(1, 0), new Complex(0, 211));
    checkProperties(new Complex(0, -32), new Complex(1, 0));
    // one number is one, the other an arbitrary complex number
    checkProperties(new Complex(1, 0), new Complex(2, -7));
    checkProperties(new Complex(-1, 5), new Complex(1, 0));
    // one number is i, the other zero
    checkProperties(new Complex(0, 1), new Complex(0, 0));
    checkProperties(new Complex(0, 0), new Complex(0, 1));
    // both numbers are i
    checkProperties(new Complex(0, 1), new Complex(0, 1));
    checkProperties(new Complex(0, 1), new Complex(0, 1));
    // one number is i, the other an arbitrary real number
    checkProperties(new Complex(0, 1), new Complex(42, 0));
    checkProperties(new Complex(-23, 0), new Complex(0, 1));
    // one number is i, the other an arbitrary imaginary number
    checkProperties(new Complex(0, 1), new Complex(0, 15));
    checkProperties(new Complex(0, -8), new Complex(0, 1));
    // one number is i, the other an arbitrary complex number
    checkProperties(new Complex(0, 1), new Complex(-6, 48));
    checkProperties(new Complex(19, -1), new Complex(0, 1));
  }
View Full Code Here

    checkProperties(new Complex(19, -1), new Complex(0, 1));
  }

  /** Tests the {@link Complex#equals(Object)} method. */
  public void testEquals() {
    assertTrue(new Complex(1, 1).equals(new Complex(1, 1)));
    assertFalse(new Complex(1, 1).equals(null));
    assertFalse(new Complex(1, 1).equals("blah"));
    assertFalse(new Complex(1, 1).equals(new Complex(2, 2)));
  }
View Full Code Here

    assertFalse(new Complex(1, 1).equals(new Complex(2, 2)));
  }

  /** Tests the {@link Complex#hashCode()} method. */
  public void testHashCode() {
    Complex a = new Complex(1, 1);
    Complex b = new Complex(1, 0);
    b = b.add(new Complex(0, 1));
    assertTrue(a.hashCode() == a.hashCode());
    assertTrue(a.hashCode() == b.hashCode());
  }
View Full Code Here

    assertTrue(a.hashCode() == b.hashCode());
  }

  /** Tests the {@link Complex#toString()} method. */
  public void testToString() {
    assertTrue(new Complex(0, 0).toString().equals("0"));
    assertTrue(new Complex(1, 1).toString().equals("1.0 + 1.0i"));
    assertTrue(new Complex(-5, 1).toString().equals("-5.0 + 1.0i"));
    assertTrue(new Complex(-5, -2).toString().equals("-5.0 - 2.0i"));
    assertTrue(new Complex(-5, 0).toString().equals("-5.0"));
    assertTrue(new Complex(0, 1).toString().equals("1.0i"));
    assertTrue(new Complex(0, -7.5).toString().equals("-7.5i"));
  }
View Full Code Here

    assertTrue(new Complex(0, -7.5).toString().equals("-7.5i"));
  }

  /** Tests the {@link Complex#doubleValue()} method. */
  public void testDoubleValue() {
    Complex c = new Complex(Math.random() * 100, Math.random() * 100);
    assertEquals(c.doubleValue(), c.getReal());
  }
View Full Code Here

TOP

Related Classes of org.jamesii.core.math.complex.Complex

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.