long end = System.currentTimeMillis();
if (VERBOSE) {
System.out.println("Time: " + (end - start));
}
FacetResult fr = facetResults.get(0); // a, depth=3, K=2
boolean hasDoctor = "Doctor".equals(fr.getFacetRequest().getCategoryPath().getComponent(0));
assertEquals(9, fr.getNumValidDescendants());
FacetResultNode parentRes = fr.getFacetResultNode();
assertEquals(16.0, parentRes.getValue(), Double.MIN_VALUE);
assertEquals(2.0, parentRes.getResidue(), Double.MIN_VALUE);
assertEquals(2, parentRes.getNumSubResults());
// two nodes sorted by descending values: a/b with 8 and a/c with 6
// a/b has residue 2 and two children a/b/2 with value 3, and a/b/1 with value 2.
// a/c has residue 0, and one child a/c/1 with value 1.
double [] expectedValues0 = { 8.0, 2.0, 3.0, 0.0, 2.0, 0.0, 6.0, 0.0, 1.0, 0.0 };
int i = 0;
for (FacetResultNode node : parentRes.getSubResults()) {
assertEquals(expectedValues0[i++], node.getValue(), Double.MIN_VALUE);
assertEquals(expectedValues0[i++], node.getResidue(), Double.MIN_VALUE);
for (FacetResultNode node2 : node.getSubResults()) {
assertEquals(expectedValues0[i++], node2.getValue(), Double.MIN_VALUE);
assertEquals(expectedValues0[i++], node2.getResidue(), Double.MIN_VALUE);
}
}
// now just change the value of the first child of the root to 5, and then rearrange
// expected are: first a/c of value 6 and residue 0, and one child a/c/1 with value 1
// then a/b with value 5 and residue 2, and both children: a/b/2 with value 3, and a/b/1 with value 2.
for (FacetResultNode node : parentRes.getSubResults()) {
node.setValue(5.0);
break;
}
// now rearrange
double [] expectedValues00 = { 6.0, 0.0, 1.0, 0.0, 5.0, 2.0, 3.0, 0.0, 2.0, 0.0 };
fr = cfra23.createFacetResultsHandler(tr).rearrangeFacetResult(fr);
i = 0;
for (FacetResultNode node : parentRes.getSubResults()) {
assertEquals(expectedValues00[i++], node.getValue(), Double.MIN_VALUE);
assertEquals(expectedValues00[i++], node.getResidue(), Double.MIN_VALUE);
for (FacetResultNode node2 : node.getSubResults()) {
assertEquals(expectedValues00[i++], node2.getValue(), Double.MIN_VALUE);
assertEquals(expectedValues00[i++], node2.getResidue(), Double.MIN_VALUE);
}
}
fr = facetResults.get(1); // a, depth=2, K=2. same result as before
hasDoctor |= "Doctor".equals(fr.getFacetRequest().getCategoryPath().getComponent(0));
assertEquals(9, fr.getNumValidDescendants());
parentRes = fr.getFacetResultNode();
assertEquals(16.0, parentRes.getValue(), Double.MIN_VALUE);
assertEquals(2.0, parentRes.getResidue(), Double.MIN_VALUE);
assertEquals(2, parentRes.getNumSubResults());
// two nodes sorted by descending values: a/b with 8 and a/c with 6
// a/b has residue 2 and two children a/b/2 with value 3, and a/b/1 with value 2.
// a/c has residue 0, and one child a/c/1 with value 1.
i = 0;
for (FacetResultNode node : parentRes.getSubResults()) {
assertEquals(expectedValues0[i++], node.getValue(), Double.MIN_VALUE);
assertEquals(expectedValues0[i++], node.getResidue(), Double.MIN_VALUE);
for (FacetResultNode node2 : node.getSubResults()) {
assertEquals(expectedValues0[i++], node2.getValue(), Double.MIN_VALUE);
assertEquals(expectedValues0[i++], node2.getResidue(), Double.MIN_VALUE);
}
}
fr = facetResults.get(2); // a, depth=1, K=2
hasDoctor |= "Doctor".equals(fr.getFacetRequest().getCategoryPath().getComponent(0));
assertEquals(4, fr.getNumValidDescendants(), 4);
parentRes = fr.getFacetResultNode();
assertEquals(16.0, parentRes.getValue(), Double.MIN_VALUE);
assertEquals(2.0, parentRes.getResidue(), Double.MIN_VALUE);
assertEquals(2, parentRes.getNumSubResults());
// two nodes sorted by descending values:
// a/b with value 8 and residue 0 (because no children considered),
// and a/c with value 6 and residue 0 (because no children considered)
double [] expectedValues2 = { 8.0, 0.0, 6.0, 0.0 };
i = 0;
for (FacetResultNode node : parentRes.getSubResults()) {
assertEquals(expectedValues2[i++], node.getValue(), Double.MIN_VALUE);
assertEquals(expectedValues2[i++], node.getResidue(), Double.MIN_VALUE);
assertEquals(node.getNumSubResults(), 0);
}
fr = facetResults.get(3); // a/b, depth=3, K=2
hasDoctor |= "Doctor".equals(fr.getFacetRequest().getCategoryPath().getComponent(0));
assertEquals(4, fr.getNumValidDescendants());
parentRes = fr.getFacetResultNode();
assertEquals(8.0, parentRes.getValue(), Double.MIN_VALUE);
assertEquals(2.0, parentRes.getResidue(), Double.MIN_VALUE);
assertEquals(2, parentRes.getNumSubResults());
double [] expectedValues3 = { 3.0, 2.0 };
i = 0;
for (FacetResultNode node : parentRes.getSubResults()) {
assertEquals(expectedValues3[i++], node.getValue(), Double.MIN_VALUE);
assertEquals(0.0, node.getResidue(), Double.MIN_VALUE);
assertEquals(0, node.getNumSubResults());
}
fr = facetResults.get(4); // a/b, depth=2, K=2
hasDoctor |= "Doctor".equals(fr.getFacetRequest().getCategoryPath().getComponent(0));
assertEquals(4, fr.getNumValidDescendants());
parentRes = fr.getFacetResultNode();
assertEquals(8.0, parentRes.getValue(), Double.MIN_VALUE);
assertEquals(2.0, parentRes.getResidue(), Double.MIN_VALUE);
assertEquals(2, parentRes.getNumSubResults());
i = 0;
for (FacetResultNode node : parentRes.getSubResults()) {
assertEquals(expectedValues3[i++], node.getValue(), Double.MIN_VALUE);
assertEquals(0.0, node.getResidue(), Double.MIN_VALUE);
assertEquals(0, node.getNumSubResults());
}
fr = facetResults.get(5); // a/b, depth=1, K=2
hasDoctor |= "Doctor".equals(fr.getFacetRequest().getCategoryPath().getComponent(0));
assertEquals(4, fr.getNumValidDescendants());
parentRes = fr.getFacetResultNode();
assertEquals(8.0, parentRes.getValue(), Double.MIN_VALUE);
assertEquals(2.0, parentRes.getResidue(), Double.MIN_VALUE);
assertEquals(2, parentRes.getNumSubResults());
i = 0;
for (FacetResultNode node : parentRes.getSubResults()) {
assertEquals(expectedValues3[i++], node.getValue(), Double.MIN_VALUE);
assertEquals(0.0, node.getResidue(), Double.MIN_VALUE);
assertEquals(0, node.getNumSubResults());
}
fr = facetResults.get(6); // a/b, depth=0, K=2
hasDoctor |= "Doctor".equals(fr.getFacetRequest().getCategoryPath().getComponent(0));
assertEquals(0, fr.getNumValidDescendants()); // 0 descendants but rootnode
parentRes = fr.getFacetResultNode();
assertEquals(8.0, parentRes.getValue(), Double.MIN_VALUE);
assertEquals(0.0, parentRes.getResidue(), Double.MIN_VALUE);
assertEquals(0, parentRes.getNumSubResults());
hasDoctor |= "Doctor".equals(fr.getFacetRequest().getCategoryPath().getComponent(0));
// doctor, depth=1, K=2
assertFalse("Shouldn't have found anything for a FacetRequest " +
"of a facet that doesn't exist in the index.", hasDoctor);
assertEquals("Shouldn't have found more than seven request.", 7, facetResults.size());