not really known
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.4 KiB

  1. package net.jrtechs.www.sorting;
  2. import net.jrtechs.www.DataStructures.Lists.ArrayList.ArrayBackedList;
  3. import net.jrtechs.www.Sorting.MergeSort;
  4. import net.jrtechs.www.Sorting.QuickSort;
  5. import org.junit.Test;
  6. import static junit.framework.TestCase.assertNotNull;
  7. import static junit.framework.TestCase.assertTrue;
  8. public class QuickSortTest
  9. {
  10. @Test
  11. public void testInitalization()
  12. {
  13. QuickSort<Double> sorter = new QuickSort<>(MergeSort.DECREASING_ORDER);
  14. assertNotNull(sorter);
  15. }
  16. @Test
  17. public void testInsertionSortAscending()
  18. {
  19. QuickSort<Double> sorter = new QuickSort<>(QuickSort.INCREASING_ORDER);
  20. ArrayBackedList<Double> list = new ArrayBackedList<>();
  21. list.add(1.0);
  22. list.add(0.0);
  23. list.add(3.0);
  24. list.add(-12.0);
  25. sorter.quickSort(list);
  26. assertTrue(list.get(0) == -12.0);
  27. assertTrue(list.get(list.size() -1) == 3);
  28. }
  29. @Test
  30. public void testInsertionSortDescending()
  31. {
  32. QuickSort<Double> sorter = new QuickSort<>(QuickSort.DECREASING_ORDER);
  33. ArrayBackedList<Double> list = new ArrayBackedList<>();
  34. list.add(1.2);
  35. list.add(1.0);
  36. list.add(0.0);
  37. list.add(3.0);
  38. list.add(-12.0);
  39. sorter.quickSort(list);
  40. assertTrue(list.get(0) == 3.0);
  41. assertTrue(list.get(list.size() -1) == -12);
  42. }
  43. }