Package org.jamesii.core.math

Examples of org.jamesii.core.math.Matrix


   * exceptions when encountering invalid arguments.
   */
  public void testAddRowsExceptions() {
    // TODO: Should the exception being thrown here really be an
    // ArrayIndexOutOfBoundsException?
    Matrix m = new Matrix(3);

    // test addRows(int, int)

    try {
      m.addRows(1, 3);
      fail();
    } catch (ArrayIndexOutOfBoundsException e) {
      assertTrue(true);
    } catch (Throwable e) {
      fail();
    }

    try {
      m.addRows(5, 2);
      fail();
    } catch (ArrayIndexOutOfBoundsException e) {
      assertTrue(true);
    } catch (Throwable e) {
      fail();
    }

    try {
      m.addRows(-1, 1);
      fail();
    } catch (ArrayIndexOutOfBoundsException e) {
      assertTrue(true);
    } catch (Throwable e) {
      fail();
    }

    try {
      m.addRows(1, -3);
      fail();
    } catch (ArrayIndexOutOfBoundsException e) {
      assertTrue(true);
    } catch (Throwable e) {
      fail();
    }

    // test addRows(int, int, double)

    try {
      m.addRows(1, 3, 1);
      fail();
    } catch (ArrayIndexOutOfBoundsException e) {
      assertTrue(true);
    } catch (Throwable e) {
      fail();
    }

    try {
      m.addRows(5, 2, 2);
      fail();
    } catch (ArrayIndexOutOfBoundsException e) {
      assertTrue(true);
    } catch (Throwable e) {
      fail();
    }

    try {
      m.addRows(-1, 1, 3);
      fail();
    } catch (ArrayIndexOutOfBoundsException e) {
      assertTrue(true);
    } catch (Throwable e) {
      fail();
    }

    try {
      m.addRows(1, -3, 4);
      fail();
    } catch (ArrayIndexOutOfBoundsException e) {
      assertTrue(true);
    } catch (Throwable e) {
      fail();
View Full Code Here


    }
  }

  /** Tests the {@link Matrix#concat(Matrix)} method. */
  public void testConcat() {
    Matrix m1 = new Matrix(new double[][] { { 1, 2 }, { 3, 4 }, { 5, 6 } });
    Matrix m2 = new Matrix(new double[][] { { 7 }, { 6 }, { 5 } });
    double[][] result =
        new double[][] { { 1, 2, 7 }, { 3, 4, 6 }, { 5, 6, 5 } };

    m1.concat(m2);
    for (int c = 0; c < m1.getColumns(); c++) {
View Full Code Here

  /**
   * Tests whether the {@link Matrix#concat(Matrix)} method throws the correct
   * exceptions when the matrices can't be concatenated.
   */
  public void testConcatExceptions() {
    Matrix m1 = new Matrix(3, 2);
    Matrix m2 = new Matrix(4, 5);

    try {
      m1.concat(m2);
      fail();
    } catch (MatrixException e) {
View Full Code Here

  }

  /** Tests the {@link Matrix#copy()} method. */
  public void testCopy() {
    double[][] data = new double[][] { { 1, 2, 3 }, { 4, 5, 6 } };
    Matrix m1 = new Matrix(data);

    Matrix m2 = m1.copy();

    assertNotNull(m2);
    assertFalse(m1 == m2);
    for (int c = 0; c < m1.getColumns(); c++) {
      for (int r = 0; r < m1.getRows(); r++) {
        assertEquals(data[r][c], m2.getElement(r, c));
      }
    }
  }
View Full Code Here

    }
  }

  /** Tests the {@link Matrix#det()} method. */
  public void testDet() {
    Matrix m = new Matrix(new double[][] { { 1, 2 }, { 4, 5 } });
    assertEquals(-3.0, m.det(), 0.000001);

    m = new Matrix(6);
    assertEquals(1.0, m.det(), 0.000001);

    m = new Matrix(new double[][] { { 1, 2, 0 }, { 4, 0, 8 }, { 1, 2, 2 } });
    assertEquals(-16.0, m.det(), 0.000001);

    m = new Matrix(0, 0);
    assertEquals(1.0, m.det(), 0.000001);

    m = new Matrix(1, 1);
    m.setElement(0, 0, 42.23);
    assertEquals(42.23, m.det(), 0.000001);
  }
View Full Code Here

   * Tests whether the {@link Matrix#det()} method throws the correct exceptions
   * when ran on a matrix that does not have a determinant.
   */
  public void testDetExceptions() {
    try {
      new Matrix(1, 2).det();
      fail();
    } catch (MatrixException e) {
      assertTrue(true);
    } catch (Throwable e) {
      fail();
View Full Code Here

    }
  }

  /** Tests the {@link Matrix#flood(double)} method. */
  public void testFlood() {
    Matrix m = new Matrix(10, 10);

    m.flood(42.23);

    for (int c = 0; c < m.getColumns(); c++) {
      for (int r = 0; r < m.getRows(); r++) {
        assertEquals(42.23, m.getElement(r, c));
      }
    }
  }
View Full Code Here

    }
  }

  /** Tests the {@link Matrix#getColumn(int)} method. */
  public void testGetColumn() {
    Matrix m = new Matrix(5);
    double[] c = m.getColumn(2);
    for (int i = 0; i < c.length; i++) {
      assertEquals(m.getElement(i, 2), c[i]);
    }
  }
View Full Code Here

  }

  /** Tests the {@link Matrix#getData()} method. */
  public void testGetData() {
    double[][] data = new double[][] { { 1, 2 }, { 3, 4 } };
    Matrix m = new Matrix(data);

    double[][] x = m.getData();
    for (int c = 0; c < m.getColumns(); c++) {
      for (int r = 0; r < m.getRows(); r++) {
        assertEquals(data[r][c], x[r][c]);
      }
    }

    // since the docs say it's a pointer to the internal data we can change it
    // and the change will be reflected in the Matrix object
    x[1][1] = 5.0;
    assertEquals(5.0, m.getElement(1, 1));
  }
View Full Code Here

    assertEquals(5.0, m.getElement(1, 1));
  }

  /** Tests the {@link Matrix#getRow(int)} method. */
  public void testGetRow() {
    Matrix m = new Matrix(5);
    double[] c = m.getRow(2);
    for (int i = 0; i < c.length; i++) {
      assertEquals(m.getElement(2, i), c[i]);
    }
  }
View Full Code Here

TOP

Related Classes of org.jamesii.core.math.Matrix

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.