Пример #1
0
 @Test
 public void testSingleton() {
   builder.add(1, 3.5);
   MutableSparseVector vec = Vectors.fromScoredIds(builder.finish());
   assertThat(vec.size(), equalTo(1));
   assertThat(vec.get(1), equalTo(3.5));
 }
Пример #2
0
 @Test
 public void testSome() {
   builder.add(1, 3.5);
   builder.add(3, 5.2);
   builder.add(-1, 0.2);
   MutableSparseVector vec = Vectors.fromScoredIds(builder.finish());
   assertThat(vec.size(), equalTo(3));
   assertThat(vec.get(1), equalTo(3.5));
   assertThat(vec.get(3), equalTo(5.2));
   assertThat(vec.get(-1), equalTo(0.2));
 }
 @Test
 public void testOverSize() {
   long[] keys = {3, 7, 9};
   double[] values = {Math.PI, Math.E, 0.42};
   ImmutableSparseVector v = MutableSparseVector.wrap(keys, values, 2).freeze();
   assertThat(v.size(), equalTo(2));
   assertThat(v.containsKey(9), equalTo(false));
   assertThat(v.get(9, Double.NaN), notANumber());
   assertThat(v.get(3), closeTo(Math.PI));
   assertThat(v.containsKey(9), equalTo(false));
 }
Пример #4
0
 @Test
 public void testEmpty() {
   MutableSparseVector vec = Vectors.fromScoredIds(Collections.<ScoredId>emptyList());
   assertThat(vec.size(), equalTo(0));
 }
 @Override
 protected ImmutableSparseVector singleton() {
   return MutableSparseVector.wrap(new long[] {5}, new double[] {Math.PI}).freeze();
 }
 @Override
 protected ImmutableSparseVector simpleVector2() {
   long[] keys = {3, 5, 8};
   double[] values = {2, 2.3, 1.7};
   return MutableSparseVector.wrap(keys, values).freeze();
 }
 @Override
 protected ImmutableSparseVector simpleVector() {
   long[] keys = {3, 7, 8};
   double[] values = {1.5, 3.5, 2};
   return MutableSparseVector.wrap(keys, values).freeze();
 }