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

import java.util.Arrays;
import java.util.Iterator;

public class MoreArraysTest {


    MoreArrayc more = new MoreArrayc();
    @Test
    public void findIndexOfTest() {
        //Given
        int[] 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
        int [] 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);
    }

}
