Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Licensed to the Apache Software Foundation (ASF) under one or more
0003  * contributor license agreements.  See the NOTICE file distributed with
0004  * this work for additional information regarding copyright ownership.
0005  * The ASF licenses this file to You under the Apache License, Version 2.0
0006  * (the "License"); you may not use this file except in compliance with
0007  * the License.  You may obtain a copy of the License at
0008  *
0009  *    http://www.apache.org/licenses/LICENSE-2.0
0010  *
0011  * Unless required by applicable law or agreed to in writing, software
0012  * distributed under the License is distributed on an "AS IS" BASIS,
0013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0014  * See the License for the specific language governing permissions and
0015  * limitations under the License.
0016  */
0017 
0018 package org.apache.spark.util.kvstore;
0019 
0020 import org.junit.Test;
0021 import static org.junit.Assert.*;
0022 
0023 public class ArrayWrappersSuite {
0024 
0025   @Test
0026   public void testGenericArrayKey() {
0027    byte[] b1 = new byte[] { 0x01, 0x02, 0x03 };
0028    byte[] b2 = new byte[] { 0x01, 0x02 };
0029    int[] i1 = new int[] { 1, 2, 3 };
0030    int[] i2 = new int[] { 1, 2 };
0031    String[] s1 = new String[] { "1", "2", "3" };
0032    String[] s2 = new String[] { "1", "2" };
0033 
0034    assertEquals(ArrayWrappers.forArray(b1), ArrayWrappers.forArray(b1));
0035    assertNotEquals(ArrayWrappers.forArray(b1), ArrayWrappers.forArray(b2));
0036    assertNotEquals(ArrayWrappers.forArray(b1), ArrayWrappers.forArray(i1));
0037    assertNotEquals(ArrayWrappers.forArray(b1), ArrayWrappers.forArray(s1));
0038 
0039    assertEquals(ArrayWrappers.forArray(i1), ArrayWrappers.forArray(i1));
0040    assertNotEquals(ArrayWrappers.forArray(i1), ArrayWrappers.forArray(i2));
0041    assertNotEquals(ArrayWrappers.forArray(i1), ArrayWrappers.forArray(b1));
0042    assertNotEquals(ArrayWrappers.forArray(i1), ArrayWrappers.forArray(s1));
0043 
0044    assertEquals(ArrayWrappers.forArray(s1), ArrayWrappers.forArray(s1));
0045    assertNotEquals(ArrayWrappers.forArray(s1), ArrayWrappers.forArray(s2));
0046    assertNotEquals(ArrayWrappers.forArray(s1), ArrayWrappers.forArray(b1));
0047    assertNotEquals(ArrayWrappers.forArray(s1), ArrayWrappers.forArray(i1));
0048 
0049    assertEquals(0, ArrayWrappers.forArray(b1).compareTo(ArrayWrappers.forArray(b1)));
0050    assertTrue(ArrayWrappers.forArray(b1).compareTo(ArrayWrappers.forArray(b2)) > 0);
0051 
0052    assertEquals(0, ArrayWrappers.forArray(i1).compareTo(ArrayWrappers.forArray(i1)));
0053    assertTrue(ArrayWrappers.forArray(i1).compareTo(ArrayWrappers.forArray(i2)) > 0);
0054 
0055    assertEquals(0, ArrayWrappers.forArray(s1).compareTo(ArrayWrappers.forArray(s1)));
0056    assertTrue(ArrayWrappers.forArray(s1).compareTo(ArrayWrappers.forArray(s2)) > 0);
0057   }
0058 
0059 }