Skip to content

Commit

Permalink
fixing tests (#291)
Browse files Browse the repository at this point in the history
Former-commit-id: a0d59d2
  • Loading branch information
silvanheller authored Apr 27, 2022
1 parent 3de8017 commit eb86c15
Showing 1 changed file with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,17 @@ protected void fillVectorData() {
vector[0] = i;
vector[1] = 1;
vector[2] = 0;
vectors.add(writer.generateTuple(String.format("%05d", i), vector));
vectors.add(writer.generateTuple(toId(i), vector));
}
/* We write a second vector with the same id in the db */
vectors.add(writer.generateTuple(String.format("%05d", 0), new float[]{0, 0, 0}));
vectors.add(writer.generateTuple(toId(0), new float[]{0, 0, 0}));
writer.persist(vectors);
}

private String toId(int id){
return String.format("%05d", id);
}

/**
* Create both a table for vector retrieval & text retrieval
*/
Expand Down Expand Up @@ -218,7 +222,7 @@ void countRowCount() {
void entriesExistById() {
this.writer.open(testVectorTableName);
for (int i = 0; i < MAX_VECTOR_ID; i++) {
Assertions.assertTrue(writer.idExists(String.valueOf(i)));
Assertions.assertTrue(writer.idExists(toId(i)));
}
this.writer.open(testTextTableName);
for (int i = 0; i < MAX_TEXT_ID; i++) {
Expand All @@ -231,7 +235,7 @@ void entriesExistById() {
@DisplayName("get multiple feature vectors")
void getFeatureVectors() {
this.selector.open(testVectorTableName);
final List<PrimitiveTypeProvider> vectors = this.selector.getFeatureVectorsGeneric(ID_COL_NAME, new StringTypeProvider("0"), FEATURE_VECTOR_COL_NAME, queryConfig);
final List<PrimitiveTypeProvider> vectors = this.selector.getFeatureVectorsGeneric(ID_COL_NAME, new StringTypeProvider(toId(0)), FEATURE_VECTOR_COL_NAME, queryConfig);
Assertions.assertTrue((Arrays.equals(PrimitiveTypeProvider.getSafeFloatArray(vectors.get(0)), new float[]{0, 0, 0}) | Arrays.equals(PrimitiveTypeProvider.getSafeFloatArray(vectors.get(0)), new float[]{0, 1, 0})));
Assertions.assertTrue((Arrays.equals(PrimitiveTypeProvider.getSafeFloatArray(vectors.get(1)), new float[]{0, 0, 0}) | Arrays.equals(PrimitiveTypeProvider.getSafeFloatArray(vectors.get(1)), new float[]{0, 1, 0})));
}
Expand All @@ -242,9 +246,9 @@ void knnSearch() {
selector.open(testVectorTableName);
List<SegmentDistanceElement> result = selector.getNearestNeighboursGeneric(3, new float[]{1, 1, 0}, FEATURE_VECTOR_COL_NAME, SegmentDistanceElement.class, queryConfig);
Assertions.assertEquals(3, result.size());
Assertions.assertEquals("1", result.get(0).getSegmentId());
Assertions.assertTrue(result.get(1).getSegmentId().equals("2") || result.get(2).getSegmentId().equals("2"));
Assertions.assertTrue(result.get(1).getSegmentId().equals("0") || result.get(2).getSegmentId().equals("0"));
Assertions.assertEquals(toId(1), result.get(0).getSegmentId());
Assertions.assertTrue(result.get(1).getSegmentId().equals(toId(2)) || result.get(2).getSegmentId().equals(toId(2)));
Assertions.assertTrue(result.get(1).getSegmentId().equals(toId(0)) || result.get(2).getSegmentId().equals(toId(0)));
}

@Test
Expand Down

0 comments on commit eb86c15

Please sign in to comment.