ArrayFeatureVector extends FeatureVector { public void set(int index, double value) throws InvalidFeatureVectorValueException { if (Double.isInfinite(value) || Double.isNaN(value)) throw new InvalidFeatureVectorValueException(index, value); for (int i = features.size(); i <= index; i++) features.add(0.0); features.set(index, value); } ArrayFeatureVector(); double get(int index); java.util.Iterator<Entry> iterator(); void set(int index, double value); double[] toArray();  }
@Test public void testEquals() throws Throwable { FeatureVector fv = new ArrayFeatureVector(); fv.set(1, 4.5); fv.set(5, 7.1); fv.set(6, 13); assertFalse(fv.equals(fv2)); fv.set(10, 2.3); assertTrue(fv.equals(fv2)); assertEquals(fv.hashCode(), fv2.hashCode()); fv.set(11, 7); assertFalse(fv.equals(fv2)); fv.set(5, 7.2); assertFalse(fv.equals(fv2)); assertFalse(fv.equals(new Integer(5))); }
@Test public void testInnerProduct() throws Throwable { FeatureVector fv = new SparseFeatureVector(); fv.set(1, 1); fv.set(3, 2.5); fv.set(6, 0.5); assertEquals(fv.innerProduct(fv2), 11, delta); assertEquals(fv2.innerProduct(fv), 11, delta); }