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

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

public class ArrazTest {

    Arraz arraz= new Arraz();

    @Test
    public void test1sumValuesOfArray(){
        //given
        int[] intArray = {4,5,-6,7,-8,4};
        //when
        int expected =6;
        //then
        int actual= arraz.sumValuesOfArray(intArray);
        Assert.assertEquals(expected,actual);
    }


    @Test
    public void test2sumValuesOfArray(){
        //given
        int[] intArray = {5,5,-6,7,-8,4};
        //when
        int expected =7;
        //then
        int actual= arraz.sumValuesOfArray(intArray);
        Assert.assertEquals(expected,actual);
    }

    @Test
    public void test1sumDoublesOfArray(){
        //given
        double[] intArray = {4,5,-6,7,-8,4};
        //when
        double expected =6;
        //then
        double actual= arraz.sumDoublesOfArray(intArray);
        Assert.assertEquals(expected,actual);
    }

    @Test
    public void test2sumDoublesOfArray(){
        //given
        double[] array = {5,5,-6,7,-8,4};
        //when
        int expected =7;
        //then
        int actual= (int) arraz.sumDoublesOfArray(array);
        Assert.assertEquals(expected,actual);
    }

    @Test
    public void test1averageOfArray(){
        //given
        int[] array =  {5,5,-6,7,-8,4};
        //when
        int expected =3;
        //then
        int actual=  arraz.averageOfArray(array);
        Assert.assertEquals(expected,actual);
    }


    @Test
    public void test2doubleAverageOfArray(){
        //given
        double[] array ={5,5,-6,7,-8,4};
        //when
        double expected =3.5;
        //then
        double actual= arraz.doubleAverageOfArray(array);
        Assert.assertEquals(expected,actual);
    }

    @Test
    public void test1contains(){
        //given
        int[] intArray =  {4,5,-6,7,-8,4};
        boolean expected=true;
        //when
        boolean actual= arraz.contains(intArray,5);
        //then
        Assert.assertEquals(expected,actual);
    }


    @Test
    public void test2contains(){
        //given
        int[] intArray = {4,5,-6,7,-8,4};
        boolean expected=false;
        //when
        boolean actual= arraz.contains(intArray,8);
        //then
        Assert.assertEquals(expected,actual);
    }

    @Test
    public void test1reverseArray(){
        //given
        Integer[] intArray = {4,5,-6,7,-8,4,9};
        Integer[] expected= {9,4,-8,7,-6,5,4};
        //when
        Integer[] actual= arraz.reverseArray(intArray);
        //then
        Assert.assertTrue(Arrays.equals(expected,actual));
    }


    @Test
    public void test2reverseArray(){
        //given
        Integer[] intArray = {8,6,5,8,7};
        Integer[] expected= {7,8,5,6,8};
        //when
        Integer[] actual= arraz.reverseArray(intArray);
        //then
        Assert.assertTrue(Arrays.equals(expected,actual));
    }

    @Test
    public void test1getOddEvensOfArray(){
        //given
        int[] intArray = {3,-3,4,-5,5,6};
       OddEven expected = new OddEven(4,2);
        //when
        OddEven actual=arraz.getOddEvensOfArray(intArray);
        //then
        Assert.assertEquals(expected,actual);
    }

    @Test
    public void test2getOddEvensOfArray(){
        //given
        int[] intArray = {1,2};
        OddEven expected = new OddEven(1,1);
        //when
        OddEven actual=arraz.getOddEvensOfArray(intArray);
        //then
        Assert.assertEquals(expected,actual);
    }


    @Test
    public void test1FindIndexOf(){
        //given
        int[] intArray = {3,-3,4,-5,5,6};
        int expected=2;
        //when
        int actual= arraz.findIndexOf(intArray,4);
        //then
        Assert.assertEquals(expected,actual);


    }


    @Test
    public void test2FindIndexOf(){
        //given
        int[] intArray = {3,-3,4,-5,5,6};
        int expected=5;
        //when
        int actual= arraz.findIndexOf(intArray,6);
        //then
        Assert.assertEquals(expected,actual);


    }

    @Test
    public void test1copyArrayByLoop(){
        //given
        Integer[] arr1={2,3,4,5};
        Integer[] expected={2,3,4,5};
        //when
        Integer[] actual= arraz.copyarrayByLoop(arr1);
        //then
        Assert.assertEquals(expected,actual);
    }

