Package org.jamesii.core.math.complex

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


  /**
   * Test multiply.
   */
  public void testMultiply() {
    ComplexArray1D a =
        new ComplexArray1D(new Complex[] { new Complex(1, 2),
            new Complex(3, 4), new Complex(5, 6) });

    // initial tests ... we can't have too many of them :)
    assertTrue(a.getComplex(0).equals(new Complex(1, 2)));
    assertTrue(a.getComplex(1).equals(new Complex(3, 4)));
    assertTrue(a.getComplex(2).equals(new Complex(5, 6)));

    // testing multiply(int, int, int)
    a.multiply(0, 1, 2);
    assertTrue(a.getComplex(0).equals(new Complex(-9, 38)));
    assertTrue(a.getComplex(1).equals(new Complex(3, 4)));
    assertTrue(a.getComplex(2).equals(new Complex(5, 6)));

    // testing multiply(int, int, double, double)
    a.multiply(0, 1, 1.5, -4.75);
    assertTrue(a.getComplex(0).equals(new Complex(23.5, -8.25)));
    assertTrue(a.getComplex(1).equals(new Complex(3, 4)));
    assertTrue(a.getComplex(2).equals(new Complex(5, 6)));

    // testing multiply(int, double, double, double, double)
    a.multiply(2, 4, 2, -1, -8);
    assertTrue(a.getComplex(0).equals(new Complex(23.5, -8.25)));
    assertTrue(a.getComplex(1).equals(new Complex(3, 4)));
    assertTrue(a.getComplex(2).equals(new Complex(12, -34)));
  }
View Full Code Here


  /**
   * Test divide exceptions.
   */
  public void testDivideExceptions() {
    ComplexArray1D a = new ComplexArray1D(new Complex[] { new Complex(1, 1) });

    // testing divide(int, double, double, double, double)
    try {
      a.divide(-1, 2d, 3d, 1d, 2d);
      fail();
    } catch (IndexOutOfBoundsException e) {
      assertTrue(true);
    } catch (Exception e) {
      fail();
    }
    try {
      a.divide(5, 5d, 4d, 2d, 1d);
      fail();
    } catch (IndexOutOfBoundsException e) {
      assertTrue(true);
    } catch (Exception e) {
      fail();
    }

    // testing divide(int, int, double, double)
    try {
      a.divide(-1, 0, 1d, 2d);
      fail();
    } catch (IndexOutOfBoundsException e) {
      assertTrue(true);
    } catch (Exception e) {
      fail();
    }
    try {
      a.divide(5, 0, 1d, 1d);
      fail();
    } catch (IndexOutOfBoundsException e) {
      assertTrue(true);
    } catch (Exception e) {
      fail();
    }
    try {
      a.divide(0, -2, 2d, 3d);
      fail();
    } catch (IndexOutOfBoundsException e) {
      assertTrue(true);
    } catch (Exception e) {
      fail();
    }
    try {
      a.divide(0, 10, 3d, 2d);
      fail();
    } catch (IndexOutOfBoundsException e) {
      assertTrue(true);
    } catch (Exception e) {
      fail();
    }

    // testing divide(int, int, int)
    try {
      a.divide(-1, 0, 0);
      fail();
    } catch (IndexOutOfBoundsException e) {
      assertTrue(true);
    } catch (Exception e) {
      fail();
    }
    try {
      a.divide(5, 0, 0);
      fail();
    } catch (IndexOutOfBoundsException e) {
      assertTrue(true);
    } catch (Exception e) {
      fail();
    }
    try {
      a.divide(0, -2, 0);
      fail();
    } catch (IndexOutOfBoundsException e) {
      assertTrue(true);
    } catch (Exception e) {
      fail();
    }
    try {
      a.divide(0, 10, 0);
      fail();
    } catch (IndexOutOfBoundsException e) {
      assertTrue(true);
    } catch (Exception e) {
      fail();
    }
    try {
      a.divide(0, 0, -1);
      fail();
    } catch (IndexOutOfBoundsException e) {
      assertTrue(true);
    } catch (Exception e) {
      fail();
    }
    try {
      a.divide(0, 0, 10);
      fail();
    } catch (IndexOutOfBoundsException e) {
      assertTrue(true);
    } catch (Exception e) {
      fail();
    }

    // check for side-effects. Nothing should have changed!
    assertTrue(a.getComplex(0).equals(new Complex(1, 1)));
  }
View Full Code Here

  /**
   * Test divide.
   */
  public void testDivide() {
    ComplexArray1D a =
        new ComplexArray1D(new Complex[] { new Complex(1, 2),
            new Complex(3, 4), new Complex(5, 6) });

    // initial tests ... we can't have too many of them :)
    assertTrue(a.getComplex(0).equals(new Complex(1, 2)));
    assertTrue(a.getComplex(1).equals(new Complex(3, 4)));
    assertTrue(a.getComplex(2).equals(new Complex(5, 6)));

    // testing divide(int, int, int)
    a.divide(0, 1, 2);
    assertTrue(a.getComplex(0).equals(new Complex(39.0 / 61, 2.0 / 61)));
    assertTrue(a.getComplex(1).equals(new Complex(3, 4)));
    assertTrue(a.getComplex(2).equals(new Complex(5, 6)));

    // testing divide(int, int, double, double)
    a.divide(0, 1, 1.5, -4.75);
    assertTrue(a.getComplex(0).equals(new Complex(-232d / 397, 324d / 397)));
    assertTrue(a.getComplex(1).equals(new Complex(3, 4)));
    assertTrue(a.getComplex(2).equals(new Complex(5, 6)));

    // testing divide(int, double, double, double, double)
    a.divide(2, 4.0, 2.0, -1.0, -8.0);
    assertTrue(a.getComplex(0).equals(new Complex(-232d / 397, 324d / 397)));
    assertTrue(a.getComplex(1).equals(new Complex(3, 4)));
    assertTrue(a.getComplex(2).equals(new Complex(-4d / 13, 6d / 13)));

    // testing divide(int, double, double, int)
    a.divide(1, 1.0, 1.0, 2);
    assertTrue(a.getComplex(0).equals(new Complex(-232d / 397, 324d / 397)));
    System.out.println(a.getComplex(1));
    assertTrue(a.getComplex(1).equals(new Complex(1d / 2, -5d / 2)));
    assertTrue(a.getComplex(2).equals(new Complex(-4d / 13, 6d / 13)));
  }
