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

import java.util.ArrayList;
import java.util.List;

public class ArrazTest {

    private Arraz arraz = new Arraz();
    
    @Test
    public void testSumValuesOfArrayPostive(){
        int[] arr = new int[] {2, 3, 4, 5, 6, 7};

        int output = arraz.sumValuesOfArray(arr);

        int expected = 27;
        int actual = output;

        Assert.assertEquals(expected, actual);
    }

    @Test
    public void testSumValuesOfArrayNegative(){
        int[] arr = new int[] {2, -3, 4, 5, 6, 7};

        int output = arraz.sumValuesOfArray(arr);

        int expected = 21;
        int actual = output;

        Assert.assertEquals(expected, actual);
    }

    @Test
    public void testSumDoublesOfArrayPostive(){

        double[] arr = new double[] {2.5, .1, 4.2, .2};

        double actual = arraz.sumDoublesOfArray(arr);

        double expected  = 7;

        Assert.assertEquals(expected, actual, .00001);
    }

    @Test
    public void testSumDoublesOfArrayNegative(){

        double[] arr = new double[] {2.5, -.1, 4.2, .2};

        double actual = arraz.sumDoublesOfArray(arr);

        double expected  = 6.8;

        Assert.assertEquals(expected, actual, 0);
    }

    @Test
    public void testAverageOfArray1(){

        int[] arr = new int[] {1,1,1,1,1,1,1};

        int actual = arraz.averageOfArray(arr);

        int expected = 1;

        Assert.assertEquals(expected, actual);
    }

    @Test
    public void testAverageOfArray2(){

        int[] arr = new int[] {1,2,34,3,1,1,-122};

        int actual = arraz.averageOfArray(arr);

        int expected = -11;

        Assert.assertEquals(expected, actual);
    }

    @Test
    public void testDoubleAverageOfArray(){
        double[] arr = new double[] {1,1,1,1,1,1,1};

        double actual = arraz.doubleAverageOfArray(arr);

        double expected = 1;

        Assert.assertEquals(expected, actual, 0);
    }

    @Test
    public void testDoubleAverageOfArray2(){
        double[] arr = new double[] {2.4,23.4,43,12,5,2,54,.5};

        double actual = arraz.doubleAverageOfArray(arr);

        double expected = 17.7875;

        Assert.assertEquals(expected, actual, .001);
    }

    @Test
    public void testContainsValueFalse(){
        int[] arr = new int[] {1,2,3,4,5,6,7,8,9};

        boolean actual = arraz.containsValue(arr, 10);

        Assert.assertFalse(actual);
    }

    @Test
    public void testContainsValueTrue(){
        int[] arr = new int[] {1,2,3,4,5,6,7,8,9};

        boolean actual = arraz.containsValue(arr, 5);

        Assert.assertTrue(actual);
    }

    @Test
    public void testReverseArray1(){
        int[] arr = new int[] {9,8,7,6,5,4,3,2,1};

        Assert.assertArrayEquals(new int[] {1,2,3,4,5,6,7,8,9}, arraz.reverseArray(arr));
    }

    @Test
    public void testReverseArray2(){
        int[] arr = new int[] {2,4,53,2,4,56,64,2};

        int[] expected = new int[] {2,64,56,4,2,53,4,2};
        int[] actual = arraz.reverseArray(arr);

        Assert.assertArrayEquals(expected, actual);
    }

    @Test
    public void testOddEven1(){
        int[] arr = new int[] {2,2,2,2,2,1,1,1,1};

        String expected = "odds: 4 evens: 5";
        String actual = arraz.getOddEvensOfArray(arr);

        Assert.assertEquals(expected, actual);
    }

    @Test
    public void testOddEven2(){
        int[] arr = new int[] {1,2,3,4,5,6,7,8,9};

        String expected = "odds: 5 evens: 4";
        String actual = arraz.getOddEvensOfArray(arr);

        Assert.assertEquals(expected, actual);
    }

    @Test
    public void testFindIndexOf1(){
        int[] arr = new int[] {1,2,3,4,5,6,7,8,9};

        int expected = 1;
        int actual = arraz.findIndexOf(arr, 2);

        Assert.assertEquals(expected, actual);
    }

    @Test
    public void testFindIndexOf2(){
        int[] arr = new int[] {2,4,2,4,5,332,22,44,32,1};

        int expected = -1;
        int actual = arraz.findIndexOf(arr, -332);

        Assert.assertEquals(expected, actual);
    }