    @Test
    public void test2copyArrayByLoop(){
        //given
        Integer[] arr1={6,-5,7,0};
        Integer[] expected={6,-5,7,0};
        //when
        Integer[] actual= arraz.copyarrayByLoop(arr1);
        //then
        Assert.assertEquals(expected,actual);
    }

    @Test
    public void test1copyArrayByInterator(){
        //given
        Integer[] arr1={6,-5,7,0};
        Integer[] expected={6,-5,7,0};
        //when
        Integer[] actual= arraz.copyArrayByInterator(arr1);
        //then
        Assert.assertEquals(expected,actual);
    }

    @Test
    public void test2copyArrayByInterator(){
        //given
        Integer[] arr1={6,-5,7,0};
        Integer[] expected={6,-5,7,0};
        //when
        Integer[] actual= arraz.copyArrayByInterator(arr1);
        //then
        Assert.assertEquals(expected,actual);
    }

    @Test
    public void test1removeElementFromArray(){
        //given
        Integer[] arr= {2,4,5,4,3,6};
        Integer[] expected = {2,5,3,6};
        //when
        Integer[] actual= arraz.removeElementFromArray(arr,4);
        //then
        Assert.assertEquals(expected,actual);
    }


    @Test
    public void test2removeElementFromArray(){
        //given
        Integer[] arr= {3,4,5,6};
        Integer[] expected = {3,5,6};
        //when
        Integer[] actual= arraz.removeElementFromArray(arr,4);
        //then
        Assert.assertEquals(expected,actual);
    }


    @Test
    public void test1InsertIntoArrayAt(){
        //given
        Integer[] arr={3,5,7,8,3,4};
        int expected=9;
        //when
        int actual= arraz.insertIntoArrayAt(arr,3,9);
        //then
        Assert.assertEquals(expected,actual);
    }

    @Test
    public  void test1FindMaxMinOfArray(){
        //given
        int[] arr={1,5,3,8,6};
        MaxMin expected= new MaxMin(8,1);
        //when
        MaxMin actual= arraz.findMaxMinOfArray(arr);
        //then
        Assert.assertEquals(expected,actual);

    }

    @Test
    public  void test2FindMaxMinOfArray(){

        //given
        int[] arr={5,-5,3,-8,6};
        MaxMin expected= new MaxMin(6,-8);
        //when
        MaxMin actual= arraz.findMaxMinOfArray(arr);
        //then
        Assert.assertEquals(expected,actual);
    }

    @Test
    public void testSort(){
        //given
        Integer[] arr={3,8,5,1};
        Integer[] expected= {1,3,5,8};
        //when
        Integer[] actual= arraz.sortArray(arr);
        //then
        Assert.assertEquals(expected,actual);
    }


    @Test
    public void test1RemoveDupesFromArray(){
        //given
        Integer[] arr= {2,6,7,6,4};
        Integer[] expected={2,4,6,7};
        //when
        Integer[] actual= arraz.removeDupesFromArray(arr);
        //then
        Assert.assertEquals(expected,actual);
    }

    @Test
    public void test2RemoveDupesFromArray(){
        //given
        Integer[] arr= {-8,6,3,-8,5};
        Integer[] expected={-8,3,5,6};
        //when
        Integer[] actual= arraz.removeDupesFromArray(arr);
        //then
        Assert.assertEquals(expected,actual);
    }

    @Test
    public void test1Find2ndLargestValueFromArray(){
        //given
        Double[] arr={7.6,5.7,4.5,3.0};
        Double expected=5.7;
        //when
        Double actual= arraz.find2ndLargestValueFromArray(arr);
        //then
        Assert.assertEquals(expected,actual);
    }

    @Test
    public void test2Find2ndLargestValueFromArray(){
        //given
        Double[] arr={9.8,8.8,-4.6,0.2};
        Double expected=8.8;
        //when
        Double actual= arraz.find2ndLargestValueFromArray(arr);
        //then
        Assert.assertEquals(expected,actual);
    }

    @Test
    public void test1MakeMeAnArrayListFromArray() {
        //given
        Integer[] arr = {4, 6, 2, 7};
        ArrayList<Integer> expected =new ArrayList<>(Arrays.asList(arr));
        //when
        ArrayList<Integer> actaul= arraz.makeMeAnArrayListFromArray(arr);
        //then
        Assert.assertEquals(expected,actaul);
    }


    @Test
    public void test2MakeMeAnArrayListFromArray() {
        //given
        Integer[] arr = {8,-9,3,-5};
        ArrayList<Integer> expected =new ArrayList<>(Arrays.asList(arr));
        //when
        ArrayList<Integer> actaul= arraz.makeMeAnArrayListFromArray(arr);
        //then
        Assert.assertEquals(expected,actaul);
    }

