package com.beardfish.test.sort;

import com.beardfish.sort.QuickSort;

import org.junit.Test;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Random;

/**
 * Created by christian on 2/17/14.
 */
public class QuickSortTest {
	
	@Test
	public void sortTestQuickSortTrivial() {
		List<Integer> numbers = new LinkedList<Integer>() {{
			add(14);
			add(33);
			add(27);
			add(10);
			add(35);
			add(19);
			add(42);
			add(44);
		}};
		QuickSort QuickSort = new QuickSort();
		QuickSort.<Integer>sort(numbers, new IntegerComparator());
		System.out.println(numbers.toString());
	}

    @Test
    public void sortTestQuickSortInt() {
       List<Integer> numbers = new LinkedList<Integer>()  {{
            add(1);
            add(10);
            add(27);
            add(7);
            add(3);
            add(0);
        }};
        QuickSort QuickSort = new QuickSort();
        QuickSort.<Integer>sort(numbers,new IntegerComparator());
        System.out.println(numbers.toString());
    }

    @Test
    public void sortTestQuickSortString() {
        List<String> strings = new LinkedList<String>() {{
            add("garbage");
            add("apple");
            add("baby");
            add("revolution");
            add("baby");
            add("alpha");
            add("rock");
            add("orphan");
            add("xylophone");
        }};
        QuickSort QuickSort = new QuickSort();
        QuickSort.<String>sort(strings,new StringComparator());
        System.out.println(strings.toString());
    }
    
    @Test
    public void sortRandom1000Integers() {
    	List<Integer> randomNumbers = new ArrayList<Integer>(10000);
    	Random random =  new Random();
    	QuickSort QuickSort = new QuickSort();
    	for(int i = 0; i<10000;i++) {
    		randomNumbers.add(random.nextInt());
    	}
    	long start = System.nanoTime();
    	QuickSort.sort(randomNumbers, new IntegerComparator());
    	double elapsedTime = ((double)(System.nanoTime()-start))/1000000000;
    	System.out.println("Elapsed Time: "+(elapsedTime));
    }
}

@@ -480,38 +480,34 @@
 %7D%7D;%0A%09%09QuickSort 
-QuickS
+qs
 ort = new QuickS
@@ -515,22 +515,18 @@
 rt();%0A%09%09
-QuickS
+qs
 ort.%3CInt
@@ -872,38 +872,34 @@
       QuickSort 
-QuickS
+qs
 ort = new QuickS
@@ -909,30 +909,26 @@
 ();%0A        
-QuickS
+qs
 ort.%3CInteger
@@ -1400,38 +1400,34 @@
       QuickSort 
-QuickS
+qs
 ort = new QuickS
@@ -1441,22 +1441,18 @@
         
-QuickS
+qs
 ort.%3CStr
@@ -1722,22 +1722,18 @@
 ickSort 
-QuickS
+qs
 ort = ne
@@ -1874,22 +1874,18 @@
 );%0A    %09
-QuickS
+qs
 ort.sort

change variable names that were QuickSort to qsort to make the code easier to read.