import junit.framework.Assert;
import org.junit.Test;
import java.util.ArrayList;

public class ArrazTest {
    Arraz arraz = new Arraz();
    Integer[] nums = {3,4,5,6};
    Double[] numsDbl = {3D,4D,5D,6D};
    @Test
   public void testSumValsOfArrInt(){
        Integer actual = arraz.sumValuesOfArray(nums);
        Assert.assertEquals(18,(int)actual);
    }
    @Test
    public void testSumValsOfArrDub(){
        Double actual = arraz.sumDoublesOfArray(numsDbl);
        Assert.assertEquals(18,actual,0);
    }

    @Test
    public void testAvgArray(){
        Integer actual = arraz.averageOfArray(nums);
        Assert.assertEquals(4,(int)actual);
    }

    @Test
    public void testAvgArrayDbl(){
        Double actual = arraz.doubleAverageOfArray(numsDbl);
        Assert.assertEquals(4.5, actual,0);
    }

    @Test
    public void testContains(){
        boolean actual = arraz.contains(nums, 3);
        Assert.assertEquals(true, actual);
    }

    @Test
    public void testReverseArr(){
        Integer[] exp = {6,5,4,3};
        Integer[] act = arraz.reverseArray(nums);
        Assert.assertEquals(arraz.toString(act),arraz.toString(exp));
    }

    @Test
    public void testOddEven(){
        OddEven exp = new OddEven(2,2);
        OddEven act = arraz.getOddEvensOfArray(nums);
        Assert.assertEquals(exp,act);
    }

    @Test
    public void testFindIndex(){
        int actual = arraz.findIndexOf(nums,4);
        Assert.assertEquals(1,actual);
    }

    @Test
    public void testCpyByItr(){
        Integer[] actArr = arraz.copyArrayByIterator(nums);
        String exp = arraz.toString(nums);
        String act = arraz.toString(actArr);
        Assert.assertEquals(exp,act);
    }

    @Test
    public void testCpyByLoop(){
        Integer[] actArr = arraz.copyArrayByLoop(nums);
        String exp = arraz.toString(nums);
        String act = arraz.toString(actArr);
        Assert.assertEquals(exp,act);
    }

    @Test
    public void testRemoveArrayElement(){
        Integer[] actArr = arraz.removeElementFromArray(nums,4);
        String exp = "ArrayVals: 3 5 6 ";
        String act = arraz.toString(actArr);
        Assert.assertEquals(exp,act);
    }

    @Test
    public void testInsertAtIndex(){
        String exp = "ArrayVals: 1 3 4 5 6 ";
        Integer[] actArr = arraz.insertIntoArrayAt(nums, 0,  1);
        String act = arraz.toString(actArr);
        Assert.assertEquals(exp, act);
    }

    @Test
    public void testMaxMin(){
        MaxMin extrema = new MaxMin(3,6);
        MaxMin actExtrema = arraz.findMaxMinOfArray(nums);
        Assert.assertEquals(extrema,actExtrema);
    }
    @Test
    public void testRemoveDups(){
        Integer[] testArr = {3,4,5,6,6,7,8,8,8,9};
        String exp = arraz.toString(new Integer[] {3,4,5,6,7,8,9});
        Integer[] actArr = arraz.removeDupesFromArray(testArr);
        String act = arraz.toString(actArr);
        Assert.assertEquals(exp,act);
    }

    @Test
    public void test2ndLargest(){
        Integer[] nums2 = {5,2,5,6,8,2,1};
        Integer expected = 6;
        Integer actual = arraz.find2ndLargestValueFromArray(nums2);
        Assert.assertEquals(expected,actual);
    }

    @Test
    public void testArrListFromArr(){
        String exp = "ArrayVals: 3 4 5 6 ";
        ArrayList<Integer> list = arraz.makeMeAnArrayListFromArray(nums);
        Assert.assertEquals(exp,arraz.toString(list));
    }

    @Test
    public void testArrayFromArrList(){
        // : Given
        ArrayList<Integer> list = new ArrayList<>();
        // : When
        list.add(1);
        list.add(2);
        String exp = "ArrayVals: 1 2 ";
        Integer[] act = arraz.makeMeAnArrayFromArrayList(list);
        // : Then
        Assert.assertEquals(exp, arraz.toString(act));
    }

    @Test
    public void test1check2ArraysEqual() {
        Assert.assertTrue(arraz.check2ArraysForEqual(nums, nums));
    }

    @Test
    public void test2check2ArraysEqual() {
        Integer[] arr = {1,2,3,4};
        Assert.assertFalse(arraz.check2ArraysForEqual(arr, nums));
    }

    @Test
    public void test1averageWOMaxMin() {
        Integer[] arr = {2,5,1,4};
        double actual = arraz.averageArrayWithoutMaxMin(arr);
        Assert.assertEquals(3.0, actual,0);
    }

    @Test
    public void test2arrayHas65and77() {
        Integer[] arr = {65,77,1};
        Assert.assertTrue(arraz.arrayHas65and77(arr));
    }

    @Test
    public void testTensTotal30False() {
        Integer[] arr = {1,10};
        Assert.assertFalse(arraz.totalOfTensIs30(arr));
    }

    @Test
    public void testTensTotal30True() {
        Integer[] arr = {1,10,2,10,3,10};
        Assert.assertTrue(arraz.totalOfTensIs30(arr));
    }

    @Test
    public void testFind2ndSmallest() {
        Integer[] arr = {1,2,3,4};
        Integer expected = 2;
        Integer actual = arraz.find2ndSmallestValueFromArray(arr);
        Assert.assertEquals(expected, actual);
    }

    @Test
    public void testReverseCopy() {
        Integer[] arr = {1,2,3};
        String exp = arraz.toString(new Integer[] {3,2,1});
        Integer[] actArr = arraz.reverseCopyOfArray(arr);
        String act = arraz.toString(actArr);
        Assert.assertEquals(exp, act);
    }

    @Test
    public void testRemoveLastItem() {
        Integer[] arr = {3,2,1,0};
        String exp = arraz.toString(new Integer[] {3,2,1});
        Integer[] actArr = arraz.removeLastItem(arr);
        String act = arraz.toString(actArr);
        Assert.assertEquals(exp, act);
    }

    @Test
    public void testRemoveFirstItem() {
        Integer[] arr = {3,2,1,0};
        String exp = arraz.toString(new Integer[] {2,1,0});
        Integer[] actArr = arraz.removeFirstItem(arr);
        String act = arraz.toString(actArr);
        Assert.assertEquals(exp, act);
    }

    @Test
    public void testInsertAtStart() {
        Integer[] arr = {3,2,1,0};
        Integer numb = 100;
        String exp = arraz.toString(new Integer[] {100,3,2,1,0});
        Integer[] actArr = arraz.insertAtStart(arr, numb);
        String act = arraz.toString(actArr);
        Assert.assertEquals(exp,act);
    }

    @Test
    public void testInsertAtEnd() {
        Integer[] arr = {3,2,1,0};
        Integer num = 100;
        String exp = arraz.toString(new Integer[] {3,2,1,0,100});
        Integer[] actArr = arraz.insertAtEnd(arr, num);
        String act = arraz.toString(actArr);
        Assert.assertEquals(exp,act);
    }

    @Test
    public void testSortEvenOdd() {
        Integer[] arr = {3,2,1,0};
        String exp = arraz.toString(new Integer[] {2,0,1,3});
        Integer[] actArr = arraz.sortArrayIntoEvensThenOdds(arr);
        String act = arraz.toString(actArr);
        Assert.assertEquals(exp,act);
    }


}