package com.hithomelabs.clients.Benchmarks;

import com.hithomelabs.princeton1.common.Apple;
import com.hithomelabs.princeton1.module5.MeasurableSort;
import com.hithomelabs.princeton1.module5.SortingMetaData;

import java.util.List;
import java.util.Random;

public class BenchMark {

    private int size;
    private List<MeasurableSort<Apple>> algorithms;
    private Apple[] sorted;
    private Apple[] reverseSorted;
    private Apple[] random;

    BenchMark(int size, List<MeasurableSort<Apple>> algorithms) {
        this.size = size;
        this.algorithms = algorithms;
        sorted = new Apple[this.size];
        reverseSorted = new Apple[this.size];
        random = new Apple[this.size];

        for (int i = 0; i < size; i++) {
            sorted[i] = new Apple(i);
            reverseSorted[i] = new Apple(size - i);
            random[i] = new Apple(new Random().nextInt(1000));
        }
    }

    public void run() {
        for (MeasurableSort<Apple> algo: algorithms){
            System.out.println("Input size: "+size);
            System.out.println("Running "+algo.getClass());
            System.out.println("Sorting already sorted list");
            SortingMetaData metaData = new SortingMetaData();
            algo.sort(sorted.clone(),Apple.COMPARE_BY_SIZE, metaData);
            System.out.println(metaData);
            System.out.println("Sorting reverse sorted list");
            metaData = new SortingMetaData();
            algo.sort(reverseSorted.clone(),Apple.COMPARE_BY_SIZE, metaData);
            System.out.println(metaData);
            System.out.println("Sorting randomly ordered list");
            metaData = new SortingMetaData();
            algo.sort(random.clone(),Apple.COMPARE_BY_SIZE, metaData);
            System.out.println(metaData);
        }
    }

}






