pylucene 3.5.0-3
[pylucene.git] / lucene-java-3.5.0 / lucene / backwards / src / test / org / apache / lucene / util / TestCharsRef.java
1 package org.apache.lucene.util;
2
3 import java.util.Arrays;
4
5 /**
6  * Licensed to the Apache Software Foundation (ASF) under one or more
7  * contributor license agreements.  See the NOTICE file distributed with
8  * this work for additional information regarding copyright ownership.
9  * The ASF licenses this file to You under the Apache License, Version 2.0
10  * (the "License"); you may not use this file except in compliance with
11  * the License.  You may obtain a copy of the License at
12  *
13  *     http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  */
21
22 public class TestCharsRef extends LuceneTestCase {
23   public void testUTF16InUTF8Order() {
24     final int numStrings = atLeast(1000);
25     BytesRef utf8[] = new BytesRef[numStrings];
26     CharsRef utf16[] = new CharsRef[numStrings];
27     
28     for (int i = 0; i < numStrings; i++) {
29       String s = _TestUtil.randomUnicodeString(random);
30       utf8[i] = new BytesRef(s);
31       utf16[i] = new CharsRef(s);
32     }
33     
34     Arrays.sort(utf8);
35     Arrays.sort(utf16, CharsRef.getUTF16SortedAsUTF8Comparator());
36     
37     for (int i = 0; i < numStrings; i++) {
38       assertEquals(utf8[i].utf8ToString(), utf16[i].toString());
39     }
40   }
41 }