add --shared
[pylucene.git] / lucene-java-3.4.0 / lucene / contrib / facet / src / test / org / apache / lucene / facet / index / CategoryListPayloadStreamTest.java
1 package org.apache.lucene.facet.index;
2
3 import java.io.ByteArrayInputStream;
4
5 import org.junit.Test;
6
7 import org.apache.lucene.util.LuceneTestCase;
8 import org.apache.lucene.facet.index.CategoryListPayloadStream;
9 import org.apache.lucene.util.encoding.DGapIntDecoder;
10 import org.apache.lucene.util.encoding.DGapIntEncoder;
11 import org.apache.lucene.util.encoding.IntDecoder;
12 import org.apache.lucene.util.encoding.NOnesIntDecoder;
13 import org.apache.lucene.util.encoding.NOnesIntEncoder;
14 import org.apache.lucene.util.encoding.UniqueValuesIntEncoder;
15
16 /**
17  * Licensed to the Apache Software Foundation (ASF) under one or more
18  * contributor license agreements.  See the NOTICE file distributed with
19  * this work for additional information regarding copyright ownership.
20  * The ASF licenses this file to You under the Apache License, Version 2.0
21  * (the "License"); you may not use this file except in compliance with
22  * the License.  You may obtain a copy of the License at
23  *
24  *     http://www.apache.org/licenses/LICENSE-2.0
25  *
26  * Unless required by applicable law or agreed to in writing, software
27  * distributed under the License is distributed on an "AS IS" BASIS,
28  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29  * See the License for the specific language governing permissions and
30  * limitations under the License.
31  */
32
33 public class CategoryListPayloadStreamTest extends LuceneTestCase {
34
35   /**
36    * Verifies that a CategoryListPayloadStream can properly encode values into
37    * a byte stream for later constructing a Payload.
38    */
39   @Test
40   public void testStream() throws Exception {
41
42     CategoryListPayloadStream clps = new CategoryListPayloadStream(
43         new UniqueValuesIntEncoder(new DGapIntEncoder(
44             new NOnesIntEncoder(3))));
45
46     clps.appendIntToStream(1);
47     clps.appendIntToStream(10);
48     clps.appendIntToStream(100);
49     clps.appendIntToStream(1000);
50     clps.appendIntToStream(10000);
51     clps.appendIntToStream(100000);
52     clps.appendIntToStream(1000000);
53     clps.appendIntToStream(10000000);
54     clps.appendIntToStream(100000000);
55     clps.appendIntToStream(1000000000);
56     clps.appendIntToStream(Integer.MAX_VALUE);
57
58     ByteArrayInputStream bais = new ByteArrayInputStream(clps
59         .convertStreamToByteArray());
60     IntDecoder decoder = new DGapIntDecoder(new NOnesIntDecoder(3));
61     decoder.reInit(bais);
62     assertEquals("Wrong value in byte stream", 1, decoder.decode());
63     assertEquals("Wrong value in byte stream", 10, decoder.decode());
64     assertEquals("Wrong value in byte stream", 100, decoder.decode());
65     assertEquals("Wrong value in byte stream", 1000, decoder.decode());
66     assertEquals("Wrong value in byte stream", 10000, decoder.decode());
67     assertEquals("Wrong value in byte stream", 100000, decoder.decode());
68     assertEquals("Wrong value in byte stream", 1000000, decoder.decode());
69     assertEquals("Wrong value in byte stream", 10000000, decoder.decode());
70     assertEquals("Wrong value in byte stream", 100000000, decoder.decode());
71     assertEquals("Wrong value in byte stream", 1000000000, decoder.decode());
72     assertEquals("Wrong value in byte stream", Integer.MAX_VALUE, decoder.decode());
73     assertEquals("End of stream not reached", IntDecoder.EOS, decoder.decode());
74
75     clps.reset();
76     decoder.reInit(bais);
77     assertEquals("End of stream not reached", IntDecoder.EOS, decoder.decode());
78   }
79
80 }