import java.util.*;

/**
 * Test for X3
 */
public class TRAII_25_X3_test {

    public static void main(String[] args) {

        // you can change these
        int N1 = 10;    // minumum collection size
        if (args.length > 0)
            N1 = Integer.parseInt(args[0]);

        // maximum collection size
        int N2 = 1000000;
        if (args.length > 1)
            N2 = Integer.parseInt(args[1]);

        // how quickly to increase collection size
        int base = 2;
        if (args.length > 2)
            base = Integer.parseInt(args[2]);

        TRAII_25_X3 myX3 = new TRAII_25_X3_skeleton(); // <--- own id here

        // test with a couple of different collection implementations

        test(myX3, new ArrayList<>(), N1, N2, base, false);
        test(myX3, new ArrayList<>(), N1, N2, base, true);

        test(myX3, new TreeSet<>(), N1, N2, base, false);
        test(myX3, new TreeSet<>(), N1, N2, base, true);

        test(myX3, new HashSet<>(), N1, N2, base, false);
        test(myX3, new HashSet<>(), N1, N2, base, true);

    }


    /**
     * Test task X3 for one collection
     *
     * @param myX3 myX3 measuring class
     * @param C          collection to measure
     * @param min        minimum collection size to measure
     * @param max        maximum collection size to measure
     * @param multiplier multiplier for increasing collection size
     * @param found     to test elements that are found in collection C or not
     */
    static void test(TRAII_25_X3 myX3, Collection<Double> C, int min, int max, int multiplier, boolean found) {
        System.out.println("\nTest " + C.getClass().getName() + " " + min + ".." + max +
                " found="+found);

        SortedMap<Integer, Long> result = new TreeMap<>();
        for (int i = min; i <= max; i *= multiplier)
            result.put(i, 0L);


        // call the X3 method
        long start = System.nanoTime();
        myX3.containsTimes(C, result, found);
        long testTime = System.nanoTime() - start;


        // print how long the test took
        System.out.format("Measurement took %.2f seconds for each collection size%n", (1.0*testTime / (1000.0*1000*1000*result.keySet().size())));

        // print the results
        System.out.println("        n       ns  ns/n");
        for (Map.Entry<Integer, Long> e : result.entrySet()) {
            System.out.format("%9d  %7d  %.2f%n",  e.getKey(), e.getValue(),
                    1.0*e.getValue()/e.getKey());
        }
    }


}
