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 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 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 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 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 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 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 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 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 testGetUnder() { try { test.get(-1); fail("expected exception"); } catch (IndexException e) { } }
public void testGetOver() { try { test.get(test.size()); fail("expected exception"); } catch (IndexException e) { } }
public void testAssignBinaryFunction3() throws Exception { test.assign(mult(4)); for (int i = 0; i < values.length; i++) { if (i % 2 == 0) { assertEquals("get [" + i + ']', 0.0, test.get(i)); } else { assertEquals("value[" + i + ']', values[i - 1] * 4, test.getQuick(i)); } } }
public void testIteratorSet() throws CloneNotSupportedException { Vector clone = test.clone(); Iterator<Vector.Element> it = clone.iterateNonZero(); while (it.hasNext()) { Vector.Element e = it.next(); e.set(e.get() * 2.0); } it = clone.iterateNonZero(); while (it.hasNext()) { Vector.Element e = it.next(); assertEquals(test.get(e.index()) * 2.0, e.get()); } clone = test.clone(); it = clone.iterator(); while (it.hasNext()) { Vector.Element e = it.next(); e.set(e.get() * 2.0); } it = clone.iterator(); while (it.hasNext()) { Vector.Element e = it.next(); assertEquals(test.get(e.index()) * 2.0, e.get()); } }
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 testCopy() throws Exception { Vector copy = test.clone(); for (int i = 0; i < test.size(); i++) { assertEquals("copy [" + i + ']', test.get(i), copy.get(i)); } }