    @Test
    public void testCopyArrayByLoop1(){
        int[] arr = new int[] {1,2,3,4,5,6,7,8};

        int[] actual = arraz.copyArrayByLoop(arr);

        Assert.assertEquals(arr, actual);
        Assert.assertNotNull(actual);
    }

    @Test
    public void testCopyArrayByLoop2(){
        int[] arr = new int[] {1,2,3,5,543,322,235,4,6674,3};

        int[] actual = arraz.copyArrayByLoop(arr);

        Assert.assertArrayEquals(arr, actual);
        Assert.assertNotNull(actual);
    }

    @Test
    public void testCopyArrayByInterator1(){
        Integer[] arr = new Integer[] {1,2,3,4,5,6,7,8};

        Integer[] actual = arraz.copyArrayByInterator(arr);

        Assert.assertArrayEquals(arr, actual);
        Assert.assertNotNull(actual);
    }

    @Test
    public void testCopyArrayByInterator2(){
        Integer[] arr = new Integer[] {1,2,3,4,5,6,7,8};

        Integer[] actual = arraz.copyArrayByInterator(arr);

        Assert.assertArrayEquals(arr, actual);
        Assert.assertNotNull(actual);
    }

    @Test
    public void testRemoveElementFromArray1(){
        int[] arr = new int[]{1,2,3,4,5,6,7,8,9};

        int[] expected = new int[]{2,3,4,5,6,7,8,9};
        int[] actual = arraz.removeElementFromArray(arr, 1);

        Assert.assertArrayEquals(expected, actual);
    }

    @Test
    public void testRemoveElementFromArray2(){
        int[] arr = new int[]{0};

        int[] expected = new int[]{};
        int[] actual = arraz.removeElementFromArray(arr, 0);

        Assert.assertArrayEquals(expected, actual);
        Assert.assertEquals(0, actual.length);
    }

    @Test
    public void testRemoveElementFromArray3(){
        int[] arr = new int[]{};

        int[] expected = new int[]{-1};
        int[] actual = arraz.removeElementFromArray(arr, 1);

        Assert.assertArrayEquals(expected, actual);
    }

    @Test
    public void testInsertIntoArrayAt1(){
        int[] arr = new int[]{1,2,3,4,5,6,7,8,9};

        int[] expected = new int[]{1,2,3,4,5,6,7,8,9,10};
        int[] actual = arraz.InsertIntoArray(arr, 10);

        Assert.assertArrayEquals(expected, actual);
    }

    @Test
    public void testInsertIntoArrayAt2(){
        int[] arr = new int[]{};

        int[] expected = new int[]{10};
        int[] actual = arraz.InsertIntoArray(arr, 10);

        Assert.assertArrayEquals(expected, actual);
    }

    @Test
    public void testFindMaxMinOfArray1(){
        int[] arr = new int[]{1,2,3,4,5,6,7,8,9};

        String expected = "min: 1 max: 9";
        String actual = arraz.findMaxMinOfArray(arr);

        Assert.assertEquals(expected, actual);
    }

    @Test
    public void testFindMaxMinOfArray2(){
        int[] arr = new int[]{-23,3,5,6433,-54};

        String expected = "min: -54 max: 6433";
        String actual = arraz.findMaxMinOfArray(arr);

        Assert.assertEquals(expected, actual);
    }

    @Test
    public void testRemoveDupesFromArray1(){
        int[] arr = new int[]{2,3,44,4,4,65,2};

        int[] expected = new int[]{3,44,65};
        int[] actual = arraz.removeDupesFromArray(arr);

        Assert.assertArrayEquals(expected, actual);
    }

    @Test
    public void testRemoveDupesFromArray2(){
        int[] arr = new int[]{0,1,1,1,1,1,1,1};

        int[] expected = new int[]{0};
        int[] actual = arraz.removeDupesFromArray(arr);

        Assert.assertArrayEquals(expected, actual);
    }

    @Test
    public void testSort1(){
        int[] arr = new int[] {1,2,3,4,5,6,7,8,9};

        int[] expected  = new int[] {1,2,3,4,5,6,7,8,9};
        int[] actual = arraz.sort(arr);

        Assert.assertArrayEquals(expected, actual);
    }

