Skip to content

Commit

Permalink
Add test when similarity is the same for all nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
tdebatty committed Feb 20, 2019
1 parent 5cac32b commit 14b797f
Showing 1 changed file with 32 additions and 13 deletions.
45 changes: 32 additions & 13 deletions src/test/java/info/debatty/java/graphs/build/NNDescentTest.java
Expand Up @@ -35,19 +35,6 @@
*/
public class NNDescentTest extends TestCase {

public NNDescentTest(String testName) {
super(testName);
}

@Override
protected void setUp() throws Exception {
super.setUp();
}

@Override
protected void tearDown() throws Exception {
super.tearDown();
}

public void testComputeGraph() {
System.out.println("computeGraph");
Expand Down Expand Up @@ -96,4 +83,36 @@ public double similarity(Integer value1, Integer value2) {

}

public void testComputeSameDistance() {
System.out.println("computeGraphSameDistance");

int n = 20000;
int k = 10;

// Generate some nodes
Random rand = new Random();
LinkedList<Integer> nodes = new LinkedList<Integer>();
for (int i = 0; i < n; i++) {
nodes.add(rand.nextInt());
}

// This dummy similarity measure always returns the same value
SimilarityInterface<Integer> sim = new SimilarityInterface<Integer>() {
public double similarity(Integer value1, Integer value2) {
return 0.5;
}
};

// Instantiate and configure the brute-force graph building algorithm
NNDescent<Integer> nndes = new NNDescent<Integer>();
nndes.setK(k);
nndes.setSimilarity(sim);
nndes.setDelta(0.001);
nndes.setMaxIterations(100);
nndes.setRho(0.6);

// Run the algorithm, and get the resulting neighbor lists
Graph<Integer> graph = nndes.computeGraph(nodes);
}

}

0 comments on commit 14b797f

Please sign in to comment.