import com.sun.xml.internal.xsom.impl.scd.Iterators;
import org.junit.Assert;
import org.junit.Test;

import java.security.PublicKey;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;

public class MoreArraysTest {


    MoreArrayc more = new MoreArrayc();
    Arraz arraz = new Arraz();
    @Test
    public void findIndexOfTest() {
        //Given
        Integer [] arr = {5, 1, 7, 8, 9, 4, 3};
        int value = 8;


        //When

       int container = more.findIndexOf(arr,value);


        //Then
        Assert.assertEquals(3, container);

    }

    @Test
    public void findIndexOfTest2(){
        //Given
        Integer[] arr = {5,1,7,8,9,4,3};
        int value = 5;

        //When

        int container = more.findIndexOf(arr,value);


        //Then
        Assert.assertEquals(0,container);


    }

    @Test
    public void CopyAnArrayByIteratingitTest(){

        //Given
        Integer [] arr = {5,1,7,8,9,4,3};
        Integer [] arrCop;


        //When
        arrCop = more.copyArrayByIteratingthroughIt(arr);


        //Then
        Assert.assertTrue(Arrays.equals(arr,arrCop));

    }

    @Test
    public void CopyAnArrayByIteratingitTestAddingnew(){

        //Given
        Integer [] arr = {5,1,7,8,9,4,3};
        Integer [] arrCop;


        //When
        arrCop = more.copyArrayByIteratingthroughIt(arr);

        arrCop [4] = 8;

        //Then
        Assert.assertFalse(Arrays.equals(arr,arrCop));

    }

    @Test
    public void check2ArraysForEquals(){

        //Given
        Integer [] arr = {5,1,7,8,9,4,3};
        Integer [] arr2 = {5,1,7,8,9,4,3};



        //When

        Boolean flag = more.checkArrayForEquals(arr,arr2);
        //Then

        Assert.assertTrue(flag);

    }

    @Test
    public void CopyAnArrayByloopingitTest(){

        //Given
        Integer [] arr = {5,1,7,8,9,4,3};
        Integer [] arrCop;


        //When
        arrCop = more.copyArrayByLoopingthroughIt(arr);



        //Then
        Assert.assertTrue(Arrays.equals(arr,arrCop));

    }

    @Test
    public void CopyAnArrayByloopingitTestadding(){

        //Given
        Integer [] arr = {5,1,7,8,9,4,3};
        Integer [] arrCop;


        //When
        arrCop = more.copyArrayByLoopingthroughIt(arr);

        arrCop[0] = 4;

        //Then
        Assert.assertFalse(Arrays.equals(arr,arrCop));

    }

    @Test
    public void removeElementFromArray(){

        //Given
        Integer [] arr = {5,1,7,8,9,4,3};
        int element = 4;
        int expected = 6;


        //When

        Integer[] cop = more.removeFromArray(arr,element);


        //Then

        Assert.assertEquals(expected,cop.length);


    }

    @Test
    public void find2ndLargestValueFromArrayTest (){
        //Given
        Integer [] arr = {5,1,7,8,9,4,3};

        //When
        Integer actual = more.find2ndLargestValueFromArray(arr);

        //Then

        Assert.assertEquals(8,actual);
    }

    @Test
    public void makeMeAnArrayListFromArrayTest(){

        //Given
        Integer [] arr = {5,1,7,8,9,4,3};
        int modCount = 0;
        //When

        ArrayList<Integer> arrlist = new ArrayList<Integer>(Arrays.asList(arr));

        //Then
        int counting = 0;




    }

    @Test
    public void sumOfTensLookingFor30TEST (){
        //Given
        Integer [] arr = {10,10,10};

        //When


         Integer sum = arraz.sumValuesOfArrayInt(arr);
         Boolean actual = sum == 30;


        //Then

        Assert.assertTrue(actual);
    }

    @Test
    public void sumOfTensLookingFor30FAIL (){
        //Given
        Integer [] arr = {10,10,1};

        //When


        Integer sum = arraz.sumValuesOfArrayInt(arr);
        Boolean actual = sum == 30;


        //Then

        Assert.assertFalse(actual);
    }

    @Test
    public void makeMeACopyPleaseTEST(){

        //Given

        Integer [] arr = {5,1,7,8,9,4,3};
        Integer [] reverse = {3,4,9,8,7,1,5};


        //When

        Integer [] actual = more.makeMeACopyplz(arr);

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

    }

    @Test
    public void removeLastThenCopy(){
        //Given

        Integer [] arr = {5,1,7,8,9,4,3};
        Integer [] copyRemove = {5,1,7,8,9,4};


        //When

        Integer [] arr2 = more.removeFromArray(arr,arr[arr.length-1]);

        for (int i = 0; i < arr2.length ; i++) {
            System.out.print(arr2[i]);
        }


        //Then
        Assert.assertEquals(copyRemove,arr2);


    }
    @Test
    public void removeFirstThenCopy(){
        //Given

        Integer [] arr = {5,1,7,8,9,4,3};
        Integer [] copyRemove = {1,7,8,9,4,3};


        //When

        Integer [] arr2 = more.removeFromArray(arr,arr[0]);

        for (int i = 0; i < arr2.length ; i++) {
            System.out.print(arr2[i]);
        }


        //Then
        Assert.assertEquals(copyRemove,arr2);


    }

    @Test
    public void insertfirstThenCopyTEST() {

        //Given

        Integer[] arr = {5, 1, 7, 8, 9, 4, 3};
        int value = 6;
        Integer[] arr2 = {6, 5, 1, 7, 8, 9, 4, 3};


        //When

       Integer[] actual = more.insertAtStartAndCopy(arr,value);

        //Then




        Assert.assertEquals(arr2, actual);

    }
    @Test
    public void insertLastThenCopyTEST(){

        //Given

        Integer [] arr = {5,1,7,8,9,4,3};
        int value = 6;

        Integer[] arr2 = {5,1,7,8,9,4,3,6};



        //When

        Integer[] actual = more.insertAtLastAndCopy(arr,value);

        //Then


        Assert.assertEquals(arr2,actual);

    }


}