View Full Code Here

   * Test to complex array.
   */
  public void testToComplexArray() {
    Complex[] a =
        new Complex[] { new Complex(1, 2), new Complex(3, 4), new Complex(5, 6) };
    ComplexArray1D b = new ComplexArray1D(a);
    Complex[] c = b.toComplexArray();

    for (int i = 0; i < a.length; i++) {
      assertTrue(a[i].equals(c[i]));
    }
  }
View Full Code Here

  /**
   * Test empty constructor.
   */
  public void testEmptyConstructor() {
    ComplexArray1D a = new ComplexArray1D();
    assertTrue(a.getLength() == 0);
  }
View Full Code Here

  /**
   * Test length constructor exceptions.
   */
  public void testLengthConstructorExceptions() {
    try {
      new ComplexArray1D(-1);
      fail();
    } catch (IllegalArgumentException e) {
      assertTrue(true);
    } catch (Exception e) {
      fail();
View Full Code Here

  /**
   * Test length constructor.
   */
  public void testLengthConstructor() {
    ComplexArray1D a = new ComplexArray1D(5);

    assertTrue(a.getLength() == 5);

    // check for numbers being zero
    for (int i = 0; i < a.getLength(); i++) {
      assertTrue(a.getComplex(i).equals(new Complex(0, 0)));
    }
  }
View Full Code Here

   */
  public void testComplexArrayConstructor() {
    Complex[] x =
        new Complex[] { new Complex(1, 2), new Complex(3, 4),
            new Complex(8, 7), new Complex(1.5, 5.75), new Complex(-8, -5.4) };
    ComplexArray1D a = new ComplexArray1D(x);

    assertTrue(x.length == a.getLength());

    for (int i = 0; i < a.getLength(); i++) {
      assertTrue(x[i].equals(a.getComplex(i)));
    }
  }
View Full Code Here

  /**
   * Test put get complex.
   */
  public void testPutGetComplex() {
    ComplexArray1D a = new ComplexArray1D(5);

    // test put and get
    a.putComplex(2, -24, 42);
    a.putComplex(0, new Complex(1, 2));
    a.putComplex(3, 10, 12);
    a.putComplex(1, new Complex(5, -7));

    // test exceptions
    try {
      a.putComplex(-1, new Complex(8, 18));
      fail();
    } catch (IndexOutOfBoundsException e) {
      assertTrue(true);
    } catch (Exception e) {
      fail();
    }
    try {
      a.putComplex(34436, new Complex(8, 18));
      fail();
    } catch (IndexOutOfBoundsException e) {
      assertTrue(true);
    } catch (Exception e) {
      fail();
    }
    try {
      a.getComplex(-4);
      fail();
    } catch (IndexOutOfBoundsException e) {
      assertTrue(true);
    } catch (Exception e) {
      fail();
    }
    try {
      a.getComplex(123);
      fail();
    } catch (IndexOutOfBoundsException e) {
      assertTrue(true);
    } catch (Exception e) {
      fail();
    }

    // if nothing interfered in between all values should be correct
    assertTrue(a.getComplex(0).equals(new Complex(1, 2)));
    assertTrue(a.getComplex(1).equals(new Complex(5, -7)));
    assertTrue(a.getComplex(2).equals(new Complex(-24, 42)));
    assertTrue(a.getComplex(3).equals(new Complex(10, 12)));
    assertTrue(a.getComplex(4).equals(new Complex(0, 0)));
  }
View Full Code Here

  /**
   * Test set length.
   */
  public void testSetLength() {
    ComplexArray1D a =
        new ComplexArray1D(new Complex[] { new Complex(1, 2),
            new Complex(3, 4), new Complex(5, 6) });

    assertTrue(a.getLength() == 3);
    assertTrue(a.getComplex(0).equals(new Complex(1, 2)));
    assertTrue(a.getComplex(1).equals(new Complex(3, 4)));
    assertTrue(a.getComplex(2).equals(new Complex(5, 6)));

    a.setLength(3);

    assertTrue(a.getLength() == 3);
    assertTrue(a.getComplex(0).equals(new Complex(1, 2)));
    assertTrue(a.getComplex(1).equals(new Complex(3, 4)));
    assertTrue(a.getComplex(2).equals(new Complex(5, 6)));

    a.setLength(2);

    assertTrue(a.getLength() == 2);
    assertTrue(a.getComplex(0).equals(new Complex(1, 2)));
    assertTrue(a.getComplex(1).equals(new Complex(3, 4)));

    a.setLength(3);

    assertTrue(a.getLength() == 3);
    assertTrue(a.getComplex(0).equals(new Complex(1, 2)));
    assertTrue(a.getComplex(1).equals(new Complex(3, 4)));
    assertTrue(a.getComplex(2).equals(new Complex(0, 0)));
  }
View Full Code Here

TOP

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

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.