    @Test
    public void testSort2(){
        int[] arr = new int[] {9,8,7,6,5,4,3,2,1};

        int[] expected  = new int[] {1,2,3,4,5,6,7,8,9};
        int[] actual = arraz.sort(arr);

        Assert.assertArrayEquals(expected, actual);
    }

    @Test
    public void testFind2ndLargestValueFromArray1(){
        int[] arr = new int[] {1,2,3,4,5,6,7,8,9};

        int expected =  8;
        int actual = arraz.find2ndLargestValueFromArray(arr);

        Assert.assertEquals(expected, actual);
    }

    @Test
    public void testFind2ndLargestValueFromArray2(){
        int[] arr = new int[] {2,334,523,232,78,45,8876,23};

        int expected =  523;
        int actual = arraz.find2ndLargestValueFromArray(arr);

        Assert.assertEquals(expected, actual);
    }

    @Test
    public void testMakeMeAnArrayListFromArray1(){
        int[] arr = new int[] {0};

        List actual = arraz.makeMeAnArrayListFromArray(arr);

        Assert.assertTrue(actual.contains(0));
    }

    @Test
    public void testMakeMeAnArrayListFromArra2(){
        int[] arr = new int[] {1,2,3,4,5};

        List actual = arraz.makeMeAnArrayListFromArray(arr);

        Assert.assertTrue(actual.contains(1));
        Assert.assertTrue(actual.contains(2));
        Assert.assertTrue(actual.contains(3));
        Assert.assertTrue(actual.contains(4));
        Assert.assertTrue(actual.contains(5));
    }

    @Test
    public void testMakeMeAnArrayFromArrayList1(){
        List<Integer> given = new ArrayList<Integer>();
        given.add(23);
        given.add(45);

        Object[] actual = arraz.makeMeAnArrayFromArrayList(given);

        Assert.assertEquals(2, actual.length);
    }

    @Test
    public void testMakeMeAnArrayFromArrayList2(){
        List<Integer> given = new ArrayList<Integer>();
        given.add(0);

        Object[] actual = arraz.makeMeAnArrayFromArrayList(given);

        Assert.assertEquals(1, actual.length);
    }

    @Test
    public void testCheck2ArraysForEqual1(){
        int[] arr1 = new int[] {1,2,3,4,5,6,7,8,9};
        int[] arr2 = new int[] {1,2,3,4,5,6,7,8,9};

        Assert.assertTrue(arraz.check2ArraysForEqual(arr1, arr2));
    }

    @Test
    public void testCheck2ArraysForEqual2(){
        int[] arr1 = new int[] {1,2,3,4,5,6,7,8,9};
        int[] arr2 = new int[] {1,2,3,5,4,6,7,8,9};

        Assert.assertFalse(arraz.check2ArraysForEqual(arr1, arr2));
    }

    @Test
    public void testCheck2ArraysForEqual3(){
        int[] arr1 = new int[] {1,2,3,4,5,6,7,8,9,10};
        int[] arr2 = new int[] {1,2,3,5,4,6,7,8,9};

        Assert.assertFalse(arraz.check2ArraysForEqual(arr1, arr2));
    }

    @Test
    public void testAverageArrayWithoutMaxMin1(){
        int[] arr = new int[] {100000,1,1,1,1,1,1,1,1,1,1,-1000};

        Assert.assertEquals(1, arraz.averageArrayWithoutMaxMin(arr));
    }

    @Test
    public void testAverageArrayWithoutMaxMin2(){
        int[] arr = new int[] {1,2,3,4,5,6,7,8,9};

        Assert.assertEquals(5, arraz.averageArrayWithoutMaxMin(arr));
    }

    @Test
    public void testArrayHas65and771(){
        int[] arr = new int[] {1,2,3,4,5,65,7,8,9};

        Assert.assertFalse(arraz.arrayHas65and77(arr));
    }

    @Test
    public void testArrayHas65and772(){
        int[] arr = new int[] {1,2,3,4,5,65,77,8,9};

        Assert.assertTrue(arraz.arrayHas65and77(arr));
    }

    @Test
    public void testTheTotalofTensIs301(){
        int[] arr = new int[] {10,10,10};

        Assert.assertTrue(arraz.theTotalofTensIs30(arr));
    }

    @Test
    public void testTheTotalofTensIs302(){
        int[] arr = new int[] {10,10};

        Assert.assertFalse(arraz.theTotalofTensIs30(arr));
    }

