/*
 * Copyright (c) 2013-2015 Cinchapi Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.cinchapi.concourse.util;

import java.nio.ByteBuffer;
import java.util.List;

import org.junit.Assert;
import org.junit.Test;

import com.cinchapi.concourse.server.model.PrimaryKey;
import com.cinchapi.concourse.server.model.Text;
import com.cinchapi.concourse.server.model.Value;
import com.cinchapi.concourse.test.ConcourseBaseTest;
import com.cinchapi.concourse.util.Convert;
import com.cinchapi.concourse.util.TArrays;
import com.cinchapi.concourse.util.TestData;
import com.google.common.collect.Lists;

/**
 * Unit tests for the {@link TArrays} class.
 * 
 * @author Jeff Nelson
 */
public class TArraysTest extends ConcourseBaseTest {

    @Test
    public void testConsistentHashing() {
        // Test that the byte buffer that is returned is consistent from JVM
        // session to JVM (e.g. it depends on persistent data).
        List<Integer> bytes = Lists.newArrayList(0,1,-116,-58,-22,32,-65,21,0,67,101,-107,90,17,84,-119,0,0,0,1,-55,19,-84,-27);
        Object[] data = { Text.wrap("foo"),
                Value.wrap(Convert.javaToThrift("bar")), PrimaryKey.wrap(1) };
        ByteBuffer buf = TArrays.hash(data);
        System.out.println(buf);
        for (int i = 0; i < buf.capacity(); i++) {
            Assert.assertEquals(buf.get(), bytes.get(i).byteValue());
        }
    }
    
    @Test
    public void testEqualObjectsHaveEqualHash(){
        Object[] data = {TestData.getText(), TestData.getValue(), TestData.getPrimaryKey()};
        ByteBuffer a = TArrays.hash(data);
        ByteBuffer b = TArrays.hash(data);
        Assert.assertEquals(a, b);
    }
    
}

@@ -39,16 +39,17 @@
  Inc.%0A *
+ 
 %0A * Lice
@@ -225,13 +225,12 @@
 t%0A *
+ 
 %0A *
-  
  htt
@@ -271,16 +271,17 @@
 E-2.0%0A *
+ 
 %0A * Unle
@@ -1501,83 +1501,138 @@
 t(0,
+ 
 1,
+ 
 -116,
+ 
 -58,
--22,32,-65,21,
+ -63, -90, 58,%0A                -104, 
 0,
+ 
 67,
+ 
 101,
+ 
 -107,
-90,17,84,-119,
+ 115, 59, 73, 102, 
 0,
+ 
 0,
+ 
 0,
+ 
 1,
--55,19,-84,-27
+ -39, 33,%0A                58, 40
 );%0A 
@@ -1968,21 +1968,17 @@
 %7D%0A    %7D%0A
-    
 %0A
+
     @Tes
@@ -2026,16 +2026,17 @@
 alHash()
+ 
 %7B%0A      
@@ -2054,16 +2054,17 @@
 data = %7B
+ 
 TestData
@@ -2095,16 +2095,32 @@
 Value(),
+%0A               
  TestDat
@@ -2136,16 +2136,17 @@
 aryKey()
+ 
 %7D;%0A     
@@ -2267,15 +2267,11 @@
 ;%0A    %7D%0A
-    
 %0A%7D%0A

fix TArraysTest