package ru.matevosyan;

import org.junit.Test;

import java.util.Iterator;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertTrue;


/**
 * FastSimpleSetTest class.
 * Created on 04.06.2017.
 * @author Matevosyan Vardan
 * @version 1.0
 */

public class FastSimpleSetTest {

    /**
     * Create whenCreateTwoObjectAndAddValuesThanCheckWhoAddedFasterToTheContainer() to check hwo is faster.
     */

    @Test public void whenCreateTwoObjectAndAddValuesThanCheckWhoAddedFasterToTheContainer() {
        FastSimpleSet<String> fastSimpleSet = new FastSimpleSet<>();
        DynamicSimpleSet<String> dynamicSimpleSet = new DynamicSimpleSet<>();

        long fastSetTimeBegin = System.currentTimeMillis();
        for (int i = 0; i < 100000; i++) {
            fastSimpleSet.add("one" + i);
        }
        for (int i = 0; i < 100000; i++) {
            fastSimpleSet.get("one" + i);
        }
        long fastSetTimeEnd = System.currentTimeMillis();


        long dynamicSimpleSetTimeBegin = System.currentTimeMillis();
        for (int i = 0; i < 100000; i++) {
            dynamicSimpleSet.add("one" + i);
        }
        for (int i = 0; i < 100000; i++) {
            dynamicSimpleSet.get(i);
        }
        long dynamicSimpleSetTimeEnd = System.currentTimeMillis();

        long fastTime = fastSetTimeEnd - fastSetTimeBegin;
        long dynamicSimpleTime = dynamicSimpleSetTimeEnd - dynamicSimpleSetTimeBegin;
        System.out.println(fastTime + "fast");

        System.out.println(dynamicSimpleTime + "simple");
        assertTrue(fastTime < dynamicSimpleTime);


    }

    /**
     * whenCreateObjectAndAddValuesThanCheckSize to test array size.
     */

    @Test public void whenCreateObjectAndAddValuesThanCheckSize() {
        FastSimpleSet<Integer> fastSimpleSet = new FastSimpleSet<>();

        for (int i = 0; i < 30; i++) {
            fastSimpleSet.add(i);
        }

        assertThat(fastSimpleSet.get(1), is(1));
        assertThat(fastSimpleSet.get(20), is(20));

        assertThat(fastSimpleSet.getSize(), is(30));
    }

    /**
     * whenCreateObjddectAndAddValuesThanCheckSize for testing iterator and check size.
     * when insert duplicates.
     */

    @Test public void whenCreateObjddectAndAddValuesThanCheckSize() {
        FastSimpleSet<String> fastSimpleSet = new FastSimpleSet<>();


            fastSimpleSet.add("---qqqqqqqqqqqqqq");
            fastSimpleSet.add("444ergw3grger");
            fastSimpleSet.add("papgerg34ga");
            fastSimpleSet.add("@gerge4g3g@@");
            fastSimpleSet.add(">ergerge>>");
            fastSimpleSet.add("~~~|rgerhrtj|ooo");
            fastSimpleSet.add("~~~|rgerhrtj|ooo");
            fastSimpleSet.add("~~~|rgerhrtj|ooo");
            fastSimpleSet.add("~~~|rgerhrtj|ooo");

        Iterator<String> itr = fastSimpleSet.iterator();

        while(itr.hasNext()) {
            String s = itr.next();
            System.out.println(s);
        }

        assertThat(fastSimpleSet.getSize(), is(6));
    }


}
@@ -67,16 +67,42 @@
 terator;
+%0Aimport java.util.TreeSet;
 %0A%0Aimport
@@ -672,28 +672,19 @@
         
-DynamicSimpl
+Tre
 eSet%3CStr
@@ -692,43 +692,25 @@
 ng%3E 
-dynamicSimpleSet = new DynamicSimpl
+treeSet = new Tre
 eSet
@@ -801,33 +801,32 @@
 i = 0; i %3C 10000
-0
 ; i++) %7B%0A       
@@ -874,102 +874,8 @@
   %7D%0A
-        for (int i = 0; i %3C 100000; i++) %7B%0A            fastSimpleSet.get(%22one%22 + i);%0A        %7D
 %0A   
@@ -1025,33 +1025,32 @@
 i = 0; i %3C 10000
-0
 ; i++) %7B%0A       
@@ -1050,36 +1050,27 @@
             
-dynamicSimpl
+tre
 eSet.add(%22on
@@ -1092,97 +1092,8 @@
   %7D%0A
-        for (int i = 0; i %3C 100000; i++) %7B%0A            dynamicSimpleSet.get(i);%0A        %7D
 %0A   
@@ -2210,24 +2210,76 @@
 eSet%3C%3E();%0A%0A%0A
+            fastSimpleSet.add(%22---qqqqqqqqqqqqqq%22);%0A
             

change to treeSet