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.BooleanArrayComparator;
26  import org.junit.Test;
27  
28  
29  /**
30   * Test the BooleanArrayComparator class
31   * 
32   * @author <a href="mailto:labs@labs.apache.org">Mavibot labs Project</a>
33   */
34  public class BooleanArrayComparatorTest
35  {
36      @Test
37      public void testBooleanArrayComparator()
38      {
39          BooleanArrayComparator comparator = new BooleanArrayComparator();
40  
41          assertEquals( 0, comparator.compare( null, null ) );
42  
43          boolean[] b1 = new boolean[]
44              { true, true, true };
45          boolean[] b2 = new boolean[]
46              { true, true, false };
47          boolean[] b3 = new boolean[]
48              { true, false, true };
49          boolean[] b4 = new boolean[]
50              { false, true, true };
51          boolean[] b5 = new boolean[]
52              { true, true };
53  
54          // 0
55          assertEquals( 0, comparator.compare( null, null ) );
56          assertEquals( 0, comparator.compare( new boolean[]
57              {}, new boolean[]
58              {} ) );
59          assertEquals( 0, comparator.compare( b1, b1 ) );
60  
61          // -1
62          assertEquals( -1, comparator.compare( null, new boolean[]
63              {} ) );
64          assertEquals( -1, comparator.compare( null, b1 ) );
65          assertEquals( -1, comparator.compare( new boolean[]
66              {}, b1 ) );
67          assertEquals( -1, comparator.compare( new boolean[]
68              {}, b4 ) );
69          assertEquals( -1, comparator.compare( b5, b1 ) );
70          assertEquals( -1, comparator.compare( b5, b3 ) );
71  
72          // 1
73          assertEquals( 1, comparator.compare( new boolean[]
74              {}, null ) );
75          assertEquals( 1, comparator.compare( b1, null ) );
76          assertEquals( 1, comparator.compare( b1, new boolean[]
77              {} ) );
78          assertEquals( 1, comparator.compare( b1, b2 ) );
79          assertEquals( 1, comparator.compare( b1, b3 ) );
80          assertEquals( 1, comparator.compare( b1, b4 ) );
81          assertEquals( 1, comparator.compare( b1, b5 ) );
82      }
83  }