View Javadoc

1   /*
2    *  Licensed to the Apache Software Foundation (ASF) under one
3    *  or more contributor license agreements.  See the NOTICE file
4    *  distributed with this work for additional information
5    *  regarding copyright ownership.  The ASF licenses this file
6    *  to you under the Apache License, Version 2.0 (the
7    *  "License"); you may not use this file except in compliance
8    *  with the License.  You may obtain a copy of the License at
9    *
10   *    http://www.apache.org/licenses/LICENSE-2.0
11   *
12   *  Unless required by applicable law or agreed to in writing,
13   *  software distributed under the License is distributed on an
14   *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   *  KIND, either express or implied.  See the License for the
16   *  specific language governing permissions and limitations
17   *  under the License.
18   *
19   */
20  package org.apache.directory.mavibot.btree.comparator;
21  
22  
23  import static org.junit.Assert.assertEquals;
24  
25  import org.apache.directory.mavibot.btree.comparator.LongArrayComparator;
26  import org.junit.Test;
27  
28  
29  /**
30   * Test the LongArrayComparator class
31   * 
32   * @author <a href="mailto:labs@labs.apache.org">Mavibot labs Project</a>
33   */
34  public class LongArrayComparatorTest
35  {
36      @Test
37      public void testLongArrayComparator()
38      {
39          LongArrayComparator comparator = new LongArrayComparator();
40  
41          // Check equality
42          assertEquals( 0, comparator.compare( null, null ) );
43          assertEquals( 0, comparator.compare( new long[]
44              {}, new long[]
45              {} ) );
46          assertEquals( 0, comparator.compare( new long[]
47              { 1L, 2L }, new long[]
48              { 1L, 2L } ) );
49  
50          // The first long[] is > the second
51          assertEquals( 1, comparator.compare( new long[]
52              {}, null ) );
53          assertEquals( 1, comparator.compare( new long[]
54              { 1L }, null ) );
55          assertEquals( 1, comparator.compare( new long[]
56              { 1L, 2L }, new long[]
57              { 1L, 1L } ) );
58          assertEquals( 1, comparator.compare( new long[]
59              { 1L, 2L, 1L }, new long[]
60              { 1L, 2L } ) );
61          assertEquals( 1, comparator.compare( new long[]
62              { 1L, 2L }, new long[]
63              { 1L, 1L, 2L } ) );
64  
65          // The first long[] is < the second
66          assertEquals( -1, comparator.compare( null, new long[]
67              {} ) );
68          assertEquals( -1, comparator.compare( null, new long[]
69              { 1L, 2L } ) );
70          assertEquals( -1, comparator.compare( null, new long[]
71              { -1L, 2L } ) );
72          assertEquals( -1, comparator.compare( new long[]
73              {}, new long[]
74              { 1L, 2L } ) );
75          assertEquals( -1, comparator.compare( new long[]
76              {}, new long[]
77              { -1L, 2L } ) );
78          assertEquals( -1, comparator.compare( new long[]
79              { -1L, 1L }, new long[]
80              { 1L, 1L, 2L } ) );
81          long[] array = new long[3];
82          array[0] = 1L;
83          array[1] = 2L;
84          assertEquals( -1, comparator.compare( new long[]
85              { 1L, 2L }, array ) );
86      }
87  }