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

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


public class ArrazTest {

    Arraz arraz = new Arraz();

    @Test

    public void testSumValuesOfArray() {
        //given
        int[] example = {1, 2, 3};

        //when
        int expected = 6;
        int actual = arraz.sumValuesOfArray(example);

        //then
        Assert.assertEquals(expected, actual);
    }

    @Test
    public void testSumValuesOfArrayPt2() {
        //given
        int[] example2 = {5, 3, 1};

        //when
        int expected = 9;
        int actual = arraz.sumValuesOfArray(example2);

        //then
        Assert.assertEquals(expected, actual);

    }

    @Test
    public void testSumDoubleOfArray() {
        //given
        double[] newArray = {5.2, 3.3, 1.2};

        //when
        double expected = 9.7;
        double actual = arraz.sumDoublesOfArray(newArray);

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

    @Test
    public void testSumDoubleOfArrayPt2() {
        //given
        double[] newArray2 = {3.0, 2.0, 1.0};

        //when
        double expected = 6.0;
        double actual = arraz.sumDoublesOfArray(newArray2);

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

    @Test
    public void testAverageOfArray() {
        //given
        Integer[] newArray = {3, 2, 4};

        //when
        Integer expected = 3;
        Integer actual = arraz.averageOfArray(newArray);

        //then
        Assert.assertEquals(expected, actual);

    }

    @Test
    public void testAverageOfArrayPt2() {
        //given
        Integer[] newArray = {3, 5, 4};

        //when
        Integer expected = 4;
        Integer actual = arraz.averageOfArray(newArray);

        //then
        Assert.assertEquals(expected, actual);

    }

    @Test
    public void testAverageOfDoubleArray() {
        //Given
        double[] v = {3.0, 3.2, 4.0};

        //When
        double expected = (v[0] + v[1] + v[2]) / v.length;
        double actual = arraz.doubleAverageOfArray(v);

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

    @Test
    public void testAverageOfDoubleArrayPyt2() {
        //Given
        double[] p = {5.0, 5.2, 5.4};

        //When
        double expected = (p[0] + p[1] + p[2]) / p.length;
        double actual = arraz.doubleAverageOfArray(p);

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

    @Test
    public void testContainsValue() {
        // Given
        Integer[] x = {1, 3, 4, 5, 10};
        int num = 10;


        //Then
        boolean expected = true;
        boolean actual = arraz.containsValue(x, num);

        //When
        Assert.assertEquals(expected, actual);

    }

    @Test
    public void testContainsValuePt2() {
        // Given
        Integer[] x = {1, 3, 4, 5, 10};
        int num = 4;


        //Then
        boolean expected = true;
        boolean actual = arraz.containsValue(x, num);

        //When
        Assert.assertEquals(expected, actual);

    }

    @Test
    public void testReverseArray() {

        //Given
        Integer[] x = {1, 2, 3, 4, 5};

        //When

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

        Integer[] actual = arraz.reverseArray(x);

        //Then

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


    @Test
    public void testReverseArrayPt2() {

        //Given
        Integer[] x = {4, 1, 2, 3, 9};

        //When

        Integer[] expected = {9, 3, 2, 1, 4};

        Integer[] actual = arraz.reverseArray(x);

        //Then

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

    @Test
    public void testGetOddEven() {
        //Given
        Integer[] example = {1, 2, 3, 4, 5, 6, 7};


        //When
        int expected = 3;
        int actual = arraz.getOddEvens(example).getEvens();


        //Then
        Assert.assertEquals(expected, actual);

    }

    @Test
    public void testGetOddEvenPt2() {
        //Given
        Integer[] example = {1, 2, 3, 4, 5, 6, 7};


        //When
        int expected = 4;
        int actual = arraz.getOddEvens(example).getOdds();


        //Then
        Assert.assertEquals(expected, actual);

    }

    @Test
    public void testFindIndexOf() {
        //Given
        Integer[] example = {1, 2, 3, 4};
        Integer value = 3;

        //When
        Integer expected = 2;
        Integer actual = arraz.findIndexOf(example, value);

        //Then
        Assert.assertEquals(expected, actual);

    }


    @Test
    public void testFindIndexOfPt2() {
        //Given
        Integer[] example = {1, 2, 3, 4};
        Integer value = 4;

        //When
        Integer expected = 3;
        Integer actual = arraz.findIndexOf(example, value);

        //Then
        Assert.assertEquals(expected, actual);

    }

    @Test
    public void testCopyArrayByIterator() {

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


        //When
        Integer[] expected = {1, 2, 3, 4, 5};

        Integer[] actual = arraz.copyArrayByIterator(array1);


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


    }

    @Test
    public void testCopyArrayByIteratorPt2() {

        //Given
        Integer[] array2 = {6, 4, 2, 8, 4};


        //When
        Integer[] expected = {6, 4, 2, 8, 4};

        Integer[] actual = arraz.copyArrayByIterator(array2);


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


    }

    @Test
    public void testCopyArrayByLoop() {
        //Given
        Integer[] array1 = {5, 9, 3, 2, 1};


        //When
        Integer[] expected = {5, 9, 3, 2, 1};

        Integer[] actual = arraz.copyArrayByLoop(array1);


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


    }

    @Test
    public void testCopyArrayByLoopPt2() {
        //Given
        Integer[] array2 = {9, 4, 3, 3, 2};


        //When
        Integer[] expected = {9, 4, 3, 3, 2};

        Integer[] actual = arraz.copyArrayByLoop(array2);


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

    }

    @Test
    public void testRemoveElementFromArray() {
        //Given
        Integer[] practArray = {2, 3, 4, 5, 6};
        Integer valueToRemove = 6;


        //When
        Integer[] expected = {2, 3, 4, 5};
        Integer[] actual = arraz.removeElementFromArray(practArray, valueToRemove);


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


    @Test
    public void testRemoveElementFromArrayPt2() {
        //Given
        Integer[] practArray2 = {10, 3, 18, 9, 3};
        Integer valueToRemove = 18;


        //When
        Integer[] expected = {10, 3, 9, 3};
        Integer[] actual = arraz.removeElementFromArray(practArray2, valueToRemove);


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

    @Test

    public void testInsertIntoArray() {
        //Given
        Integer[] practicalArray = {1, 2, 3, 4, 5};
        Integer valueToAdd = 6;
        Integer index = 2;

        //When
        Integer[] expected = {1, 2, 6, 3, 4, 5};
        Integer[] actual = arraz.insertIntoArray(practicalArray, index, valueToAdd);
        //System.out.println(Arrays.toString(actual));
        //Then
        Assert.assertTrue(Arrays.equals(expected, actual));
    }

    @Test
    public void testInsertIntoArrayPt2() {
        //Given
        Integer[] differentArray = {5, 12, 13, 40, 53};
        Integer valueToAdd = 69;
        Integer index = 3;

        //When
        Integer[] expected = {5, 12, 13, 69, 40, 53};
        Integer[] actual = arraz.insertIntoArray(differentArray, index, valueToAdd);

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

    }

    @Test
    public void testgetMinValue() {
        //Given
        Integer[] array = {62, 73, -544, 13};

        //When
        Integer expected = -544;
        Integer actual = arraz.getMinValue(array);


        //Then
        Assert.assertEquals(expected, actual);

    }

    @Test
    public void testgetMaxValue() {
        //Given
        Integer[] array = {62, 73, -544, 13};

        //When
        Integer expected = 73;
        Integer actual = arraz.getMaxValue(array);


        //Then
        Assert.assertEquals(expected, actual);

    }

    @Test
    public void testFindMaxMinOfArray(){
        Integer[] newStuff = { 1,2,3,4,5,6};
        MaxMin newTest = new MaxMin(1,6);
          MaxMin actual = arraz.findMaxMinOfArray(newStuff);
        Assert.assertEquals(newTest,actual);





        }

    @Test
    public void testRemoveDuplicatesFromArray() {
        //Given
        Integer[] array = {5, 12, 13, 13, 40, 53};


        //When
        Integer[] expected = {5, 12, 13, 40, 53};
        Integer[] actual = arraz.removeDuplicatesFromArray(array);

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

    }

    @Test
    public void testRemoveDuplicatesFromArrayPt2() {
        //Given
        Integer[] array2 = {5, 11, 11, 9, 5, 40, 53};


        //When
        Integer[] expected = {5, 11, 9, 40, 53};
        Integer[] actual = arraz.removeDuplicatesFromArray(array2);

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

    }

    @Test
    public void testFind2ndLargestValueFromArray() {

        //Given
        Double[] array1 = {1.1, 2.2, 3.3, 4.4, 5.5, 6.6};

        //Then
        Double expected = 5.5;
        Double actual = arraz.find2ndLargestValueFromArray(array1);

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

    @Test
    public void testFind2ndLargestValueFromArrayPt2() {

        //Given
        Double[] array2 = {13.1, 12.2, 83.3, 77.2, 9.3, 7.6};

        //Then
        Double expected = 77.2;
        Double actual = arraz.find2ndLargestValueFromArray(array2);

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


    @Test
    public void testTurnArrayToArrayList() {
        //Given
        Integer[] example = {2, 3, 4, 5, 6};
        List<Integer> list = new ArrayList<Integer>();
        list.add(2);
        list.add(3);
        list.add(4);
        list.add(5);
        list.add(6);

        //Then
        List<Integer> actual = arraz.turnArrayToArrayList(example);
        //When
        Assert.assertEquals(list, actual);
    }

    @Test
    public void testTurnArrayToArrayListPt2() {
        //Given
        Integer[] example2 = {4, 5, 9, 10, 1};
        List<Integer> list = new ArrayList<Integer>();
        list.add(4);
        list.add(5);
        list.add(9);
        list.add(10);
        list.add(1);

        //Then
        List<Integer> actual = arraz.turnArrayToArrayList(example2);
        //When
        Assert.assertEquals(list, actual);

    }

        @Test
    public void testMakeMeAnArrayFromArrayList(){
             //Given
            List<Integer> arrayList = new ArrayList<Integer>();
            arrayList.add(10);
            arrayList.add(12);
            arrayList.add(13);
            arrayList.add(60);
            //Then

            Integer[] expected ={10,12,13,60};
            Integer[] actual = arraz.makeMeAnArrayFromArrayList(arrayList);

            //When

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

        }

    @Test
    public void testMakeMeAnArrayFromArrayListPt2(){
        //Given
        List<Integer> arrayList = new ArrayList<Integer>();
        arrayList.add(60);
        arrayList.add(100);
        arrayList.add(35);
        arrayList.add(95);
        //Then

        Integer[] expected ={60,100,35,95};
        Integer[] actual = arraz.makeMeAnArrayFromArrayList(arrayList);

        //When

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


    @Test
    public void testCheck2ArraysForEqual(){
        //Given
        Integer[] example1 = {1,2,3,4,5,6};
        Integer[] example2 = {1,2,3,4,5,6};



        //when
       Assert.assertTrue(arraz.check2ArraysForEqual(example1,example2));
    }

    @Test
    public void testCheck2ArraysForEqualPt2(){
        //Given
        Integer[] example2 = {1,2,3,4,5,6};
        Integer[] example3 = {1,3,3,4,3,6};



        //when
        Assert.assertFalse(arraz.check2ArraysForEqual(example2,example3));
    }

    @Test
    public void testAverageArrayWithoutMaxMin(){
       //Given
        Integer[] arrayProvided= {1,2,3,4,5,6};

        //When
        Integer expected = (2+3+4+5) / (arrayProvided.length-2);
        Integer actual = arraz.averageArratWithoutMaxMin(arrayProvided);

        //Then
        Assert.assertEquals(expected, actual);


    }

    @Test
    public void testAverageArrayWithoutMaxMinPt2(){
        //Given
        Integer[] arrayProvidedpt2= {10,2,12,5,4,6};

        //When
        Integer expected = (10+5+4+6) / (arrayProvidedpt2.length-2);
        Integer actual = arraz.averageArratWithoutMaxMin(arrayProvidedpt2);

        //Then
        Assert.assertEquals(expected, actual);


    }

    @Test
    public void arrayHas65and77(){
        //Given
        Integer[] example1 = {30, 65, 92, 77, 101};

        //When

        Boolean expected = true;
        Boolean actual = arraz.arrayHas65and77(example1);

        //Them
        Assert.assertFalse(arraz.arrayHas65and77(example1));


    }

    @Test
    public void arrayHas65and77Pt2(){
        //Given
        Integer[] example1 = {30, 33, 92, 100, 101};

        //When

        Boolean expected = true;
        Boolean actual = arraz.arrayHas65and77(example1);

        //Then
        Assert.assertFalse(arraz.arrayHas65and77(example1));


    }

    @Test
    public void testTheTotalofTensIs30(){
        //Given
        Integer[] example1= {13, 7,11, 10, 10, 22, 10};

        //When

        Boolean expected = true;
        Boolean actual = arraz.theTotalofTensIs30(example1);

        //Then
        Assert.assertFalse(arraz.theTotalofTensIs30(example1));


    }

    @Test
    public void testTheTotalofTensIs30Pt2(){
        //Given
        Integer[] example2= {13, 7,11, 10, 22, 10};

        //When

        Boolean expected = true;
        Boolean actual = arraz.theTotalofTensIs30(example2);

        //Then
        Assert.assertFalse(arraz.theTotalofTensIs30(example2));


    }


    @Test
    public void testFindSmallestAndSecondSmallestOfArray(){
        //Given
        Integer[] example1 = {3,1,7,19,22,31};

        //when
        Integer[] expected = {1,3};
        Integer[] actual = arraz.findSmallestAndSecondSmallestOfArray(example1);


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

    }



    @Test
    public void testFindSmallestAndSecondSmallestOfArrayPt2(){
        //Given
        Integer[] example1 = {9,10,7,19,22,31};

        //when
        Integer[] expected = {7,9};
        Integer[] actual = arraz.findSmallestAndSecondSmallestOfArray(example1);


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

    }

    @Test
    public void testReverseACopyOfArray(){
        //Given
        Integer[] array1 = {1,2,3,4,5};


        //When
        Integer[] expected = {5,4,3,2,1};
        Integer[] actual = arraz.reverseACopyOfArray(array1);

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

    @Test
    public void testReverseACopyOfArrayPt2(){
        //Given
        Integer[] array1 = {10,11,12,13,14,15};


        //When
        Integer[] expected = {15,14,13,12,11,10};
        Integer[] actual = arraz.reverseACopyOfArray(array1);

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

    @Test
    public void testRemoveLastItemAndCopy(){

        //Given
        Integer[] array1 = {2,4,6,8,10};

        //When

        Integer[] expected = {2,4,6,8};
        Integer[] actual = arraz.removeLastItemAndCopy(array1);


        //Then

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

    @Test
    public void testRemoveLastItemAndCopyPt2(){

        //Given
        Integer[] array1 = {9,4,6,8,11};

        //When

        Integer[] expected = {9,4,6,8};
        Integer[] actual = arraz.removeLastItemAndCopy(array1);


        //Then

        Assert.assertTrue(Arrays.equals(expected, actual));
    }
    @Test
    public void testRemoveFirstItemAndCopy(){
        //Given

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


        //When

        Integer[] expected = {2,3,4,5,6};
        Integer[] actual = arraz.removeFirstItemAndCopy(array1);


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

    }

    @Test
    public void testRemoveFirstItemAndCopyPt2(){
        //Given

        Integer[] array1 = {6,7,8,9,10,11};


        //When

        Integer[] expected = {7,8,9,10,11};
        Integer[] actual = arraz.removeFirstItemAndCopy(array1);


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

    }

    @Test
    public void testInsertAtStartAndCopy(){

        //Given
        Integer[] array1 = {1,2,3,4,5};
        Integer num = 1;

        //when
        Integer[] expected = {1,1,2,3,4,5};
        Integer[] actual = arraz.insertAtStartAndCopy(array1, num);

        //Then

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

    @Test
    public void testInsertAtStartAndCopyPT2(){

        //Given
        Integer[] array1 = {5,4,3,2,1};
        Integer num = 6;

        //when
        Integer[] expected = {6,5,4,3,2,1};
        Integer[] actual = arraz.insertAtStartAndCopy(array1, num);

        //Then

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

    @Test
    public void testInsertAtEndAndCopy() {

        //Given
        Integer[] array1 = {1, 2, 3, 4, 5};
        Integer num = 6;

        //when
        Integer[] expected = {1, 2, 3, 4, 5, 6};
        Integer[] actual = arraz.insertAtEndAndCopy(array1, num);

        //Then

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


    @Test
    public void testInsertAtEndAndCopyPt2(){

        //Given
        Integer[] array1 = {3,4,5,9,10};
        Integer num = 37;

        //when
        Integer[] expected = {3,4,5,9,10,37};
        Integer[] actual = arraz.insertAtEndAndCopy(array1, num);

        //Then

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

    @Test
 public void sortArrayIntoEvensThenOdds() {
        //Given
        Integer[] array1 = {102,13,15,16,18,22,3,7};
        //Then
        Integer[] expected = {16,18,22,102,3,7,13,15};
        Integer[] actual = arraz.sortArrayIntoEvensThenOdds(array1);
        //when
        Assert.assertTrue(Arrays.equals(expected,actual));
           }

    @Test
    public void sortArrayIntoEvensThenOddsPt2() {
        //Given
        Integer[] spiffyHandyIntArray = {4,5,102,6,-7,12,-32,92,8};
        //Then
        Integer[] expected = {-32,4,6,8,12,92,102,-7,5,};
        Integer[] actual = arraz.sortArrayIntoEvensThenOdds(spiffyHandyIntArray);
        //when
        Assert.assertTrue(Arrays.equals(expected,actual));
    }





}


