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

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

import static org.junit.Assert.*;

public class ArrazTest {

    Arraz arraz = new Arraz();

    int[] arr = {2,2,2,2,2};
    int[] arr2 = {1,2,3,4,5};

    @Test
    public void test1sumValuesOfArray(){

        int expected = 10;
        int actual = arraz.sumValuesOfArray(arr);

        Assert.assertEquals(expected, actual);
    }


    @Test
    public void test2sumValuesOfArray(){

        int expected = 15;
        int actual = arraz.sumValuesOfArray(arr2);

        Assert.assertEquals(expected, actual);
    }

    double[] arr3 = {2.0,2.0,2.0,2.0,2.0};


    @Test
    public void test1DoublesOfArray(){

        double expected = 10.0;
        double actual = arraz.sumDoublesOfArray(arr3);

        Assert.assertEquals(expected, actual);
    }

    double[] arr4 = {1.5 , 2.5 , 3.0,4.75,5.25};

    @Test
    public void test2DoublesOfArray(){

        double expected = 17.0;
        double actual = arraz.sumDoublesOfArray(arr4);

        Assert.assertEquals(expected, actual);
    }

    @Test
    public void test1AverageOfArray(){

        int expected = 2;
        int actual = arraz.averageOfArray(arr);

        Assert.assertEquals(expected, actual);

    }

    @Test
    public void test2AverageOfArray(){

        int expected = 3;
        int actual = arraz.averageOfArray(arr2);

        Assert.assertEquals(expected, actual);

    }

    @Test
    public void test1DoubleAverageOfArray(){

        double expected = 2.0;
        double actual = arraz.doubleAverageOfArray(arr3);

        Assert.assertEquals(expected, actual);

    }

    @Test
    public void test2DoubleAverageOfArray(){

        double expected = (17.0 / 5.0);
        double actual = arraz.doubleAverageOfArray(arr4);

        Assert.assertEquals(expected, actual);

    }

    @Test
    public void test1ContainsValue(){
        int value = 4;

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

        Assert.assertFalse(actual);
    }

    @Test
    public void test2ContainsValue(){
        int value = 2;

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

        Assert.assertTrue(actual);
    }

    int[] array1 = {1,2,3,4,5};

