package com.hithomelabs.princeton1.module7;

import com.hithomelabs.princeton1.common.Apple;
import org.junit.jupiter.api.*;

import java.util.ArrayList;
import java.util.Random;
import static org.junit.jupiter.api.Assertions.*;

class QuickTest {

    private Quick<Apple> quick;
    private ArrayList<Apple> apples;
    private Random random;

    @BeforeEach
    void setUp() {
        quick = new Quick<Apple>();
        apples = new ArrayList<Apple>();
        random = new Random();
    }

    @Test
    @DisplayName("testing Quick sort default implementation")
    public void testSort(){

        for(int i = 0; i < 100; i++)
            apples.add(new Apple(random.nextInt(1000)));
        Apple[] arr = apples.toArray(new Apple[apples.size()]);
        quick.sort(arr);
        apples.sort(null);
        Apple[] sorted =  apples.toArray(new Apple[apples.size()]);
        Assertions.assertArrayEquals(sorted, arr);
    }

    // * * Optional test for alternate sort implmentation
    /*
    @Test
    @DisplayName("testing Quick sort default implementation")
    public void testAltSort(){

        for(int i = 0; i < 100; i++)
            apples.add(new Apple(random.nextInt(1000)));
        Apple[] arr = apples.toArray(new Apple[apples.size()]);
        quick.altSort(arr);
        apples.sort(null);
        Apple[] sorted =  apples.toArray(new Apple[apples.size()]);
        Assertions.assertArrayEquals(sorted, arr);
    }
    */



    @AfterEach
    void tearDown() {
        quick = null;
        apples = null;
        random = null;
        }
}