

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;


public class ArrazTest {

    private Arraz testArraz;
    private OddEven oddEven1;
    private MaxMin maxMin;
    private int[] arr1;
    private int[] arr2;
    private double[] double1;
    private double[] double2;

    @Before
    public void before() {
        arr1 = new int[]{5, 10, 3, 29, 100};
        arr2 = new int[]{2, 7, 432, 89};
        double1 = new double[] {1.0, 0.5, 3.6, 38.4, 17.3, 62.0, 9.0, 3.375, 0, 3.14159};
        double2 =  new double[]{6.0, 2.897, 3.1, 654.3, 5.21, 78.9};
        testArraz = new Arraz();
        oddEven1 = new OddEven(3, 2);
        maxMin = new MaxMin(100,3);
    }

    @Test
    public void test1SumValuesOfArray1() {
        int expected = 147;
        int actual = testArraz.sumValuesOfArray(arr1);

         Assert.assertEquals(expected, actual);
    }

    @Test
    public void test2SumValuesOfArray2(){
        int expected = 530;
        int actual = testArraz.sumValuesOfArray(arr2);

        Assert.assertEquals(expected, actual);
    }

    @Test
    public void testSumDoublesOfArray1(){
        double expected =138.31659;
        double actual = testArraz.sumDoublesOfArray(double1);

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

    @Test
    public void testSumDoublesOfArray2(){
        double expected = 0;
        double actual = testArraz.sumDoublesOfArray(new double[]{0.0,0.0});

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

    @Test
    public void testAverageOfArray1(){
        int expected = 29;
        int actual = testArraz.averageOfArray(arr1);

        Assert.assertEquals(expected, actual);
    }

    @Test
    public void testAverageOfArray2(){
        int expected = 132;
        int actual = testArraz.averageOfArray(arr2);

        Assert.assertEquals(expected, actual);
    }

    @Test
    public void testDoubleAverageOfArray1(){
        double expected = 13.831659;
        double actual = testArraz.doubleAverageOfArray(double1);

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

    @Test
    public void testDoubleAverageOfArray2(){
        double expected = 0;
        double actual = testArraz.doubleAverageOfArray(new double[]{0.0, 0.0});

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

    @Test
    public void testContainsValue1(){
        boolean actual = testArraz.containsValue(arr1, 29);
        Assert.assertTrue(actual);
    }

    @Test
    public void testContainsValue2(){
        boolean actual = testArraz.containsValue(arr1, 50000);
        Assert.assertFalse(actual);
    }

    @Test
    public void testReverseArray1(){
        int[] expected =new int[]{100, 29, 3, 10, 5};
        int[] actual = testArraz.reverseArray(arr1);

        Assert.assertArrayEquals(expected, actual);
    }

    @Test
    public void testReverseArray2(){
        int[] expected = arr1;
        int[] actual = testArraz.reverseArray(arr1);

        Assert.assertFalse(Arrays.equals(expected, actual));
    }

    @Test
    public void testOddEvens1(){
        OddEven actual = testArraz.oddEvens(arr1);
        Assert.assertEquals(oddEven1.getOdd(), actual.getOdd());
    }

    @Test
    public void testOddEvens2(){
        OddEven actual = testArraz.oddEvens(arr1);
        Assert.assertEquals(oddEven1.getEven(), actual.getEven());
    }

    @Test
    public void testFindIndexOf1(){
        int expected = 3;
        int actual = testArraz.getIndexOf(arr1, 29);

        Assert.assertEquals(expected, actual);
    }

    @Test
    public void testFindIndexOf2(){
        int expected = -1;
        int actual = testArraz.getIndexOf(arr1, 500);

        Assert.assertEquals(expected,actual);
    }

    @Test
    public void testCopyArrayByIterator1(){
        Integer[] expected = new Integer[]{1,2,3,4,5};
        Integer[] actual = testArraz.copyArrayByIterator(expected);

        Assert.assertArrayEquals(expected, actual);
    }

    @Test
    public void testCopyArrayByIterator2(){
        Integer[] expected = new Integer[]{10, 3, 5, 43};
        Integer[] actual = testArraz.copyArrayByIterator(expected);

        Assert.assertArrayEquals(expected, actual);
    }

    @Test
    public void testCopyArrayByLoop1(){
        int[] expected = arr1;
        int[] actual = testArraz.copyArrayByLoop(arr1);

        Assert.assertArrayEquals(expected, actual);
    }

    @Test
    public void testCopyArrayByLoop2(){
        Assert.assertFalse(Arrays.equals(arr1, testArraz.copyArrayByLoop(arr2)));
    }

    @Test
    public void testRemoveElementFromArray1(){
        int[] expected = new int[]{5, 10, 29, 100};
        int[] actual = testArraz.removeElementFromArray(arr1, 3);

        Assert.assertArrayEquals(expected, actual);
    }

    @Test
    public void testRemoveElementFromArray2(){
        int[] expected = new int[]{2, 7, 89};
        int[] actual = testArraz.removeElementFromArray(arr2, 432);

        Assert.assertArrayEquals(expected, actual);
    }

    @Test
    public void testInsertArrayAt1(){
        int[] expected = new int[]{5, 10, 3, 17, 29, 100};
        int[] actual = testArraz.insertArrayAt(arr1, 3, 17);
        System.out.println(Arrays.toString(actual));

        Assert.assertArrayEquals(expected, actual);
    }

    @Test
    public void testInsertArrayAt2(){
        int[] expected =  new int[]{2, 6, 7, 432, 89};
        int[] actual = testArraz.insertArrayAt(arr2, 1, 6);
        System.out.println(Arrays.toString(actual));

        Assert.assertArrayEquals(expected, actual);
    }

    @Test
    public void testFindMaxMinOfArray1(){
        Assert.assertEquals(maxMin.getMax(), testArraz.findMaxMinOfArray(arr1).getMax());
    }

    @Test
    public void testFindMaxMinOfArray2(){
        Assert.assertEquals(maxMin.getMin(), testArraz.findMaxMinOfArray(arr1).getMin());
    }

    @Test
    public void testRemoveDupesFromArray1(){
        Integer[] array1 = new Integer[]{1,3 ,4, 3, 7, 7, 10};
        Integer[] expected = new Integer[]{1, 3, 4, 7, 10};
        Integer[] actual = testArraz.removeDupesFromArray(array1);
        System.out.println(Arrays.toString(actual));

        Assert.assertArrayEquals(expected, actual);
    }

    @Test
    public void testRemoveDupesFromArray2(){
        Integer[] array1 = new Integer[]{5, 1, 5, 5, 5 ,5};
        Integer[] expected = new Integer[]{5, 1};
        Integer[] actual = testArraz.removeDupesFromArray(array1);
        System.out.println(Arrays.toString(actual));

        Assert.assertArrayEquals(expected, actual);
    }

    @Test
    public void testFind2ndLargestFromArray1(){
        Double expected = 99.3;
        Double[] doubleArr = new Double[]{10.4, 99.3, 89.45, 23.0, 1.1, 199.4, 199.4};
        Double actual = testArraz.find2ndLargestValueFromArray(doubleArr);

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

    @Test
    public void testFind2ndLargestFromArray2(){
        Double expected = 3.149;
        Double[] doubleArr = new Double[]{3.14, 3.14, 3.14, 3.14, 54.9};
        Double actual = testArraz.find2ndLargestValueFromArray(doubleArr);

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

    @Test
    public void testMakeMeAnArrayListFromArray1(){
        List<Integer> expected= new ArrayList<>();
        expected.add(5);
        expected.add(4);
        expected.add(3);
        Integer[] array = new Integer[]{5, 4, 3};
        List<Integer> actual = testArraz.makeMeAnArrayListFromArray(array);

        Assert.assertEquals(expected, actual);
    }

    @Test
    public void testMakeMeAnArrayListFromArray2(){
        List<Integer> expected = new ArrayList<>();
        expected.add(100);
        expected.add(37);
        expected.add(10);
        expected.add(67);
        Integer[] array = new Integer[]{100, 37, 10, 67};
        List<Integer> actual = testArraz.makeMeAnArrayListFromArray(array);

        Assert.assertEquals(expected, actual);
    }

    @Test
    public void testMakeMeAnArrayFromArrayList1(){
        Integer[] expected = new Integer[]{10, 7, 23, 50};
        List<Integer> list = new ArrayList<>();
        list.add(10);
        list.add(7);
        list.add(23);
        list.add(50);
        Integer[] actual = testArraz.makeMeAnArrayFromArrayList(list);

        Assert.assertArrayEquals(expected, actual);
    }

    @Test
    public void testMakeMeAnArrayFromArrayList2(){
        Integer[] expected = new Integer[]{43, 19, 99, 6};
        List<Integer> list = new ArrayList<>();
        list.add(43);
        list.add(19);
        list.add(99);
        list.add(6);
        Integer[] actual = testArraz.makeMeAnArrayFromArrayList(list);

        Assert.assertArrayEquals(expected, actual);
    }


    @Test
    public void testCheck2ArraysForEqual1(){
        int[] expected = new int[]{5, 10, 3, 29, 100};
        Assert.assertTrue(testArraz.check2ArraysForEqual(arr1, expected));
    }

    @Test
    public void testCheck2ArraysForEqual2(){
        int[] expected = new int[]{100, 900, 1, 32};
        Assert.assertFalse(testArraz.check2ArraysForEqual(arr1, expected));
    }

    @Test
    public void testAverageArrayWithoutMaxMin(){
        double expected = 14.0;
        double actual = testArraz.averageArrayWithoutMaxMin(arr1);

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

    @Test
    public void testAverageArrayWithoutMaxMin2(){
        double expected = 48;
        double actual = testArraz.averageArrayWithoutMaxMin(arr2);
        System.out.println(actual);

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

    @Test
    public void testArrayHas65and771(){
        Integer[] array = new Integer[]{65, 10, 34, 7, 77, 89};
        Assert.assertTrue(testArraz.arrayHas65and77(array));
    }

    @Test
    public void testArrayHas65and772(){
        Integer[] array = new Integer[]{3, 1, 9999, 5, 44};
        Assert.assertFalse(testArraz.arrayHas65and77(array));
    }

    @Test
    public void testTheTotalOfTenIs301() {
        Integer[] array = new Integer[]{10, 4, 3, 10, 56, 10};
        Assert.assertTrue(testArraz.theTotalOfTenIs30(array));
    }

    @Test
    public void testTheTotalOfTenIs302(){
        Integer[] array = new Integer[]{10, 98, 2, 34,10};
        Assert.assertFalse(testArraz.theTotalOfTenIs30(array));
    }

    @Test
    public void testMin2Array1(){
        Integer[] expected = new Integer[]{3, 5};
        Integer[] actual = testArraz.min2Array(new Integer[]{100, 54, 10, 78, 10, 5, 3});

        Assert.assertArrayEquals(expected, actual);
    }

    @Test
    public void testMin2Array(){
        Integer[] expected = new Integer[]{1, 10};
        Integer[] actual = testArraz.min2Array(new Integer[]{1,1,1,1,10});

        Assert.assertArrayEquals(expected, actual);
    }

    @Test
    public void testReverseCopy1(){
        int[] expected = new int[]{100, 29, 3, 10, 5};
        int[] actual = testArraz.reverseCopy(arr1);

        Assert.assertArrayEquals(expected,actual);
    }

    @Test
    public void testReverseCopy2(){
        int[] expected = new int[]{89, 432, 7, 2};
        int[] actual = testArraz.reverseCopy(arr2);

        Assert.assertArrayEquals(expected, actual);
    }

    @Test
    public void testRemoveLastItemCopy1(){
        int[] expected = new int[]{5, 10, 3, 29};
        int[] actual = testArraz.removeLastItemCopy(arr1);

        Assert.assertArrayEquals(expected, actual);
    }

    @Test
    public void testRemoveLastItemCopy2(){
        int[] expected =  new int[]{2, 7, 432};
        int[] actual = testArraz.removeLastItemCopy(arr2);

        Assert.assertArrayEquals(expected, actual);
    }

    @Test
    public void testRemoveFirstItemCopy1(){
        int[] expected = new int[]{7, 432, 89};
        int[] actual = testArraz.removeFirstItemCopy(arr2);

        Assert.assertArrayEquals(expected, actual);
    }

    @Test
    public void testRemoveFirstItemCopy2(){
        int[] expected = new int[]{10, 3, 29, 100};
        int[] actual = testArraz.removeFirstItemCopy(arr1);

        Assert.assertArrayEquals(expected, actual);
    }

    @Test
    public void testInsertStartCopy1(){
        int[] expected = new int[]{4, 5, 10, 3, 29, 100};
        int[] actual = testArraz.insertStartCopy(arr1, 4);

        Assert.assertArrayEquals(expected, actual);
    }

    @Test
    public void testInsertStartCopy2(){
        int[] expected = new int[]{56, 2, 7, 432, 89};
        int[] actual = testArraz.insertStartCopy(arr2, 56);

        Assert.assertArrayEquals(expected, actual);
    }

    @Test
    public void testInsertEndCopy1(){
        Integer[] expected = new Integer[]{2, 7, 432, 89, 9};
        Integer[] actual = testArraz.insertEndCopy(new Integer[]{2, 7, 432, 89}, 9);

        Assert.assertArrayEquals(expected, actual);
    }

    @Test
    public void testInsertEndCopy2(){
        Integer[] expected = new Integer[]{5, 10, 3, 29, 100, 90};
        Integer[] actual = testArraz.insertEndCopy(new Integer[]{5, 10, 3, 29, 100}, 90);
        System.out.println(Arrays.toString(actual));

        Assert.assertArrayEquals(expected, actual);
    }
}