    @Test
    public void test1ReverseArray(){

        int[] expected = {5,4,3,2,1};
        int[] actual = arraz.reverseArray(array1);

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

    int[] array2 = {10,2,4,7,2};

    @Test
    public void test2ReverseArray(){

        int[] expected = {2,7,4,2,10};
        int[] actual = arraz.reverseArray(array2);

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

    }



    //int[] array1 = {1,2,3,4,5};



    @Test
    public void testGetOddEvensOfArray(){
        Arraz.OddEven oe = arraz.new OddEven();

        int expected = 3;
        oe.getOddEvensOfArray(array1);

        Assert.assertEquals(expected, oe.getOdds(array1));

    }

    @Test
    public void test2GetOddEvensOfArray(){
        Arraz.OddEven oe = arraz.new OddEven();

        int expected = 2;
        oe.getOddEvensOfArray(array1);

        Assert.assertEquals(expected, oe.getEvens(array1));

    }

    @Test
    public void testFindIndexOf(){

        int value = 3;
        int expected = 2;
        int actual = arraz.findIndexOf(array1, value);

        Assert.assertEquals(expected, actual);

    }

    @Test
    public void test2FindIndexOf(){

        int value = 7;
        int expected = -1;
        int actual = arraz.findIndexOf(array1, value);

        Assert.assertEquals(expected, actual);

    }

    Integer[] array3 = {1,2,3,4,5};

    @Test
    public void testCopyArrayByIterator(){

        Integer[] expected = {1,2,3,4,5};
        Integer[] actual = arraz.copyArrayByIterator(array3);

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

    }

    Integer[] array4 = {1};
    @Test
    public void test2CopyArrayByIterator(){

        Integer[] expected = {1};
        Integer[] actual = arraz.copyArrayByIterator(array4);

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

    }

    @Test
    public void testCopyArrayByLoop(){

        Integer[] expected = {1,2,3,4,5};
        Integer[] actual = arraz.copyArrayByLoop(array3);

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

    }

    @Test
    public void test2CopyArrayByLoop(){
        Integer[] array3 = {-1};

        Integer[] expected = {-1};
        Integer[] actual = arraz.copyArrayByLoop(array3);

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

    }

    @Test
    public void testRemoveElementFromArray(){
        Integer[] array = {1,2,3,4,5};
        Integer value = 3;

        Integer[] expected = {1,2,4,5};
        Integer[] actual = arraz.removeElementFromArray(array, value);

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

    }

    @Test
    public void test2RemoveElementFromArray() {
        Integer[] array = {1};
        Integer value = 1;

        Integer[] expected = {};
        Integer[] actual = arraz.removeElementFromArray(array, value);

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

    }

    @Test
    public void testInsertIntoArrayAt() {
        int pos = 3;
        int value = 4;
        int[] array = {1,2,3,4,5};


        int[] expected = {1,2,4,3,4,5};
        int[] actual = arraz.insertIntoArray(array, pos, value);

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

    @Test
    public void test2InsertIntoArrayAt() {
        int pos = 1;
        int value = 4;
        int[] array = {1,2,3,4,5};


        int[] expected = {4,1,2,3,4,5};
        int[] actual = arraz.insertIntoArray(array, pos, value);

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

    @Test
    public void testFindMaxMinOfArray(){

        int[] array = {1,5,2,4,3};
        int expected = 5;

        Arraz arraz = new Arraz();
        Arraz.MaxMin mn = arraz.new MaxMin();

        arraz.findMaxMinOfArray(array);

        Assert.assertEquals(expected, arraz.findMaxMinOfArray(array).getMax());

    }

    @Test
    public void test2FindMaxMinOfArray(){

        int[] array = {1,5,2,-1,0};
        int expected = -1;

        Arraz arraz = new Arraz();
        Arraz.MaxMin mn = arraz.new MaxMin();


        Assert.assertEquals(expected, arraz.findMaxMinOfArray(array).getMin());

    }

    @Test
    public void testRemoveDupesFromArray(){

        Integer[] array = {1,2,3,2,4,4,5,6,7,7,8};

        Integer[] expected = {1,2,3,4,5,6,7,8};
        Integer[] actual = arraz.removeDupesFromArray(array);

        Assert.assertEquals(expected, actual);
    }

    @Test
    public void test2RemoveDupesFromArray(){

        Integer[] array = {1,1,1,1,1,1,1,1};

        Integer[] expected = {1};
        Integer[] actual = arraz.removeDupesFromArray(array);

        Assert.assertEquals(expected, actual);
    }

    @Test
    public void testFind2ndLargestValueFromArray(){

        Integer[] array = {1,2,3,4,5};

        Integer expected = 4;
        Integer actual = arraz.find2ndLargestValueFromArray(array);

        Assert.assertEquals(expected, actual);
    }

    @Test
    public void test2Find2ndLargestValueFromArray(){

        Integer[] array = {1};

        Integer expected = -1;
        Integer actual = arraz.find2ndLargestValueFromArray(array);

        Assert.assertEquals(expected, actual);
    }

    @Test
    public void testMakeMeAnArrayListFromArray(){
        Integer[] array = {1,2,3};
        ArrayList<Integer> al = new ArrayList<Integer>();
        al.add(1);
        al.add(2);
        al.add(3);

        Integer[] expected = {1,2,3};
        ArrayList<Integer> actual = arraz.makeMeAnArrayListFromArray(array);

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

    }

    @Test
    public void test2MakeMeAnArrayListFromArray(){
        Integer[] array = {1};
        ArrayList<Integer> al = new ArrayList<Integer>();
        al.add(1);

        Integer[] expected = {1};
        ArrayList<Integer> actual = arraz.makeMeAnArrayListFromArray(array);

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

    }

    @Test
    public void testMakeMeAnArrayFromArrayList(){

        ArrayList<Integer> al = new ArrayList<Integer>();
        al.add(1);
        al.add(2);
        al.add(3);

        Integer[] expected = {1,2,3};
        Integer[] actual = arraz.makeMeAnArrayFromArrayList(al);

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

    }

    @Test
    public void test2MakeMeAnArrayFromArrayList(){

        ArrayList<Integer> al = new ArrayList<Integer>();
        al.add(1);

        Integer[] expected = {1};
        Integer[] actual = arraz.makeMeAnArrayFromArrayList(al);

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

    }

    @Test
    public void testCheck2ArraysForEqual(){

        String[] str1 = {"Happy", "Happy", "Joy", "Joy"};
        String[] str2 = {"Happy", "Happy", "Joy", "Joy"};

        boolean actual = arraz.check2ArraysForEqual(str1, str2);

        Assert.assertTrue(actual);
    }

    @Test
    public void test2Check2ArraysForEqual(){

        String[] str1 = {"Happy", "Happy", "Joy", "Joy"};
        String[] str2 = {"Happy", "Happy", "Joy", "Joo"};

        boolean actual = arraz.check2ArraysForEqual(str1, str2);

        Assert.assertFalse(actual);
    }

    @Test
    public void testAverageArrayWithoutMaxMin(){

        Integer[] arr1 = {1,2,3,4,5};

        Integer expected = 3;
        Integer actual = arraz.averageArrayWithoutMaxMin(arr1);

        Assert.assertEquals(expected, actual);
    }


}