    @Test
    public void test1MakeMeAnArrayFromArrayList(){
        //given
        ArrayList<Integer> list= new ArrayList<>();
        list.add(1);
        list.add(3);
        list.add(8);
        Integer[] expected= {1,3,8};
        //when
        Integer[] actual=  arraz.makeMeAnArrayFromArrayList(list);
        //then
        Assert.assertEquals(expected,actual);
    }

    @Test
    public void test2MakeMeAnArrayFromArrayList(){
        //given
        ArrayList<Integer> list= new ArrayList<>();
        list.add(-9);
        list.add(34);
        list.add(87);
        Integer[] expected= {-9,34,87};
        //when
        Integer[] actual=  arraz.makeMeAnArrayFromArrayList(list);
        //then
        Assert.assertEquals(expected,actual);
    }

    @Test
    public void test1check2ArraysForEqual(){
        //given
        Integer[] arr1= {1,2,3,4};
        Integer[] arr2={1,2,3,4};
        //when
        boolean expected= true;
        boolean actual= arraz.check2ArraysForEqual(arr1,arr2);
        //then
        Assert.assertEquals(expected,actual);
    }


    @Test
    public void test2check2ArraysForEqual(){
        //given
        Integer[] arr1= {1,2,3,4};
        Integer[] arr2={1,4};
        //when
        boolean expected= false;
        boolean actual= arraz.check2ArraysForEqual(arr1,arr2);
        //then
        Assert.assertEquals(expected,actual);
    }

    @Test
    public void test3check2ArraysForEqual(){
        //given
        Integer[] arr1= {1,2,3,4};
        Integer[] arr2={2,5,6,7};
        //when
        boolean expected= false;
        boolean actual= arraz.check2ArraysForEqual(arr1,arr2);
        //then
        Assert.assertEquals(expected,actual);
    }

    @Test
    public void test1AverageArrayWithoutMaxMin(){
        //given
        int[] arr={2,4,3};
        //when
        int expected= 1;
        int actual= arraz.averageArrayWithoutMaxMin(arr);
        //then
        Assert.assertEquals(expected,actual);

    }


    @Test
    public void test2AverageArrayWithoutMaxMin(){
        //given
        int[] arr={3,5,6,2,5,8};
        //when
        int expected= 3;
        int actual= arraz.averageArrayWithoutMaxMin(arr);
        //then
        Assert.assertEquals(expected,actual);
    }


    @Test
    public void test1AarrayHas65and77(){
        //given
        int[] arr={55,65,87,77,90};
        boolean expected =true;
        //when
        boolean actaul= arraz.arrayHas65and77(arr);
        //then
        Assert.assertEquals(expected,actaul);
    }


    @Test
    public void test2AarrayHas65and77(){
        //given
        int[] arr={55,65,87,90};
        boolean expected =false;
        //when
        boolean actaul= arraz.arrayHas65and77(arr);
        //then
        Assert.assertEquals(expected,actaul);
    }


    @Test
    public void test1theTotalofTensIs30(){
        //given
        int[] arr={2,10,3,10,10,6};
        boolean expected=true;
        //when
        boolean actual= arraz.theTotalofTensIs30(arr);
        //then
        Assert.assertEquals(expected,actual);
    }

    @Test
    public void test2theTotalofTensIs30(){
        //given
        int[] arr={2,10,3,10,6};
        boolean expected=false;
        //when
        boolean actual= arraz.theTotalofTensIs30(arr);
        //then
        Assert.assertEquals(expected,actual);
    }


    @Test
    public void test1smallAndSecondSmall(){
        //given
        int[] arr={3,5,7,2,4};
        String expected= "smallest: " + 2 + " second smallest: " + 3;

        //when
        String  actual= arraz.smallAndSecondSmall(arr);
        //then
        Assert.assertEquals(expected,actual);
    }


    @Test
    public void test2smallAndSecondSmall(){
        //given
        int[] arr={-7,8,4,-3};
        String expected= "smallest: " + -7 + " second smallest: " + -3;

        //when
        String  actual= arraz.smallAndSecondSmall(arr);
        //then
        Assert.assertEquals(expected,actual);
    }

    @Test
    public void testmakeMeACopyPlease(){
        //given
        Integer[] arr= {1,4,3,5};
        Integer[] expected= {1,4,3,5};
        //when
        Integer[] actual= arraz.copyArray(arr);
        //then
        Assert.assertEquals(expected,actual);
    }

