From b666699aebbcd7dbe3288187d67cf4f7aa521ce6 Mon Sep 17 00:00:00 2001 From: gmungoc Date: Thu, 5 Mar 2015 10:38:43 +0000 Subject: [PATCH] JAL-1270 tests added --- test/jalview/util/QuickSortTest.java | 79 ++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 test/jalview/util/QuickSortTest.java diff --git a/test/jalview/util/QuickSortTest.java b/test/jalview/util/QuickSortTest.java new file mode 100644 index 0000000..6631871 --- /dev/null +++ b/test/jalview/util/QuickSortTest.java @@ -0,0 +1,79 @@ +package jalview.util; + +import static org.junit.Assert.assertTrue; + +import java.util.Arrays; + +import org.junit.Before; +import org.junit.Test; + +public class QuickSortTest +{ + private static final String c1 = "Blue"; + + private static final String c2 = "Yellow"; + + private static final String c3 = "Orange"; + + private static final String c4 = "Green"; + + private Object[] things; + + private final Object[] sortedThings = new Object[] + { c4, c2, c1, c3 }; + + @Before + public void setUp() + { + things = new Object[] + { c1, c2, c3, c4 }; + } + + @Test + public void testSort_byIntValues() + { + int[] values = new int[] + { 3, 2, 4, 1 }; + QuickSort.sort(values, things); + assertTrue(Arrays.equals(new int[] + { 1, 2, 3, 4 }, values)); + assertTrue(Arrays.equals(sortedThings, things)); + } + + @Test + public void testSort_byFloatValues() + { + float[] values = new float[] + { 3f, 2f, 4f, 1f }; + QuickSort.sort(values, things); + assertTrue(Arrays.equals(new float[] + { 1f, 2f, 3f, 4f }, values)); + assertTrue(Arrays.equals(sortedThings, things)); + } + + @Test + public void testSort_byDoubleValues() + { + double[] values = new double[] + { 3d, 2d, 4d, 1d }; + QuickSort.sort(values, things); + assertTrue(Arrays.equals(new double[] + { 1d, 2d, 3d, 4d }, values)); + assertTrue(Arrays.equals(sortedThings, things)); + } + + /** + * Sort by String is descending order, case-sensitive + */ + @Test + public void testSort_byStringValues() + { + String[] values = new String[] + { "JOHN", "henry", "lucy", "ALISON" }; + QuickSort.sort(values, things); + assertTrue(Arrays.equals(new String[] + { "lucy", "henry", "JOHN", "ALISON" }, values)); + assertTrue(Arrays.equals(new Object[] + { c3, c2, c1, c4 }, things)); + } +} -- 1.7.10.2