package org.psjava.example.algo;

import junit.framework.Assert;

import org.junit.Test;
import org.psjava.algo.sequence.sort.BubbleSort;
import org.psjava.algo.sequence.sort.InsertionSort;
import org.psjava.algo.sequence.sort.MergeSort;
import org.psjava.algo.sequence.sort.RandomizedQuicksort;
import org.psjava.algo.sequence.sort.SortingHelper;
import org.psjava.ds.array.MutableArray;
import org.psjava.ds.array.MutableArrayFromValues;
import org.psjava.goods.GoodSortingAlgorithm;
import org.psjava.util.DefaultComparator;

/**
 * @see {@link QuicksortExample}
 * @see {@link InsertionSortExample}
 * @see {@link BubbleSortExample}
 * @see {@link MergeSortExample}
 */
public class SortExample {
	@Test
	public void example() {

		// Following example is normal usage.

		MutableArray<Integer> array1 = MutableArrayFromValues.create(2, 1, 3);
		MergeSort.getInstance().sort(array1, new DefaultComparator<Integer>());

		// There is only one method in Sort interface,
		// but there are several convenient methods in SortHelper class
		// Following is partial sorting.

		MutableArray<Integer> array2 = MutableArrayFromValues.create(100, 3, 2, 1, 0);
		SortingHelper.sort(MergeSort.getInstance(), array2, 1, 4);

		// There are several implementations.
		RandomizedQuicksort.getInstance();
		InsertionSort.getInstance();
		BubbleSort.getInstance();
		MergeSort.getInstance();
		GoodSortingAlgorithm.getInstance(); // We choose a good one for you.

		Assert.assertEquals("(1,2,3)", array1.toString());
		Assert.assertEquals("(100,1,2,3,0)", array2.toString());
	}
}

@@ -128,176 +128,14 @@
 ort.
-BubbleSort;%0D%0Aimport org.psjava.algo.sequence.sort.InsertionSort;%0D%0Aimport org.psjava.algo.sequence.sort.MergeSort;%0D%0Aimport org.psjava.algo.sequence.sort.RandomizedQuicks
+MergeS
 ort;
@@ -287,55 +287,8 @@
 s;%0D%0A
-import org.psjava.goods.GoodSortingAlgorithm;%0D%0A
 impo
@@ -569,16 +569,18 @@
 mple is 
+a 
 normal u
@@ -736,16 +736,70 @@
 er%3E());%0D
+%0A%09%09Assert.assertEquals(%22(1,2,3)%22, array1.toString());%0D
 %0A%0D%0A%09%09// 
@@ -826,20 +826,26 @@
 thod in 
+the '
 Sort
+'
  interfa
@@ -898,16 +898,17 @@
 hods in 
+'
 SortHelp
@@ -909,16 +909,17 @@
 rtHelper
+'
  class%0D%0A
@@ -936,16 +936,18 @@
 wing is 
+a 
 partial 
@@ -953,16 +953,24 @@
  sorting
+ example
 .%0D%0A%0D%0A%09%09M
@@ -1113,306 +1113,8 @@
 4);%0D
-%0A%0D%0A%09%09// There are several implementations.%0D%0A%09%09RandomizedQuicksort.getInstance();%0D%0A%09%09InsertionSort.getInstance();%0D%0A%09%09BubbleSort.getInstance();%0D%0A%09%09MergeSort.getInstance();%0D%0A%09%09GoodSortingAlgorithm.getInstance(); // We choose a good one for you.%0D%0A%0D%0A%09%09Assert.assertEquals(%22(1,2,3)%22, array1.toString());%0D
 %0A%09%09A

make sort example more simpler