package org.jtheque.utils.tests;

/*
 * Copyright JTheque (Baptiste Wicht)
 *
 * 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.
 */

import org.jtheque.utils.bean.Version;
import org.jtheque.utils.collections.ArrayUtils;

import org.junit.Test;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

/**
 * A TestCase to test the ArrayUtils class.
 *
 * @author Baptiste Wicht
 */
public class ArrayUtilsTest {
    /**
     * Test the indexOf method.
     */
    @Test
    public void testIndexOf() {
        Object[] objects = {"Tests", 6.0, 4, Version.get("1.2")};

        assertTrue(ArrayUtils.indexOf(objects[1], objects) == 1);
        assertTrue(ArrayUtils.indexOf(objects[3], objects) == 3);
        assertTrue(ArrayUtils.indexOf("Bonjour", objects) == -1);
        assertTrue(ArrayUtils.indexOf(Version.get("1.2"), objects) == -1);
    }

    /**
     * Test the reverse method.
     */
    @Test
    public void testReverseObjectArray() {
        Object[] array = {"Tests", 6.0, 4, Version.get("1.2")};
        List<Object> list = Arrays.<Object>asList("Tests", 6.0, 4, Version.get("1.2"));

        ArrayUtils.reverse(array);
        Collections.reverse(list);

        for (int i = 0; i < array.length; i++) {
            assertTrue(array[i].equals(list.get(i)));
        }
    }

    /**
     * Test the reverse method.
     */
    @Test
    public void testReverseIntArray() {
        int[] array = {1, 100, 67, 34, 0, 44};
        List<Integer> list = Arrays.asList(1, 100, 67, 34, 0, 44);

        ArrayUtils.reverse(array);
        Collections.reverse(list);

        for (int i = 0; i < array.length; i++) {
            assertTrue(array[i] == list.get(i));
        }
    }

    @Test
    public void isEmpty() {
        Object[] a1 = new Object[]{};
        Object[] a2 = {null};
        Object[] a3 = {"test"};

        assertTrue(ArrayUtils.isEmpty(a1));
        assertTrue(ArrayUtils.isEmpty(a2));
        assertFalse(ArrayUtils.isEmpty(a3));
    }

    @Test
    public void copyOf() {
        String[] toCopy = {"Big Show", "The Undertaker"};
        String[] copy = ArrayUtils.copyOf(toCopy);

        assertFalse(copy == toCopy);
        assertTrue(copy[0].equals(toCopy[0]));
        assertTrue(copy[1].equals(toCopy[1]));
    }
}

@@ -854,62 +854,9 @@
 ert.
-assertFalse;%0Aimport static org.junit.Assert.assertTrue
+*
 ;%0A%0A/
@@ -1128,37 +1128,42 @@
 %0A%0A        assert
-True(
+Equals(1, 
 ArrayUtils.index
@@ -1189,13 +1189,8 @@
 cts)
- == 1
 );%0A 
@@ -1194,37 +1194,42 @@
 ;%0A        assert
-True(
+Equals(3, 
 ArrayUtils.index
@@ -1255,13 +1255,8 @@
 cts)
- == 3
 );%0A 
@@ -1260,37 +1260,43 @@
 ;%0A        assert
-True(
+Equals(-1, 
 ArrayUtils.index
@@ -1313,30 +1313,24 @@
 r%22, objects)
- == -1
 );%0A        a
@@ -1326,37 +1326,42 @@
 ;%0A        assert
-True(
+Equals(3, 
 ArrayUtils.index
@@ -1395,14 +1395,8 @@
 cts)
- == -1
 );%0A 
@@ -1785,36 +1785,38 @@
           assert
-True
+Equals
 (array%5Bi%5D.equals
@@ -1808,24 +1808,18 @@
 array%5Bi%5D
-.equals(
+, 
 list.get
@@ -1822,17 +1822,16 @@
 .get(i))
-)
 ;%0A      
@@ -2196,21 +2196,33 @@
 sert
-True(
+Equals((Integer) 
 array%5Bi%5D
  == 
@@ -2217,19 +2217,17 @@
 array%5Bi%5D
- ==
+,
  list.ge
@@ -2694,21 +2694,21 @@
 sert
-Fals
+NotSam
 e(copy
- ==
+,
  toC
@@ -2731,20 +2731,22 @@
 sert
-True
+Equals
 (copy%5B0%5D
 .equ
@@ -2741,24 +2741,18 @@
 (copy%5B0%5D
-.equals(
+, 
 toCopy%5B0
@@ -2753,17 +2753,16 @@
 Copy%5B0%5D)
-)
 ;%0A      
@@ -2773,20 +2773,22 @@
 sert
-True
+Equals
 (copy%5B1%5D
 .equ
@@ -2787,16 +2787,10 @@
 y%5B1%5D
-.equals(
+, 
 toCo
@@ -2795,17 +2795,16 @@
 Copy%5B1%5D)
-)
 ;%0A    %7D%0A

Correct the method to take in account the unicity of Version instance