|
| 1 | +/* |
| 2 | + * Copyright (c) "Neo4j" |
| 3 | + * Neo4j Sweden AB [http://neo4j.com] |
| 4 | + * |
| 5 | + * This file is part of Neo4j. |
| 6 | + * |
| 7 | + * Neo4j is free software: you can redistribute it and/or modify |
| 8 | + * it under the terms of the GNU General Public License as published by |
| 9 | + * the Free Software Foundation, either version 3 of the License, or |
| 10 | + * (at your option) any later version. |
| 11 | + * |
| 12 | + * This program is distributed in the hope that it will be useful, |
| 13 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | + * GNU General Public License for more details. |
| 16 | + * |
| 17 | + * You should have received a copy of the GNU General Public License |
| 18 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | + */ |
| 20 | +package org.neo4j.gds.similarity; |
| 21 | + |
| 22 | +import org.junit.jupiter.params.ParameterizedTest; |
| 23 | +import org.junit.jupiter.params.provider.Arguments; |
| 24 | +import org.junit.jupiter.params.provider.MethodSource; |
| 25 | + |
| 26 | +import java.util.Arrays; |
| 27 | +import java.util.List; |
| 28 | +import java.util.stream.Collector; |
| 29 | +import java.util.stream.Collectors; |
| 30 | +import java.util.stream.Stream; |
| 31 | + |
| 32 | +import static org.assertj.core.api.Assertions.assertThat; |
| 33 | + |
| 34 | +class JaccardSimilarityTest { |
| 35 | + |
| 36 | + @ParameterizedTest(name = "{2}") |
| 37 | + @MethodSource("listCollectors") |
| 38 | + void shouldPassAtAllCasesOfListInput( |
| 39 | + Collector<Number, ?, List<Number>> firstListCollector, |
| 40 | + Collector<Number, ?, List<Number>> secondListCollector, |
| 41 | + String label |
| 42 | + ) { |
| 43 | + var arr1 = new int[]{1,2,3}; |
| 44 | + var arr2 = new int[]{1,2,3}; |
| 45 | + List<Number> l1 = Arrays.stream(arr1).boxed().collect(firstListCollector); |
| 46 | + List<Number> l2 = Arrays.stream(arr2).boxed().collect(secondListCollector); |
| 47 | + |
| 48 | + var similarities = new SimilaritiesFunc(); |
| 49 | + var jaccarded = similarities.jaccardSimilarity(l1, l2); |
| 50 | + assertThat(jaccarded).isEqualTo(1); |
| 51 | + } |
| 52 | + |
| 53 | + private static Stream<Arguments> listCollectors() { |
| 54 | + return Stream.of( |
| 55 | + Arguments.of( |
| 56 | + Collectors.toUnmodifiableList(), Collectors.toUnmodifiableList(), "Unmodifiable, Unmodifiable" |
| 57 | + ), |
| 58 | + Arguments.of( |
| 59 | + Collectors.toUnmodifiableList(), Collectors.toList(), "Unmodifiable, Modifiable" |
| 60 | + ), |
| 61 | + Arguments.of( |
| 62 | + Collectors.toList(), Collectors.toList(), "Modifiable, Modifiable" |
| 63 | + ), |
| 64 | + Arguments.of( |
| 65 | + Collectors.toList(), Collectors.toUnmodifiableList(), "Modifiable, Unmodifiable" |
| 66 | + ) |
| 67 | + ); |
| 68 | + } |
| 69 | + |
| 70 | +} |
0 commit comments