1 package org.apache.lucene.facet.example;
5 import org.apache.lucene.util.LuceneTestCase;
6 import org.apache.lucene.facet.example.ExampleResult;
7 import org.apache.lucene.facet.example.association.AssociationMain;
8 import org.apache.lucene.facet.search.results.FacetResultNode;
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed with
13 * this work for additional information regarding copyright ownership.
14 * The ASF licenses this file to You under the Apache License, Version 2.0
15 * (the "License"); you may not use this file except in compliance with
16 * the License. You may obtain a copy of the License at
18 * http://www.apache.org/licenses/LICENSE-2.0
20 * Unless required by applicable law or agreed to in writing, software
21 * distributed under the License is distributed on an "AS IS" BASIS,
22 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23 * See the License for the specific language governing permissions and
24 * limitations under the License.
28 * Test that the association example works as expected. This test helps to
29 * verify that examples code is alive!
31 public class TestAssociationExample extends LuceneTestCase {
33 private static final double[] EXPECTED_INT_SUM_RESULTS = { 4, 2};
34 private static final double[] EXPECTED_FLOAT_SUM_RESULTS = { 1.62, 0.34};
37 public void testAssociationExamples() throws Exception {
38 assertExampleResult(new AssociationMain().runSumIntAssociationSample(), EXPECTED_INT_SUM_RESULTS);
39 assertExampleResult(new AssociationMain().runSumFloatAssociationSample(), EXPECTED_FLOAT_SUM_RESULTS);
42 private void assertExampleResult(ExampleResult res, double[] expectedResults) {
43 assertNotNull("Null result!", res);
44 assertNotNull("Null facet result!", res.getFacetResults());
45 assertEquals("Wrong number of results!", 1, res.getFacetResults().size());
46 assertEquals("Wrong number of facets!", 2, res.getFacetResults().get(0).getNumValidDescendants());
48 Iterable<? extends FacetResultNode> it = res.getFacetResults().get(0).getFacetResultNode().getSubResults();
50 for (FacetResultNode fResNode : it) {
51 assertEquals("Wrong result for facet "+fResNode.getLabel(), expectedResults[i++], fResNode.getValue(), 1E-5);