
import java.util.*;

public class TRAII_25_X2_test {

    static TRAII_25_X2 myClass = new TRAII_25_X2_skeleton();
    //                                              ^^^^ own id here


    public static void main(String[] args) {

        // max number of elements
        int N = 1000000;
        if (args.length > 0)
            N = Integer.parseInt(args[0]);

        int seed = 42;
        if (args.length > 1)
            seed = Integer.parseInt(args[1]);
        Random rnd = new Random(seed);

        // amount of print
        int print = 3;
        if (args.length > 2)
            print = Integer.parseInt(args[2]);

        // call first without prints for 2 seconds
        warmUp(N, rnd, 3);

        // sitten varsinainen testiajo
        testX2(N, rnd, print);


    } // main()


    /**
     * Test with input size 1..n
     * @param n max number of elements
     * @param rnd random number generator
     * @param print amount of print
     */
    static void testX2(int n, Random rnd, int print) {
        int k = 1;
        // you can try different implementations here
        // Map<Double, Double> M = new HashMap<>();
        // Map<Double, Double> M = new LinkedHashMap<>();
        Map<Double, Double> M = new TreeMap<>();
        while (M.size() < n) {
            while (M.size() < k)
                M.put(rnd.nextDouble(), rnd.nextDouble());
            testX2(M, print);
            k *= 2;
        }
    }


    /**
     * Call this to warm up the JVM before the real test starts
     * @param n max number of elements
     * @param rnd random number generator
     * @param sec duration of execution
     */
    static void warmUp(int n, Random rnd, int sec) {

        System.out.println("Warm up starts for " + sec + "s");
        long end = System.nanoTime() + sec*1000L*1000*1000;
        while (System.nanoTime() < end)
            testX2(n, rnd, 0);
        System.out.println("Warm up ends.");
    }


    /**
     * Test task X2 with Map M
     * @param M Map to test
     * @param print amount of print
     */
    static void testX2(Map<Double, Double> M, int print) {

        if (print > 1)
            System.out.println("\nTest, Map = " + M.getClass().toString() + " n = " + M.size());

        long start = System.nanoTime();

        long result = myClass.containsKeyTime(M);

        long end = System.nanoTime();

        if (print > 0) System.out.println("  result = " + result + " ns");

        if (end-start > 1000L*1000*1000)
            System.out.println("Warning: test was too slow (over 1s)");

        if (print > 3)  // adjust here if you want to see how long your test lasted
            System.out.println("Test lasted " + ((end-start)/1000000.0) + " ms");


    }


}
