pylucene 3.5.0-3
[pylucene.git] / lucene-java-3.5.0 / lucene / backwards / src / test / org / apache / lucene / util / TestVersionComparator.java
1 package org.apache.lucene.util;
2
3 /**
4  * Licensed to the Apache Software Foundation (ASF) under one or more
5  * contributor license agreements.  See the NOTICE file distributed with
6  * this work for additional information regarding copyright ownership.
7  * The ASF licenses this file to You under the Apache License, Version 2.0
8  * (the "License"); you may not use this file except in compliance with
9  * the License.  You may obtain a copy of the License at
10  *
11  *     http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19
20 import java.util.Comparator;
21
22 /**
23  * Tests for StringHelper.getVersionComparator
24  */
25 public class TestVersionComparator extends LuceneTestCase {
26   public void testVersions() {
27     Comparator<String> comp = StringHelper.getVersionComparator();
28     assertTrue(comp.compare("1", "2") < 0);
29     assertTrue(comp.compare("1", "1") == 0);
30     assertTrue(comp.compare("2", "1") > 0);
31     
32     assertTrue(comp.compare("1.1", "1") > 0);
33     assertTrue(comp.compare("1", "1.1") < 0);
34     assertTrue(comp.compare("1.1", "1.1") == 0);
35     
36     assertTrue(comp.compare("1.0", "1") == 0);
37     assertTrue(comp.compare("1", "1.0") == 0);
38     assertTrue(comp.compare("1.0.1", "1.0") > 0);
39     assertTrue(comp.compare("1.0", "1.0.1") < 0);
40     
41     assertTrue(comp.compare("1.02.003", "1.2.3.0") == 0);
42     assertTrue(comp.compare("1.2.3.0", "1.02.003") == 0);
43     
44     assertTrue(comp.compare("1.10", "1.9") > 0);
45     assertTrue(comp.compare("1.9", "1.10") < 0);
46     
47     assertTrue(comp.compare("0", "1.0") < 0);
48     assertTrue(comp.compare("00", "1.0") < 0);
49     assertTrue(comp.compare("-1.0", "1.0") < 0);
50     assertTrue(comp.compare("3.0", Integer.toString(Integer.MIN_VALUE)) > 0);
51   }
52 }