add --shared
[pylucene.git] / lucene-java-3.4.0 / lucene / contrib / facet / src / test / org / apache / lucene / facet / example / TestMultiCLExample.java
1 package org.apache.lucene.facet.example;
2
3 import java.util.Iterator;
4 import java.util.List;
5
6 import org.junit.Test;
7
8 import org.apache.lucene.util.LuceneTestCase;
9 import org.apache.lucene.facet.example.ExampleResult;
10 import org.apache.lucene.facet.example.multiCL.MultiCLMain;
11 import org.apache.lucene.facet.search.results.FacetResult;
12 import org.apache.lucene.facet.search.results.FacetResultNode;
13
14 /**
15  * Licensed to the Apache Software Foundation (ASF) under one or more
16  * contributor license agreements.  See the NOTICE file distributed with
17  * this work for additional information regarding copyright ownership.
18  * The ASF licenses this file to You under the Apache License, Version 2.0
19  * (the "License"); you may not use this file except in compliance with
20  * the License.  You may obtain a copy of the License at
21  *
22  *     http://www.apache.org/licenses/LICENSE-2.0
23  *
24  * Unless required by applicable law or agreed to in writing, software
25  * distributed under the License is distributed on an "AS IS" BASIS,
26  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
27  * See the License for the specific language governing permissions and
28  * limitations under the License.
29  */
30
31 /**
32  * Test that the multi-category list example works as expected. This test helps
33  * to verify that examples code is alive!
34  */
35 public class TestMultiCLExample extends LuceneTestCase {
36
37   @Test
38   public void testMulti() throws Exception {
39     ExampleResult res = new MultiCLMain().runSample();
40     assertCorrectMultiResults(res);
41   }
42
43   public static void assertCorrectMultiResults(ExampleResult exampleResults)
44       throws Exception {
45     List<FacetResult> results = exampleResults.getFacetResults();
46     FacetResult result = results.get(0);
47     assertNotNull("Result should not be null", result);
48     assertEquals("Invalid label", "5", result.getFacetResultNode()
49         .getLabel().toString());
50     assertEquals("Invalid value", 2.0, result.getFacetResultNode()
51         .getValue(), 0.0);
52     assertEquals("Invalid # of subresults", 3, result.getFacetResultNode()
53         .getNumSubResults());
54
55     Iterator<? extends FacetResultNode> subResults = result
56         .getFacetResultNode().getSubResults().iterator();
57     FacetResultNode sub = subResults.next();
58     assertEquals("Invalid subresult value", 1.0, sub.getValue(), 0.0);
59     assertEquals("Invalid subresult label", "5/2", sub.getLabel()
60         .toString());
61     sub = subResults.next();
62     assertEquals("Invalid subresult value", 1.0, sub.getValue(), 0.0);
63     assertEquals("Invalid subresult label", "5/7", sub.getLabel()
64         .toString());
65     sub = subResults.next();
66     assertEquals("Invalid subresult value", 1.0, sub.getValue(), 0.0);
67     assertEquals("Invalid subresult label", "5/5", sub.getLabel()
68         .toString());
69
70     result = results.get(1);
71     assertNotNull("Result should not be null", result);
72     assertEquals("Invalid label", "5/5", result.getFacetResultNode()
73         .getLabel().toString());
74     assertEquals("Invalid value", 1,
75         result.getFacetResultNode().getValue(), 0.0);
76     assertEquals("Invalid number of subresults", 0, result
77         .getFacetResultNode().getNumSubResults());
78
79     result = results.get(2);
80     assertNotNull("Result should not be null", result);
81     assertEquals("Invalid label", "6/2", result.getFacetResultNode()
82         .getLabel().toString());
83     assertEquals("Invalid value", 1,
84         result.getFacetResultNode().getValue(), 0.0);
85     assertEquals("Invalid number of subresults", 0, result
86         .getFacetResultNode().getNumSubResults());
87
88   }
89
90 }