import help.OddEven;
import org.junit.Assert;
import org.junit.Test;

import java.util.List;

public class ArrazTest {
    Arraz test = new Arraz();

    @Test
    public void testSumOfArray_int1(){
        Assert.assertEquals(10, test.sumValuesOfArray(new int[]{4, 3, 2, 1}));
    }

    @Test
    public void testSumOfArray_int2(){
        Assert.assertEquals(-15, test.sumValuesOfArray(new int[]{-5,20,-30}));
    }

    @Test
    public void testSumOfArray_double1(){
        Assert.assertEquals(10.5, test.sumDoubleofArray(new double[]{4.0,3,2,1.5}),.1);
    }

    @Test
    public void testSumOfArray_double2(){
        Assert.assertEquals(0, test.sumDoubleofArray(new double[]{-5.0,20,-15.0}),.1);
    }

    @Test
    public void testAverageOfArray_int1(){
        Assert.assertEquals(7, test.averageOfArray(new int[]{3,20,-1}));
    }

    @Test
    public void testAverageOfArray_int2(){
        Assert.assertEquals(29, test.averageOfArray(new int[]{12,50,15,39}));
    }

    @Test
    public void testDoubleAverageOfArray_double1(){
        Assert.assertEquals(1.0, test.doubleAverageOfArray(new double[]{3,-5,5.0}),.1);
    }

    @Test
    public void testDoubleAverageOfArray_double2(){
        Assert.assertEquals(12, test.doubleAverageOfArray(new double[]{12,4,20,12}),.1);
    }

    @Test
    public void testContainsValue1(){
        Assert.assertTrue(test.containsValue(new int[]{1,2,3,4},3));
    }

    @Test
    public void testContainsValue2(){
        Assert.assertFalse(test.containsValue(new int[]{1,2,3,4},5));
    }

    @Test
    public void testOddEven1(){
        OddEven oe = test.oddEven(new int[]{1,2,3,4,5});
        Assert.assertEquals(3,oe.getOdd());
    }

    @Test
    public void testOddEven2(){
        OddEven oe = test.oddEven(new int[]{1,2,3,4,5});
        Assert.assertEquals(2,oe.getEven());
    }

    @Test
    public void testFindIndexOf1(){
        Assert.assertEquals(2, test.findIndexOf(new Integer[]{1,2,3,4,5},3));
    }

    @Test
    public void testFindIndexOf2(){
        Assert.assertEquals(-1, test.findIndexOf(new Integer[]{1,2,3,4,5},6));
    }

    @Test
    public void testCopyArrayByIterator1(){
        Integer[] a = {1,2,3};
        Integer[] b = test.copyArrayByIterator(a);
        Assert.assertEquals(1, b[0]);
    }

    @Test
    public void testCopyArrayByIterator2(){
        Integer[] a = {1,2,4};
        Integer[] b = test.copyArrayByIterator(a);
        Assert.assertEquals(4, b[2]);
    }

    @Test
    public void testCopyArrayByLoop(){
        int[] a = {1,2,3};
        int[] b = test.copyArrayByLoop(a);
        Assert.assertEquals(1, b[0]);
    }

    @Test
    public void testCopyArrayByLoop2(){
        int[] a = {1,2,3};
        int[] b = test.copyArrayByLoop(a);
        Assert.assertEquals(3, b[2]);
    }

    @Test
    public void testRemoveElementFromArray1(){
        Integer[] a = {1,2,3};
        Integer[] b = test.removeElementFromArray(a,2);
        Assert.assertEquals(3,b[1]);
    }

    @Test
    public void testRemoveElementFromArray2(){
        Integer[] a = {1,2,3,4,5,6,7};
        Integer[] b = test.removeElementFromArray(a,4);
        Assert.assertEquals(5,b[3]);
    }

    @Test
    public void testRemoveDupesFromArray(){
        Integer[] a = {1,1,2,3,4};
        Integer[] b = test.removeDupesFromArray(a);
        Assert.assertEquals(4,b.length);
        Assert.assertEquals(2,b[1]);
    }

    @Test
    public void testRemoveDupesFromArray2(){
        Integer[] a = {1,1,2,3,4,4,5,1,6};
        Integer[] b = test.removeDupesFromArray(a);
        Assert.assertEquals(6,b.length);
        Assert.assertEquals(1,b[4]);
    }

    @Test
    public void testFind2ndLargest1(){
        Double[] d = {1.0,2.0,3.0,4.0};
        Assert.assertEquals(3.0,test.find2ndLargestValueFromArray(d));
    }

    @Test
    public void testFind2ndLargest2(){
        Double[] d = {1.0,1.0,2.0,2.0,2.0,2.0};
        Assert.assertEquals(1.0,test.find2ndLargestValueFromArray(d));
    }

    @Test
    public void testMakeArrayList1(){
        Integer[] a = {1,2,3,4};
        List<Integer> b = test.makeArrayListFromArray(a);
        Assert.assertEquals(4,b.size());
        Assert.assertEquals(4,b.get(3));
    }

    @Test
    public void testMakeArrayList2(){
        Integer[] a = {1,2,3,4,6};
        List<Integer> b = test.makeArrayListFromArray(a);
        Assert.assertEquals(5,b.size());
        Assert.assertEquals(6,b.get(4));
    }

