package ru.matevosyan;

import org.junit.Test;

import java.util.Iterator;
import java.util.TreeSet;

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<>();
        TreeSet<String> treeSet = new TreeSet<>();

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

        long fastSetTimeEnd = System.currentTimeMillis();


        long dynamicSimpleSetTimeBegin = System.currentTimeMillis();
        for (int i = 0; i < 10000; i++) {
            treeSet.add("one" + 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("---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));
    }


}
@@ -71,34 +71,8 @@
 tor;
-%0Aimport java.util.TreeSet;
 %0A%0Aim
@@ -583,38 +583,39 @@
   FastSimpleSet%3C
-String
+Integer
 %3E fastSimpleSet 
@@ -651,41 +651,69 @@
     
-TreeSet%3CString%3E treeSet = new Tre
+DynamicSimpleSet%3CInteger%3E dynamicSimpleSet = new DynamicSimpl
 eSet
@@ -803,33 +803,32 @@
  i = 0; i %3C 1000
-0
 ; i++) %7B%0A       
@@ -846,32 +846,24 @@
 mpleSet.add(
-%22one%22 + 
 i);%0A        
@@ -1026,17 +1026,16 @@
 i %3C 1000
-0
 ; i++) %7B
@@ -1051,11 +1051,20 @@
     
-tre
+dynamicSimpl
 eSet
@@ -1072,16 +1072,8 @@
 add(
-%22one%22 + 
 i);%0A
@@ -1300,113 +1300,8 @@
 in;%0A
-        System.out.println(fastTime + %22fast%22);%0A%0A        System.out.println(dynamicSimpleTime + %22simple%22);
 %0A   
@@ -1416,480 +1416,19 @@
 Size
- to test array size.%0A     */%0A%0A    @Test public void whenCreateObjectAndAddValuesThanCheckSize() %7B%0A        FastSimpleSet%3CInteger%3E fastSimpleSet = new FastSimpleSet%3C%3E();%0A%0A        for (int i = 0; i %3C 30; i++) %7B%0A            fastSimpleSet.add(i);%0A        %7D%0A%0A        assertThat(fastSimpleSet.get(1), is(1));%0A        assertThat(fastSimpleSet.get(20), is(20));%0A%0A        assertThat(fastSimpleSet.getSize(), is(30));%0A    %7D%0A%0A    /**%0A     * whenCreateObjddectAndAddValuesThanCheckSize
+AndIterator
  for
@@ -1536,18 +1536,16 @@
 reateObj
-dd
 ectAndAd
@@ -1564,16 +1564,27 @@
 heckSize
+AndIterator
 () %7B%0A   
@@ -2200,24 +2200,52 @@
 terator();%0A%0A
+        String last = null;%0A
         whil
@@ -2279,16 +2279,12 @@
     
-String s
+last
  = i
@@ -2306,45 +2306,56 @@
     
+%7D%0A%0A
     
-System.out.println(s);%0A        %7D%0A
+    assertThat(last, is(%22@gerge4g3g@@%22));
 %0A   

test for task 3. Увеличение скорости вставки объекта в коллекцию типа Set [#998]