1 package org.apache.lucene.facet.index;
3 import java.io.ByteArrayInputStream;
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;
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
24 * http://www.apache.org/licenses/LICENSE-2.0
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.
33 public class CategoryListPayloadStreamTest extends LuceneTestCase {
36 * Verifies that a CategoryListPayloadStream can properly encode values into
37 * a byte stream for later constructing a Payload.
40 public void testStream() throws Exception {
42 CategoryListPayloadStream clps = new CategoryListPayloadStream(
43 new UniqueValuesIntEncoder(new DGapIntEncoder(
44 new NOnesIntEncoder(3))));
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);
58 ByteArrayInputStream bais = new ByteArrayInputStream(clps
59 .convertStreamToByteArray());
60 IntDecoder decoder = new DGapIntDecoder(new NOnesIntDecoder(3));
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());
77 assertEquals("End of stream not reached", IntDecoder.EOS, decoder.decode());