ソートアルゴリズム計画その1.9
テストの部分
import static org.hamcrest.CoreMatchers.*; import static org.junit.Assert.*; import java.util.ArrayList; import java.util.List; import org.junit.Test; public class QuickAndBubble { @Test public void 引数に与えた配列をクイックソートまたはバブルソートする() throws Exception { List<Integer> list = new ArrayList<Integer>(); list.add(3); list.add(4); list.add(2); list.add(5); list.add(1); Sortable bubblesort = new BubbleSort(); List<Integer> bubble = bubblesort.sort(list); List<Integer> except = new ArrayList<Integer>(); except.add(1); except.add(2); except.add(3); except.add(4); except.add(5); for (int i = 0; i <= except.size() - 1; i++) { System.out.println(bubble.get(i)); assertThat(bubble.get(i), is(except.get(i))); } Sortable quicksort = new QuickSort(); List<Integer> quick = quicksort.sort(list); for (int i = 0; i <= except.size() - 1; i++) { System.out.println(quick.get(i)); assertThat(quick.get(i), is(except.get(i))); } } }