    @Test
    public void testCheck2ArraysForEqual1(){
        Integer[] a = {1,2,3,4};
        Integer[] b = {1,2,3,4};
        Assert.assertTrue(test.check2ArraysForEqual(a,b));
    }

    @Test
    public void testCheck2ArraysForEqual2(){
        Integer[] a = {1,2,3,4};
        Integer[] b = {1,2,3,5};
        Assert.assertFalse(test.check2ArraysForEqual(a,b));
    }

    @Test
    public void testHas65and77_1(){
        Integer[] a = {1,2,3,4,65};
        Integer[] b = {1,2,3,4,77};
        Integer[] c = {1,2,3,4};
        Assert.assertFalse(test.arrayHas65and77(a));
        Assert.assertFalse(test.arrayHas65and77(b));
        Assert.assertFalse(test.arrayHas65and77(c));
    }

    @Test
    public void testHas65and77_2(){
        Integer[] a = {1,2,3,4,65,77};
        Assert.assertTrue(test.arrayHas65and77(a));
    }

    @Test
    public void testTotalofTensIs30_1(){
        Integer[] a = {1,2,10,10,10,10};
        Integer[] b = {1,2,10,10};
        Assert.assertFalse(test.theTotalofTensIs30(a));
        Assert.assertFalse(test.theTotalofTensIs30(b));
    }

    @Test
    public void testTotalofTensIs30_2(){
        Integer[] a = {1,2,10,10,10};
        Integer[] b = {10,2,10,10};
        Assert.assertTrue(test.theTotalofTensIs30(a));
        Assert.assertTrue(test.theTotalofTensIs30(b));
    }

    @Test
    public void testFindTwoSmallest1(){
        Integer[] a = {1,2,3,4,5};
        Integer[] b = test.findTwoSmallest(a);

        Assert.assertEquals(1,b[0]);
        Assert.assertEquals(2,b[1]);
    }

    @Test
    public void testFindTwoSmallest2(){
        Integer[] a = {1,1,1,2,2,3,4,5};
        Integer[] b = test.findTwoSmallest(a);

        Assert.assertEquals(1,b[0]);
        Assert.assertEquals(2,b[1]);
    }

    @Test
    public void testMakeMeACopyPlease1(){
        Integer[] a = {1,2,3,4};
        Integer[] b = {4,3,2,1};

        Assert.assertEquals(b,test.makeMeACopyPlease(a));
    }

    @Test
    public void testMakeMeACopyPlease2(){
        Integer[] a = {1,2,3,4,5,1,1};
        Integer[] b = {1,1,5,4,3,2,1};

        Assert.assertEquals(b,test.makeMeACopyPlease(a));
    }

    @Test
    public void testRemoveLastItemAndCopy1(){
        Integer[] a = {1,2,3,4,5};
        Integer[] b = {1,2,3,4};

        Assert.assertEquals(b,test.removeLastItemAndCopy(a));
    }

    @Test
    public void testRemoveLastItemAndCopy2(){
        Integer[] a = {1,2,3,4,5,6};
        Integer[] b = {1,2,3,4,5};

        Assert.assertEquals(b,test.removeLastItemAndCopy(a));
    }

    @Test
    public void testRemoveFirstItemAndCopy1(){
        Integer[] a = {1,2,3,4,5};
        Integer[] b = {2,3,4,5};

        Assert.assertEquals(b,test.removeFirstItemAndCopy(a));
    }


    @Test
    public void testInsertAtStartAndCopy1(){
        Integer[] a = {1,2,3,4,5,6};
        Integer[] b = {5,1,2,3,4,5,6};

        Assert.assertEquals(b,test.insertAtStartAndCopy(a,5));
    }

    @Test
    public void testInsertAtStartAndCopy2(){
        Integer[] a = {1,2,3,4,5,6};
        Integer[] b = {6,1,2,3,4,5,6};

        Assert.assertEquals(b,test.insertAtStartAndCopy(a,6));
    }

    @Test
    public void testInsertAtEndAndCopy1(){
        Integer[] a = {1,2,3,4,5,6};
        Integer[] b = {1,2,3,4,5,6,12};

        Assert.assertEquals(b,test.insertAtEndAndCopy(a,12));
    }

    @Test
    public void testInsertAtEndAndCopy2(){
        Integer[] a = {1,2,6};
        Integer[] b = {1,2,6,13};

        Assert.assertEquals(b,test.insertAtEndAndCopy(a,13));
    }

    @Test
    public void testSortArrayIntoEvensThenOdds1(){
        Integer[] a = {4,5,102,6,-7,12,-32,92,8};
        a = test.sortArrayIntoEvensThenOdds(a);
        Integer[] b = {4,102,6,12,-32,92,8,5,-7};
        Assert.assertEquals(b,test.sortArrayIntoEvensThenOdds(a));
    }

    @Test
    public void testSortArrayIntoEvensThenOdds2(){
        Integer[] a = {4,5,102,6,-7,12,-32,92,8,29, 15, 105, -8};
        a = test.sortArrayIntoEvensThenOdds(a);
        Integer[] b = {4,102,6,12,-32,92,8,-8,5,-7,29,15,105};
        Assert.assertEquals(b,test.sortArrayIntoEvensThenOdds(a));
    }
}