Package org.jamesii.core.math.complex

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


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

    try {
      a.setLength(-1);
      fail();
    } catch (IllegalArgumentException e) {
      assertTrue(true);
    } catch (Exception e) {
      fail();
View Full Code Here


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

    try {
      a.negate(-1);
      fail();
    } catch (IndexOutOfBoundsException e) {
      assertTrue(true);
    } catch (Exception e) {
      fail();
    }
    try {
      a.negate(5);
      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 negate.
   */
  public void testNegate() {
    ComplexArray1D a =
        new ComplexArray1D(new Complex[] { new Complex(1, 4),
            new Complex(-2, 3), new Complex(-1, -3), new Complex() });

    ComplexArray1D b = new ComplexArray1D(a.toComplexArray());

    for (int i = 0; i < a.getLength(); i++) {
      a.negate(i);

      // check for side-effects in other numbers of the array -- there shouldn't
      // be any
      for (int j = 0; j < a.getLength(); j++) {
        if (i != j) {
          assertTrue(a.getComplex(j) + " was not equal to " + b.getComplex(j),
              a.getComplex(j).equals(b.getComplex(j)));
        } else {
          assertTrue(a.getComplex(j).equals(b.getComplex(j).negate()));
        }
      }

      // since the operation is the reverse of itself, this should revert
      // everything back to the state before
      a.negate(i);
      assertTrue(a.getComplex(i).equals(b.getComplex(i)));
    }
  }
View Full Code Here

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

    try {
      a.conjugate(-1);
      fail();
    } catch (IndexOutOfBoundsException e) {
      assertTrue(true);
    } catch (Exception e) {
      fail();
    }
    try {
      a.conjugate(5);
      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 conjugate.
   */
  public void testConjugate() {
    ComplexArray1D a =
        new ComplexArray1D(new Complex[] { new Complex(1, 4),
            new Complex(-2, 3), new Complex(-1, -3), new Complex() });

    ComplexArray1D b = new ComplexArray1D(a.toComplexArray());

    for (int i = 0; i < a.getLength(); i++) {
      a.conjugate(i);

      // check for side-effects in other numbers of the array -- there shouldn't
      // be any
      for (int j = 0; j < a.getLength(); j++) {
        if (i != j) {
          assertTrue(a.getComplex(j) + " was not equal to " + b.getComplex(j),
              a.getComplex(j).equals(b.getComplex(j)));
        } else {
          assertTrue(a.getComplex(j).equals(b.getComplex(j).conjugate()));
        }
      }

      // since the operation is the reverse of itself, this should revert
      // everything back to the state before
      a.conjugate(i);
      assertTrue(a.getComplex(i).equals(b.getComplex(i)));
    }
  }
View Full Code Here

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

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

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

    // testing add(int, int, int)
    try {
      a.add(-1, 0, 0);
      fail();
    } catch (IndexOutOfBoundsException e) {
      assertTrue(true);
    } catch (Exception e) {
      fail();
    }
    try {
      a.add(5, 0, 0);
      fail();
    } catch (IndexOutOfBoundsException e) {
      assertTrue(true);
    } catch (Exception e) {
      fail();
    }
    try {
      a.add(0, -2, 0);
      fail();
    } catch (IndexOutOfBoundsException e) {
      assertTrue(true);
    } catch (Exception e) {
      fail();
    }
    try {
      a.add(0, 10, 0);
      fail();
    } catch (IndexOutOfBoundsException e) {
      assertTrue(true);
    } catch (Exception e) {
      fail();
    }
    try {
      a.add(0, 0, -1);
      fail();
    } catch (IndexOutOfBoundsException e) {
      assertTrue(true);
    } catch (Exception e) {
      fail();
    }
    try {
      a.add(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 add.
   */
  public void testAdd() {
    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 add(int, int, int)
    a.add(0, 1, 2);
    assertTrue(a.getComplex(0).equals(new Complex(8, 10)));
    assertTrue(a.getComplex(1).equals(new Complex(3, 4)));
    assertTrue(a.getComplex(2).equals(new Complex(5, 6)));

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

    // testing add(int, double, double, double, double)
    a.add(2, 4, 2, -1, -8);
    assertTrue(a.getComplex(0).equals(new Complex(4.5, -.75)));
    assertTrue(a.getComplex(1).equals(new Complex(3, 4)));
    assertTrue(a.getComplex(2).equals(new Complex(3, -6)));
  }
View Full Code Here

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

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

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

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

    // testing subtract(int, int, int)
    try {
      a.subtract(-1, 0, 0);
      fail();
    } catch (IndexOutOfBoundsException e) {
      assertTrue(true);
    } catch (Exception e) {
      fail();
    }
    try {
      a.add(5, 0, 0);
      fail();
    } catch (IndexOutOfBoundsException e) {
      assertTrue(true);
    } catch (Exception e) {
      fail();
    }
    try {
      a.add(0, -2, 0);
      fail();
    } catch (IndexOutOfBoundsException e) {
      assertTrue(true);
    } catch (Exception e) {
      fail();
    }
    try {
      a.add(0, 10, 0);
      fail();
    } catch (IndexOutOfBoundsException e) {
      assertTrue(true);
    } catch (Exception e) {
      fail();
    }
    try {
      a.add(0, 0, -1);
      fail();
    } catch (IndexOutOfBoundsException e) {
      assertTrue(true);
    } catch (Exception e) {
      fail();
    }
    try {
      a.add(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 subtract.
   */
  public void testSubtract() {
    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 subtract(int, int, int)
    a.subtract(0, 1, 2);
    assertTrue(a.getComplex(0).equals(new Complex(-2, -2)));
    assertTrue(a.getComplex(1).equals(new Complex(3, 4)));
    assertTrue(a.getComplex(2).equals(new Complex(5, 6)));

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

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

    // testing subtract(int, double, double, double, double)
    a.subtract(2, 4, 2, -1, -8);
    assertTrue(a.getComplex(0).equals(new Complex(-3.5, -10.75)));
    assertTrue(a.getComplex(1).equals(new Complex(3, 4)));
    assertTrue(a.getComplex(2).equals(new Complex(5, 10)));
  }
View Full Code Here

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

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

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

    // testing multiply(int, int, int)
    try {
      a.multiply(-1, 0, 0);
      fail();
    } catch (IndexOutOfBoundsException e) {
      assertTrue(true);
    } catch (Exception e) {
      fail();
    }
    try {
      a.multiply(5, 0, 0);
      fail();
    } catch (IndexOutOfBoundsException e) {
      assertTrue(true);
    } catch (Exception e) {
      fail();
    }
    try {
      a.multiply(0, -2, 0);
      fail();
    } catch (IndexOutOfBoundsException e) {
      assertTrue(true);
    } catch (Exception e) {
      fail();
    }
    try {
      a.multiply(0, 10, 0);
      fail();
    } catch (IndexOutOfBoundsException e) {
      assertTrue(true);
    } catch (Exception e) {
      fail();
    }
    try {
      a.multiply(0, 0, -1);
      fail();
    } catch (IndexOutOfBoundsException e) {
      assertTrue(true);
    } catch (Exception e) {
      fail();
    }
    try {
      a.multiply(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

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.