    @Test
    public void testGet2SmallestNumbers1(){
        int[] arr = new int[] {1,2,3,4,5,6,7,8,9};

        String expected = "smallest: 1, 2nd smallest: 2";
        Assert.assertEquals(expected, arraz.get2SmallestNumbers(arr));
    }

    @Test
    public void testGet2SmallestNumbers2(){
        int[] arr = new int[] {23,2,55,34664,223,554,22,-1};

        String expected = "smallest: -1, 2nd smallest: 2";
        Assert.assertEquals(expected, arraz.get2SmallestNumbers(arr));
    }

    @Test
    public void testMakeMeACopyPlease1(){
        int[] arr = new int[] {1,2,3,4,5,6,7,8,9};

        int[] expected = new int[] {9,8,7,6,5,4,3,2,1};
        Assert.assertArrayEquals(expected, arraz.makeMeACopyPlease(arr));
    }

    @Test
    public void testMakeMeACopyPlease2(){
        int[] arr = new int[] {2,3,542,12,55,3,2,45,67};

        int[] expected = new int[] {67,45,2,3,55,12,542,3,2};
        Assert.assertArrayEquals(expected, arraz.makeMeACopyPlease(arr));
    }

    @Test
    public void testRemoveLastItemAndCopy1(){
        int[] arr = new int[] {1,2,3,4,5,6,7,8,9};

        int[] expected = new int[] {1,2,3,4,5,6,7,8};

        Assert.assertArrayEquals(expected, arraz.removeLastItemAndCopy(arr));
    }

    @Test
    public void testRemoveLastItemAndCopy2(){
        int[] arr = new int[] {1,2,445,32,3,6,545326,34,6262,73,2634,358,12};

        int[] expected = new int[] {1,2,445,32,3,6,545326,34,6262,73,2634,358};

        Assert.assertArrayEquals(expected, arraz.removeLastItemAndCopy(arr));
    }

    @Test
    public void testRemoveFirstItemAndCopy1(){
        int[] arr = new int[] {1,2,3,4,5,6,7,8,9};

        int[] output = arraz.removeFirstItemAndCopy(arr);

        Assert.assertEquals(8, output.length);
        Assert.assertTrue(!arraz.containsValue(output, 1));
    }

    @Test
    public void testRemoveFirstItemAndCopy2(){
        int[] arr = new int[] {10};

        int[] output = arraz.removeFirstItemAndCopy(arr);

        Assert.assertEquals(0, output.length);
        Assert.assertTrue(!arraz.containsValue(output, 10));
    }

    @Test
    public void testInsertAtStartAndCopy1(){
        int[] arr = new int[] {1,2,3,4,5,6,7,8,9};

        int[] expected = new int[] {10,1,2,3,4,5,6,7,8,9};

        Assert.assertArrayEquals(expected, arraz.insertAtStartAndCopy(arr, 10));
    }

    @Test
    public void testInsertAtStartAndCopy2(){
        int[] arr = new int[] {};

        int[] expected = new int[] {10};

        Assert.assertArrayEquals(expected, arraz.insertAtStartAndCopy(arr, 10));
    }

    @Test
    public void testInsertAtEndAndCopy1(){
        int[] arr = new int[] {1,2,3,4,5,6,7,8,9};

        int[] expected = new int[] {1,2,3,4,5,6,7,8,9,10};

        Assert.assertArrayEquals(expected, arraz.insertAtEndAndCopy(arr, 10));
    }

    @Test
    public void testInsertAtEndAndCopy2(){
        int[] arr = new int[] {};

        int[] expected = new int[] {10};

        Assert.assertArrayEquals(expected, arraz.insertAtEndAndCopy(arr, 10));
    }

    @Test
    public void testSortArrayIntoEvensThenOdds1(){
        int[] arr = new int[] {4,5,102,6,-7,12,-32,92,8};

        int[] expected = new int[] {-32, 4, 6, 8, 12, 92, 102, -7, 5};

        Assert.assertArrayEquals(expected, arraz.sortArrayIntoEvensThenOdds(arr));
    }

    @Test
    public void testSortArrayIntoEvensThenOdds2(){
        int[] arr = new int[] {1,2,3,4,5,6,7,8,9};

        int[] expected = new int[] {2,4,6,8,1,3,5,7,9};

        Assert.assertArrayEquals(expected, arraz.sortArrayIntoEvensThenOdds(arr));
    }
}