

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

import java.util.Arrays;


public class ArrazTest {

    private Arraz testArraz;
    private OddEven oddEven1;
    private MaxMin maxMin;
    private int[] arr1;
    private int[] arr2;
    private double[] double1;

    @Before
    public void before() {
        arr1 = new int[]{5, 10, 3, 29, 100};
        arr2 = new int[]{2, 7, 432, 89};
        double1 = new double[] {1.0, 0.5, 3.6, 38.4, 17.3, 62.0, 9.0, 3.375, 0, 3.14159};
        testArraz = new Arraz();
        oddEven1 = new OddEven(3, 2);
        maxMin = new MaxMin(100,3);
    }

    @Test
    public void test1SumValuesOfArray1() {
        int expected = 147;
        int actual = testArraz.sumValuesOfArray(arr1);

         Assert.assertEquals(expected, actual);
    }

    @Test
    public void test2SumValuesOfArray2(){
        int expected = 530;
        int actual = testArraz.sumValuesOfArray(arr2);

        Assert.assertEquals(expected, actual);
    }

    @Test
    public void testSumDoublesOfArray1(){
        double expected =138.31659;
        double actual = testArraz.sumDoublesOfArray(double1);

        Assert.assertEquals(expected, actual, .01);
    }

    @Test
    public void testSumDoublesOfArray2(){
        double expected = 0;
        double actual = testArraz.sumDoublesOfArray(new double[]{0.0,0.0});

        Assert.assertEquals(expected, actual, .01);
    }

    @Test
    public void testAverageOfArray1(){
        int expected = 29;
        int actual = testArraz.averageOfArray(arr1);

        Assert.assertEquals(expected, actual);
    }

    @Test
    public void testAverageOfArray2(){
        int expected = 132;
        int actual = testArraz.averageOfArray(arr2);

        Assert.assertEquals(expected, actual);
    }

    @Test
    public void testDoubleAverageOfArray1(){
        double expected = 13.831659;
        double actual = testArraz.doubleAverageOfArray(double1);

        Assert.assertEquals(expected, actual, .01);
    }

    @Test
    public void testDoubleAverageOfArray2(){
        double expected = 0;
        double actual = testArraz.doubleAverageOfArray(new double[]{0.0, 0.0});

        Assert.assertEquals(expected, actual, 01);
    }

    @Test
    public void testContainsValue1(){
        boolean actual = testArraz.containsValue(arr1, 29);
        Assert.assertTrue(actual);
    }

    @Test
    public void testContainsValue2(){
        boolean actual = testArraz.containsValue(arr1, 50000);
        Assert.assertFalse(actual);
    }

    @Test
    public void testReverseArray1(){
        int[] expected =new int[]{100, 29, 3, 10, 5};
        int[] actual = testArraz.reverseArray(arr1);

        Assert.assertArrayEquals(expected, actual);
    }

    @Test
    public void testReverseArray2(){
        int[] expected = arr1;
        int[] actual = testArraz.reverseArray(arr1);

        Assert.assertFalse(Arrays.equals(expected, actual));
    }

    @Test
    public void testOddEvens1(){
        OddEven actual = testArraz.oddEvens(arr1);
        Assert.assertEquals(oddEven1.getOdd(), actual.getOdd());
    }

    @Test
    public void testOddEvens2(){
        OddEven actual = testArraz.oddEvens(arr1);
        Assert.assertEquals(oddEven1.getEven(), actual.getEven());
    }

    @Test
    public void testFindIndexOf1(){
        int expected = 3;
        int actual = testArraz.getIndexOf(arr1, 29);

        Assert.assertEquals(expected, actual);
    }

    @Test
    public void testFindIndexOf2(){
        int expected = -1;
        int actual = testArraz.getIndexOf(arr1, 500);

        Assert.assertEquals(expected,actual);
    }

    @Test
    public void testCopyArrayByIterator1(){
        Integer[] expected = new Integer[]{1,2,3,4,5};
        Integer[] actual = testArraz.copyArrayByIterator(expected);

        Assert.assertArrayEquals(expected, actual);
    }

    @Test
    public void testCopyArrayByIterator2(){
        Integer[] expected = new Integer[]{10, 3, 5, 43};
        Integer[] actual = testArraz.copyArrayByIterator(expected);

        Assert.assertArrayEquals(expected, actual);
    }

    @Test
    public void testCopyArrayByLoop1(){
        int[] expected = arr1;
        int[] actual = testArraz.copyArrayByLoop(arr1);

        Assert.assertArrayEquals(expected, actual);
    }

    @Test
    public void testCopyArrayByLoop2(){
        Assert.assertFalse(Arrays.equals(arr1, testArraz.copyArrayByLoop(arr2)));
    }

    @Test
    public void testRemoveElementFromArray1(){
        int[] expected = new int[]{5, 10, 29, 100};
        int[] actual = testArraz.removeElementFromArray(arr1, 3);

        Assert.assertArrayEquals(expected, actual);
    }

    @Test
    public void testRemoveElementFromArray2(){
        int[] expected = new int[]{2, 7, 89};
        int[] actual = testArraz.removeElementFromArray(arr2, 432);

        Assert.assertArrayEquals(expected, actual);
    }

    @Test
    public void testInsertArrayAt1(){
        int[] expected = new int[]{5, 10, 17, 3, 29, 100};
        int[] actual = testArraz.insertArrayAt(arr1, 2, 17);

        Assert.assertArrayEquals(expected, actual);
    }

    @Test
    public void testInsertArrayAt2(){
        int[] expected =  new int[]{2, 7, 432, 89, 6};
        int[] actual = testArraz.insertArrayAt(arr2, 4, 6);

        Assert.assertArrayEquals(expected, actual);
    }

    @Test
    public void testFindMaxMinOfArray1(){
        Assert.assertEquals(maxMin.getMax(), testArraz.findMaxMinOfArray(arr1).getMax());
    }

    @Test
    public void testFindMaxMinOfArray2(){
        Assert.assertEquals(maxMin.getMin(), testArraz.findMaxMinOfArray(arr1).getMin());
    }

    @Test
    public void testRemoveDupesFromArray1(){
        Integer[] array1 = new Integer[]{1,3 ,4, 3, 7, 7, 10};
        Integer[] expected = new Integer[]{1, 3, 4, 7, 10};
        Integer[] actual = testArraz.removeDupesFromArray(array1);

        Assert.assertArrayEquals(expected, actual);
    }

    @Test
    public void testRemoveDupesFromArray2(){
        Integer[] array1 = new Integer[]{5, 1, 1, 1, 1 ,1};
        Integer[] expected = new Integer[]{5, 1};
        Integer[] actual = testArraz.removeDupesFromArray(array1);

        Assert.assertArrayEquals(expected, actual);
    }
}