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

import javax.accessibility.AccessibleStateSet;

import java.util.ArrayList;
import java.util.Arrays;

import static org.junit.Assert.*;

public class ArrazTest {

    private int[] intArr = new int[]{1, 23, 10, 4, 5, 3};
    private double[] dbArr = new double[]{1.0, 2.0, 3.0, 4.0};
    Arraz arraz = new Arraz();


    @Test
    public void sumValuesOfArrayTest1() {
        int expected = 46;

        int actual = arraz.sumValuesOfArray(intArr);

        Assert.assertEquals(expected, actual);
    }

    @Test
    public void sumValuesOfArrayTest2() {
        int[] intArr2 = new int[]{10, 20, 30, 40};
        int expected = 100;

        int actual = arraz.sumValuesOfArray(intArr2);

        Assert.assertEquals(expected, actual);

    }

    @Test
    public void sumDoublesOfArrayTest1() {
        double expected = 10.0;

        double actual = arraz.sumDoublesOfArray(dbArr);

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

    @Test
    public void sumDoublesOfArrayTest2() {
        double[] dbArr2 = new double[]{10.5, 20.1, 30.0, 40.0};
        double expected = 100.6;

        double actual = arraz.sumDoublesOfArray(dbArr2);

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

    @Test
    public void averageOfArrayTest1() {
        int expected = 7;

        int actual = arraz.averageOfArray(intArr);

        Assert.assertEquals(expected, actual);
    }

    @Test
    public void averageOfArrayTest2() {
        int[] intArr2 = new int[]{10, 20, 30, 40};

        int expected = 25;

        int actual = arraz.averageOfArray(intArr2);

        Assert.assertEquals(expected, actual);
    }

    @Test
    public void averageDoubleOfArrayTest1() {
        double expected = 2.5;

        double actual = arraz.averageDoubleOfArray(dbArr);

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

    @Test
    public void averageDoubleOfArrayTest2() {
        double[] dbArr2 = new double[]{10.0, 20.0, 30.0, 40.0};

        double expected = 25.0;

        double actual = arraz.averageDoubleOfArray(dbArr2);

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

    @Test
    public void containsValueTest1() {
        Assert.assertTrue(arraz.containsValue(intArr, 23));
    }

    @Test
    public void containsValueTest2() {
        Assert.assertFalse(arraz.containsValue(intArr, 300));
    }

    @Test
    public void reverseArrayTest1() {
        int[] expected = new int[]{3, 5, 4, 10, 23, 1};

        int[] actual = arraz.reverseArray(intArr);

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

    @Test
    public void reverseArrayTest2() {

    }

    @Test
    public void getOddEvensOfArrayTest(){
        int[] testArr = new int[]{4, 2};
        int[] actual = arraz.getOddEvensOfArray(intArr);

        Assert.assertEquals(Arrays.toString(testArr), Arrays.toString(actual));
    }

    @Test
    public void findIndexOfTest() {
        Assert.assertEquals(3,arraz.findIndexOf(intArr, 4));
    }

    @Test
    public void findIndexOfTest2() {
        Assert.assertEquals(0,arraz.findIndexOf(intArr, 1));
    }

    @Test
    public void copyArrayByIteratorTest() {
        Integer[] intArr = new Integer[]{1, 23, 10, 4, 5, 3};

        Integer[] newArr = new Integer[intArr.length];
        arraz.copyArrayByIterator(intArr, newArr);

        Assert.assertTrue(Arrays.equals(intArr, newArr));
    }

    @Test
    public void copyArrayByLoopTest() {
        int[] newArr = new int[intArr.length];
        arraz.copyArrayByLoop(intArr, newArr);

        Assert.assertTrue(Arrays.equals(intArr, newArr));
    }

    @Test
    public void removeElementFromArrayTest() {
        int[] intArr2 = arraz.removeElementFromArray(intArr, 10);
        System.out.println(Arrays.toString(intArr2));
        Assert.assertFalse(arraz.containsValue(intArr2, 10));
    }

    @Test
    public void removeElementFromArrayTest2() {
        int[] intArr2 = arraz.removeElementFromArray(intArr, 23);
        System.out.println(Arrays.toString(intArr2));
        Assert.assertFalse(arraz.containsValue(intArr2, 23));
    }

    @Test
    public void insertIntoArrayAtTest() {
        int[] intArr2 = new int[]{1, 23, 10, 4, 5, 3};

        arraz.insertIntoArrayAt(intArr2, 20, 0);

        Assert.assertTrue(arraz.containsValue(intArr2, 20));
    }

    @Test
    public void insertIntoArrayAtTest2() {
        int[] intArr2 = new int[]{1, 23, 10, 4, 5, 3};

        arraz.insertIntoArrayAt(intArr2, -20, 4);

        Assert.assertTrue(arraz.containsValue(intArr2, -20));
    }

    @Test
    public void findMaxMinOfArrayTest() {
        int[] expected = new int[]{1, 23};

        int[] actual = arraz.findMaxMinOfArray(intArr);

        Assert.assertEquals(Arrays.toString(expected), Arrays.toString(actual));
    }


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

        Integer[] arr3 = arraz.removeDupeFromArray(arr);

        System.out.println(Arrays.toString(arr3));

        Assert.assertTrue(Arrays.equals(arr3, arr2));
    }


    @Test
    public void removeDupeFromArrayTest2() {
        Integer[] arr = new Integer[]{1, 10, 22, 1, 1, 2, 3, 4, 4, 5, 3, 22, 2, 10};
        Integer[] arr2 = new Integer[]{1, 2, 3, 4, 5, 10, 22};

        Integer[] arr3 = arraz.removeDupeFromArray(arr);

        System.out.println(Arrays.toString(arr3));

        Assert.assertTrue(Arrays.equals(arr3, arr2));
    }

    @Test
    public void find2ndLargestValueFromArrayTest() {
        double expected = 3.0;
        double actual = arraz.find2ndLargestValueFromArray(dbArr);

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

    @Test
    public void find2ndLargestValueFromArrayTest2() {
        double[] dbArr2 = new double[]{103.0, 22.0, 34.0, 4010.0};

        double expected = 103.0;
        double actual = arraz.find2ndLargestValueFromArray(dbArr2);

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

    @Test
    public void makeMeAnArrayListFromArrayTest() {
        Assert.assertTrue(arraz.makeMeAnArrayListFromArray(intArr).contains(10));
    }

    @Test
    public void makeMeAnArrayListFromArrayTest2() {
        Assert.assertTrue(arraz.makeMeAnArrayListFromArray(intArr).contains(1));
    }

    @Test
    public void makeMeAnArrayFromArrayListTest() {

    }

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

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

    @Test
    public void check2ArraysForEqualTest2() {
        int[] arr = new int[]{109, 1040, -2, 30, -64, 4, 5, 3};
        int[] arr2 = new int[]{109, 1040, -2, 30, -64, 4, 5, 3};

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

    @Test
    public void averageArrayWithoutMaxMinTest() {
        int expected = 5;

        int actual = arraz.averageArrayWithoutMaxMin(intArr);

        Assert.assertEquals(expected, actual);
    }

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

        int expected = 2;

        int actual = arraz.averageArrayWithoutMaxMin(arr);

        Assert.assertEquals(expected, actual);
    }

    @Test
    public void arrayHas65and77Test() {
        Assert.assertFalse(arraz.arrayHas65and77(intArr));
    }

    @Test
    public void arrayHas65and77Test2() {
        int[] arr = new int[]{109, 1040, -2, 65, -64, 4, 77, 3};


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

    @Test
    public void theTotalofTensIs30Test() {
        Assert.assertFalse(arraz.theTotalofTensIs30(intArr));
    }

    @Test
    public void theTotalofTensIs30Test2() {
        int[] arr = new int[]{10, 10, 10, 65, -10, 4, 77, 3};
        Assert.assertTrue(arraz.theTotalofTensIs30(arr));
    }


    @Test
    public void twoSmallestInArrayTest() {
        int[] expected = new int[]{1, 3};
        int[] actual = arraz.twoSmallestInArray(intArr);

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

    @Test
    public void makeMeACopyPleaseTest() {
        Integer[] arr = new Integer[]{1, 2, 3, 4, 5, 10, 22};
        Integer[] expected = new Integer[]{22, 10, 5, 4, 3, 2, 1};

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

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

    @Test
    public void makeMeACopyPleaseTest2() {
        Integer[] arr = new Integer[]{1, -42, 3, -4, 5, 10, 22};
        Integer[] expected = new Integer[]{22, 10, 5, -4, 3, -42, 1};

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

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

    @Test
    public void removeLastItemAndCopyTest() {
        Integer[] arr = new Integer[]{1, -42, 3, -4, 5, 10, 22};

        Integer[] expected = new Integer[]{1, -42, 3, -4, 5, 10};

        Integer[] actual = arraz.removeLastItemAndCopy(arr);
        Assert.assertTrue(Arrays.equals(expected, actual));
    }

    @Test
    public void removeLastItemAndCopyTest2() {
        Integer[] arr = new Integer[]{1, -42, 3, -4, 5, 10, 22, 1000, -32};

        Integer[] expected = new Integer[]{1, -42, 3, -4, 5, 10, 22, 1000};

        Integer[] actual = arraz.removeLastItemAndCopy(arr);
        Assert.assertTrue(Arrays.equals(expected, actual));
    }

    @Test
    public void removeFirstItemAndCopyTest() {
        Integer[] arr = new Integer[]{1, -42, 3, -4, 5, 10, 22, 1000, -32};

        Integer[] expected = new Integer[]{-42, 3, -4, 5, 10, 22, 1000, -32};

        Integer[] actual = arraz.removeFirstItemAndCopy(arr);
        Assert.assertTrue(Arrays.equals(expected, actual));
    }

    @Test
    public void removeFirstItemAndCopyTest2() {
        Integer[] arr = new Integer[]{-1, -42, 3, -4, 5, 10, 22, 1000, -32};

        Integer[] expected = new Integer[]{-42, 3, -4, 5, 10, 22, 1000, -32};

        Integer[] actual = arraz.removeFirstItemAndCopy(arr);
        Assert.assertTrue(Arrays.equals(expected, actual));
    }

    @Test
    public void insertAtStartAndCopyTest() {
        Integer[] arr = new Integer[]{-1, -42, 3, -4, 5, 10, 22, 1000, -32};

        Integer[] expected = new Integer[]{50, -1, -42, 3, -4, 5, 10, 22, 1000, -32};

        Integer[] actual = arraz.insertAtStartAndCopy(arr, 50);
        System.out.println(Arrays.toString(actual));
        Assert.assertTrue(Arrays.equals(expected, actual));
    }

    @Test
    public void insertAtStartAndCopyTest2() {
        Integer[] arr = new Integer[]{-1, -42, 3, -4, 5, 10, 22, 1000, -32};

        Integer[] expected = new Integer[]{-50, -1, -42, 3, -4, 5, 10, 22, 1000, -32};

        Integer[] actual = arraz.insertAtStartAndCopy(arr, -50);
        Assert.assertTrue(Arrays.equals(expected, actual));
    }

    @Test
    public void insertAtEndAndCopyTest() {
        Integer[] arr = new Integer[]{-1, -42, 3, -4, 5, 10, 22, 1000, -32};

        Integer[] expected = new Integer[]{-1, -42, 3, -4, 5, 10, 22, 1000, -32, -50};

        Integer[] actual = arraz.insertAtEndAndCopy(arr, -50);
        Assert.assertTrue(Arrays.equals(expected, actual));
    }

    @Test
    public void insertAtEndAndCopyTest2() {
        Integer[] arr = new Integer[]{-1, -42, 3, -4, 5, 10, 22, 1000, -32};

        Integer[] expected = new Integer[]{-1, -42, 3, -4, 5, 10, 22, 1000, -32, 73};

        Integer[] actual = arraz.insertAtEndAndCopy(arr, 73);
        Assert.assertTrue(Arrays.equals(expected, actual));
    }

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

        Integer[] expected = new Integer[]{2, 4, 10, 6};

        Integer[] actual = arraz.evensArray(arr);
        System.out.println(Arrays.toString(actual));
        Assert.assertTrue(Arrays.equals(expected, actual));

    }

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

        Integer[] expected = new Integer[]{1, 3, 5, 3};

        Integer[] actual = arraz.oddsArray(arr);
        System.out.println(Arrays.toString(actual));
        Assert.assertTrue(Arrays.equals(expected, actual));

    }

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

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

        Integer[] actual = arraz.mergeArrays(arr, arr2);
        System.out.println(Arrays.toString(actual));
        Assert.assertTrue(Arrays.equals(expected, actual));
    }
    @Test
    public void sortArrayIntoEvensThenOddstest() {
        Integer[] arr = new Integer[]{3, 2, 5, 6, 10, 11, 15};

        Integer[] expected = new Integer[]{2, 6, 10, 3, 5, 11, 15};

        Integer[] actual = arraz.sortArrayIntoEvensThenOdds(arr);
        System.out.println(Arrays.toString(arr));
        Assert.assertTrue(Arrays.equals(expected, actual));

    }
}