Skip to content

Commit

Permalink
Move the Jaccard test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
vnickolov committed Nov 27, 2023
1 parent c344608 commit 21702e0
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 135 deletions.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,12 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collector;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatNoException;
import static org.junit.jupiter.api.Assertions.assertEquals;

class SimilaritiesFuncTest {
Expand Down Expand Up @@ -157,4 +160,39 @@ void testJaccardWithNulls() {
assertEquals(1 / 3.0, new SimilaritiesFunc().jaccardSimilarity(left, right));
}

@ParameterizedTest(name = "{2}")
@MethodSource("listCollectors")
void shouldComputeJaccardAtAllCasesOfListInput(
Collector<Number, ?, List<Number>> firstListCollector,
Collector<Number, ?, List<Number>> secondListCollector,
String label
) {
var arr1 = new int[]{1,2,3};
var arr2 = new int[]{1,2,3};
var l1 = Arrays.stream(arr1).boxed().collect(firstListCollector);
var l2 = Arrays.stream(arr2).boxed().collect(secondListCollector);

var similarities = new SimilaritiesFunc();
assertThatNoException().isThrownBy(
() -> assertThat(similarities.jaccardSimilarity(l1, l2)).isEqualTo(1)
);
}

private static Stream<Arguments> listCollectors() {
return Stream.of(
Arguments.of(
Collectors.toUnmodifiableList(), Collectors.toUnmodifiableList(), "Unmodifiable, Unmodifiable"
),
Arguments.of(
Collectors.toUnmodifiableList(), Collectors.toList(), "Unmodifiable, Modifiable"
),
Arguments.of(
Collectors.toList(), Collectors.toList(), "Modifiable, Modifiable"
),
Arguments.of(
Collectors.toList(), Collectors.toUnmodifiableList(), "Modifiable, Unmodifiable"
)
);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
import org.neo4j.gds.BaseTest;
import org.neo4j.gds.compat.GraphDatabaseApiProxy;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatNoException;
import static org.assertj.core.api.InstanceOfAssertFactories.DOUBLE;
import static org.junit.jupiter.api.Assertions.assertEquals;

class SimilaritiesFuncWithCypherTest extends BaseTest {
Expand Down Expand Up @@ -80,4 +83,20 @@ void testJaccardFunction() {
result -> assertEquals(1.0 / 3.0, result.next().get("score"))
);
}

@Test
void testJaccardFunctionWithInputFromDatabase() {
assertThatNoException().isThrownBy(
() -> runQueryWithResultConsumer(
"CREATE (t:Test {listone: [1, 5], listtwo: [5, 5]}) RETURN gds.similarity.jaccard(t.listone, t.listtwo) AS score",
result -> {
assertThat(result.hasNext()).isTrue();
var score = result.next().get("score");
assertThat(score)
.asInstanceOf(DOUBLE)
.isEqualTo(1.0 / 3.0);
}
)
);
}
}

0 comments on commit 21702e0

Please sign in to comment.