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.junit.Test;
26  
27  
28  /**
29   * Test the LongArrayComparator class
30   *
31   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
32   */
33  public class LongArrayComparatorTest
34  {
35      @Test
36      public void testLongArrayComparator()
37      {
38          LongArrayComparator comparator = LongArrayComparator.INSTANCE;
39  
40          // Check equality
41          assertEquals( 0, comparator.compare( null, null ) );
42          assertEquals( 0, comparator.compare( new long[]
43              {}, new long[]
44              {} ) );
45          assertEquals( 0, comparator.compare( new long[]
46              { 1L, 2L }, new long[]
47              { 1L, 2L } ) );
48  
49          // The first long[] is > the second
50          assertEquals( 1, comparator.compare( new long[]
51              {}, null ) );
52          assertEquals( 1, comparator.compare( new long[]
53              { 1L }, null ) );
54          assertEquals( 1, comparator.compare( new long[]
55              { 1L, 2L }, new long[]
56              { 1L, 1L } ) );
57          assertEquals( 1, comparator.compare( new long[]
58              { 1L, 2L, 1L }, new long[]
59              { 1L, 2L } ) );
60          assertEquals( 1, comparator.compare( new long[]
61              { 1L, 2L }, new long[]
62              { 1L, 1L, 2L } ) );
63  
64          // The first long[] is < the second
65          assertEquals( -1, comparator.compare( null, new long[]
66              {} ) );
67          assertEquals( -1, comparator.compare( null, new long[]
68              { 1L, 2L } ) );
69          assertEquals( -1, comparator.compare( null, new long[]
70              { -1L, 2L } ) );
71          assertEquals( -1, comparator.compare( new long[]
72              {}, new long[]
73              { 1L, 2L } ) );
74          assertEquals( -1, comparator.compare( new long[]
75              {}, new long[]
76              { -1L, 2L } ) );
77          assertEquals( -1, comparator.compare( new long[]
78              { -1L, 1L }, new long[]
79              { 1L, 1L, 2L } ) );
80          long[] array = new long[3];
81          array[0] = 1L;
82          array[1] = 2L;
83          assertEquals( -1, comparator.compare( new long[]
84              { 1L, 2L }, array ) );
85      }
86  }