public void testPlusDouble() throws Exception {
   Vector val = test.plus(1);
   assertEquals("size", test.size(), val.size());
   for (int i = 0; i < test.size(); i++) {
     if (i % 2 == 0) {
       assertEquals("get [" + i + ']', 1.0, val.get(i));
     } else {
       assertEquals("get [" + i + ']', values[i / 2] + 1.0, val.get(i));
     }
   }
 }
 public void testDivideDouble() throws Exception {
   Vector val = test.divide(3);
   assertEquals("size", test.size(), val.size());
   for (int i = 0; i < test.size(); i++) {
     if (i % 2 == 0) {
       assertEquals("get [" + i + ']', 0.0, val.get(i));
     } else {
       assertEquals("get [" + i + ']', values[i / 2] / 3.0, val.get(i), EPSILON);
     }
   }
 }
 public void testTimesVector() throws Exception {
   Vector val = test.times(test);
   assertEquals("size", test.size(), val.size());
   for (int i = 0; i < test.size(); i++) {
     if (i % 2 == 0) {
       assertEquals("get [" + i + ']', 0.0, val.get(i));
     } else {
       assertEquals("get [" + i + ']', values[i / 2] * values[i / 2], val.get(i));
     }
   }
 }
  public void testMinus() throws Exception {
    Vector val = test.minus(test);
    assertEquals("size", test.size(), val.size());
    for (int i = 0; i < test.size(); i++) {
      assertEquals("get [" + i + ']', 0.0, val.get(i));
    }

    val = test.minus(test).minus(test);
    assertEquals("cardinality", test.size(), val.size());
    for (int i = 0; i < test.size(); i++) {
      assertEquals("get [" + i + ']', 0.0, val.get(i) + test.get(i));
    }

    Vector val1 = test.plus(1);
    val = val1.minus(test);
    for (int i = 0; i < test.size(); i++) {
      assertEquals("get [" + i + ']', 1.0, val.get(i));
    }

    val1 = test.plus(-1);
    val = val1.minus(test);
    for (int i = 0; i < test.size(); i++) {
      assertEquals("get [" + i + ']', -1.0, val.get(i));
    }
  }
 public void testAssignDoubleArray() throws Exception {
   double[] array = new double[test.size()];
   test.assign(array);
   for (int i = 0; i < values.length; i++) {
     assertEquals("value[" + i + ']', 0.0, test.getQuick(i));
   }
 }
 public void testAssignVector() throws Exception {
   Vector other = new DenseVector(test.size());
   test.assign(other);
   for (int i = 0; i < values.length; i++) {
     assertEquals("value[" + i + ']', 0.0, test.getQuick(i));
   }
 }
 public void testSparseDoubleVectorInt() throws Exception {
   Vector val = new RandomAccessSparseVector(4);
   assertEquals("size", 4, val.size());
   for (int i = 0; i < 4; i++) {
     assertEquals("get [" + i + ']', 0.0, val.get(i));
   }
 }
 public void testViewPart() throws Exception {
   Vector part = test.viewPart(1, 2);
   assertEquals("part size", 2, part.getNumNondefaultElements());
   for (int i = 0; i < part.size(); i++) {
     assertEquals("part[" + i + ']', test.get(i + 1), part.get(i));
   }
 }
 public void testTimesVectorCardinality() {
   try {
     test.times(new DenseVector(test.size() + 1));
     fail("expected exception");
   } catch (CardinalityException e) {
   }
 }
 public void testGetOver() {
   try {
     test.get(test.size());
     fail("expected exception");
   } catch (IndexException e) {
   }
 }
 public void testAssignDoubleArrayCardinality() {
   double[] array = new double[test.size() + 1];
   try {
     test.assign(array);
     fail("cardinality exception expected");
   } catch (CardinalityException e) {
   }
 }
 public void testAssignVectorCardinality() {
   Vector other = new DenseVector(test.size() - 1);
   try {
     test.assign(other);
     fail("cardinality exception expected");
   } catch (CardinalityException e) {
   }
 }
 public void testGet() throws Exception {
   for (int i = 0; i < test.size(); i++) {
     if (i % 2 == 0) {
       assertEquals("get [" + i + ']', 0.0, test.get(i));
     } else {
       assertEquals("get [" + i + ']', values[i / 2], test.get(i));
     }
   }
 }
 public void testNormalize() throws Exception {
   Vector val = test.normalize();
   double mag = Math.sqrt(1.1 * 1.1 + 2.2 * 2.2 + 3.3 * 3.3);
   for (int i = 0; i < test.size(); i++) {
     if (i % 2 == 0) {
       assertEquals("get [" + i + ']', 0.0, val.get(i));
     } else {
       assertEquals("dot", values[i / 2] / mag, val.get(i));
     }
   }
 }
 public void testGetDistanceSquared() {
   Vector other = new RandomAccessSparseVector(test.size());
   other.set(1, -2);
   other.set(2, -5);
   other.set(3, -9);
   other.set(4, 1);
   double expected = test.minus(other).getLengthSquared();
   assertTrue(
       "a.getDistanceSquared(b) != a.minus(b).getLengthSquared",
       Math.abs(expected - test.getDistanceSquared(other)) < 10.0E-7);
 }
 public void testSet() throws Exception {
   test.set(3, 4.5);
   for (int i = 0; i < test.size(); i++) {
     if (i % 2 == 0) {
       assertEquals("get [" + i + ']', 0.0, test.get(i));
     } else if (i == 3) {
       assertEquals("set [" + i + ']', 4.5, test.get(i));
     } else {
       assertEquals("set [" + i + ']', values[i / 2], test.get(i));
     }
   }
 }
 public void testCrossProduct() {
   Matrix result = test.cross(test);
   assertEquals("row size", test.size(), result.size()[0]);
   assertEquals("col size", test.size(), result.size()[1]);
   for (int row = 0; row < result.size()[0]; row++) {
     for (int col = 0; col < result.size()[1]; col++) {
       assertEquals(
           "cross[" + row + "][" + col + ']',
           test.getQuick(row) * test.getQuick(col),
           result.getQuick(row, col));
     }
   }
 }
 public void testLike() {
   Vector other = test.like();
   assertTrue("not like", test.getClass().isAssignableFrom(other.getClass()));
   assertEquals("size", test.size(), other.size());
 }
 public void testDecodeVector() throws Exception {
   Vector val = AbstractVector.decodeVector(test.asFormatString());
   for (int i = 0; i < test.size(); i++) {
     assertEquals("get [" + i + ']', test.get(i), val.get(i));
   }
 }
 public void testCardinality() {
   assertEquals("size", 7, test.size());
 }
 public void testCopy() throws Exception {
   Vector copy = test.clone();
   for (int i = 0; i < test.size(); i++) {
     assertEquals("copy [" + i + ']', test.get(i), copy.get(i));
   }
 }