X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=test%2Fjalview%2Futil%2FQuickSortTest.java;h=bf9d16b187454184e0d23fb46d7b14b995443b6e;hb=57738a1f3c19b1c3a00bd3ac5108f8cd0af32f99;hp=f9769550a3ec46d787b0715ffd5f44707909d3af;hpb=37de9310bec3501cbc6381e0c3dcb282fcaad812;p=jalview.git diff --git a/test/jalview/util/QuickSortTest.java b/test/jalview/util/QuickSortTest.java index f976955..bf9d16b 100644 --- a/test/jalview/util/QuickSortTest.java +++ b/test/jalview/util/QuickSortTest.java @@ -23,13 +23,24 @@ package jalview.util; import static org.testng.AssertJUnit.assertEquals; import static org.testng.AssertJUnit.assertTrue; +import jalview.gui.JvOptionPane; + import java.util.Arrays; import java.util.Random; +import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; public class QuickSortTest { + + @BeforeClass(alwaysRun = true) + public void setUpJvOptionPane() + { + JvOptionPane.setInteractiveMode(false); + JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION); + } + private static final String c1 = "Blue"; private static final String c2 = "Yellow"; @@ -109,8 +120,9 @@ public class QuickSortTest String[] values = new String[] { "JOHN", "henry", "lucy", "henry", "ALISON" }; QuickSort.sort(values, things); - assertTrue(Arrays.equals(new String[] { "lucy", "henry", "henry", - "JOHN", "ALISON" }, values)); + assertTrue( + Arrays.equals(new String[] + { "lucy", "henry", "henry", "JOHN", "ALISON" }, values)); assertTrue(Arrays.equals(new Object[] { c3, c2, c4, c1, c5 }, things)); } @@ -125,8 +137,9 @@ public class QuickSortTest QuickSort.sort(values, letters); assertTrue(Arrays.equals(new int[] { 1, 2, 3, 4, 4 }, values)); // this fails - do we care? - assertTrue(Arrays.equals(new Object[] { "Z", "Y", "A", "X", "B" }, - letters)); + assertTrue( + Arrays.equals(new Object[] + { "Z", "Y", "A", "X", "B" }, letters)); } /** @@ -183,10 +196,9 @@ public class QuickSortTest QuickSort.sort(counts, residues); } long elapsed = System.currentTimeMillis() - start; - System.out - .println(String - .format("Time for %d optimised sorts of mostly zeros array length %d was %dms", - iterations, counts.length, elapsed)); + System.out.println(String.format( + "Time for %d optimised sorts of mostly zeros array length %d was %dms", + iterations, counts.length, elapsed)); /* * time it using unoptimised external sort @@ -201,10 +213,9 @@ public class QuickSortTest QuickSort.charSortByFloat(counts, residues, true); } elapsed = System.currentTimeMillis() - start; - System.out - .println(String - .format("Time for %d external sorts of mostly zeros array length %d was %dms", - iterations, counts.length, elapsed)); + System.out.println(String.format( + "Time for %d external sorts of mostly zeros array length %d was %dms", + iterations, counts.length, elapsed)); /* * optimised external sort, well-filled array @@ -223,10 +234,9 @@ public class QuickSortTest QuickSort.sort(counts, residues); } elapsed = System.currentTimeMillis() - start; - System.out - .println(String - .format("Time for %d optimised sorts of non-zeros array length %d was %dms", - iterations, counts.length, elapsed)); + System.out.println(String.format( + "Time for %d optimised sorts of non-zeros array length %d was %dms", + iterations, counts.length, elapsed)); /* * time unoptimised external sort, filled array @@ -238,10 +248,9 @@ public class QuickSortTest QuickSort.charSortByFloat(counts, residues, true); } elapsed = System.currentTimeMillis() - start; - System.out - .println(String - .format("Time for %d external sorts of non-zeros array length %d was %dms", - iterations, counts.length, elapsed)); + System.out.println(String.format( + "Time for %d external sorts of non-zeros array length %d was %dms", + iterations, counts.length, elapsed)); } /** @@ -346,16 +355,18 @@ public class QuickSortTest * sort descending */ QuickSort.sortByString(values, things, false); - assertTrue(Arrays.equals(new String[] { "lucy", "henry", "henry", - "JOHN", "ALISON" }, values)); + assertTrue( + Arrays.equals(new String[] + { "lucy", "henry", "henry", "JOHN", "ALISON" }, values)); assertTrue(Arrays.equals(new Object[] { c3, c2, c4, c1, c5 }, things)); /* * resort ascending */ QuickSort.sortByString(values, things, true); - assertTrue(Arrays.equals(new String[] { "ALISON", "JOHN", "henry", - "henry", "lucy" }, values)); + assertTrue( + Arrays.equals(new String[] + { "ALISON", "JOHN", "henry", "henry", "lucy" }, values)); // sort is stable: c2/c4 do not swap order assertTrue(Arrays.equals(new Object[] { c5, c1, c2, c4, c3 }, things)); }