    @Test
    public void test1makeMeACopyPleaseAndReverse(){
        //given
        Integer[] arr= {1,4,3,5};
        Integer[] expected= {5,3,4,1};
        //when
        Integer[] actual= arraz.makeMeACopyPleaseAndReverse(arr);
        //then
        Assert.assertEquals(expected,actual);
    }


    @Test
    public void test2makeMeACopyPleaseAndReverse(){
        //given
        Integer[] arr= {3,7,9,2};
        Integer[] expected= {2,9,7,3};
        //when
        Integer[] actual= arraz.makeMeACopyPleaseAndReverse(arr);
        //then
        Assert.assertEquals(expected,actual);
    }


    @Test
    public void test1removeLastItemAndCopy(){
        Integer[] arr= {3,7,9,2};
        Integer[] expected= {3,7,9};
        //when
        Integer[] actual= arraz.removeLastItemAndCopy(arr);
        //then
        Assert.assertEquals(expected,actual);
    }

    @Test
    public void test2removeLastItemAndCopy(){
        Integer[] arr= {3,7,9,2};
        Integer[] expected= {3,7,9};
        //when
        Integer[] actual= arraz.removeLastItemAndCopy(arr);
        //then
        Assert.assertEquals(expected,actual);
    }

    @Test
    public void test1removeFirstItemAndCopy(){
        Integer[] arr1= {3,7,9,2};
        Integer[] expected= {7,9,2};
        //when
        Integer[] actual= arraz.removeFirstItemAndCopy(arr1);
        //then
        Assert.assertEquals(expected,actual);
    }

    @Test
    public void test2removeFirstItemAndCopy(){
        Integer[] arr= {4,6,9,3,8};
        Integer[] expected= {6,9,3,8};
        //when
        Integer[] actual= arraz.removeFirstItemAndCopy(arr);
        //then
        Assert.assertEquals(expected,actual);
    }

    @Test
    public void test1insertAtStartAndCopy(){

        Integer[] arr= {3,7,9,2};
        Integer[] expected= {1,3,7,9,2};
        //when
        Integer[] actual= arraz.insertAtStartAndCopy(arr,1);
        //then
        Assert.assertEquals(expected,actual);

    }


    @Test
    public void test2insertAtStartAndCopy(){

        Integer[] arr= {2,6,9,4};
        Integer[] expected= {5,2,6,9,4};
        //when
        Integer[] actual= arraz.insertAtStartAndCopy(arr,5);
        //then
        Assert.assertEquals(expected,actual);

    }

    @Test
    public void test1insertAtEndAndCopy(){
        Integer[] arr= {3,7,9,2};
        Integer[] expected= {3,7,9,2,1};
        //when
        Integer[] actual= arraz.insertAtEndAndCopy(arr,1);
        //then
        Assert.assertEquals(expected,actual);
    }


    @Test
    public void test2insertAtEndAndCopy(){
        Integer[] arr= {5,-9,2,7};
        Integer[] expected= {5,-9,2,7,3};
        //when
        Integer[] actual= arraz.insertAtEndAndCopy(arr,3);
        //then
        Assert.assertEquals(expected,actual);
    }


    @Test
    public void test1sortArrayIntoEvensThenOdds(){

        Integer[] arr= {3,6,7,8};
        Integer[] expected= {6,8,3,7};

        Integer[] expected1= new Integer[0];
        System.out.println(expected1.length);

        //when
        Integer[] actual= arraz.sortArrayIntoEvensThenOdds(arr);
        //then
        Assert.assertEquals(expected,actual);

    }

    @Test
    public void test2sortArrayIntoEvensThenOdds(){

        Integer[] arr= {9,3,2,5,4};
        Integer[] expected= {2,4,3,5,9};
        //when
        Integer[] actual= arraz.sortArrayIntoEvensThenOdds(arr);
        //then
        Assert.assertEquals(expected,actual);

    }

    @Test
    public void testFindCommanItem(){
        //given
        String[] str1={"sam","abhi","ladi"};
        String[] str2={"sam","rina","ladi"};
        String[] expected= {"sam","ladi"};
        //when
        String[] actual=arraz.findCommanItems(str1,str2);
        //then
        Assert.assertEquals(expected,actual);
    }





//    @Test
//    public void testFindSecondLargest(){
//        //given
//        int[] arr1={3,5,8,4};
//        String expected= "the second largest is: " + 5;
//        //when
//        String actual= Arraz.secondLargest(arr1);
//        //then
//        Assert.assertEquals(expected,actual);
//    }

}