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";
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));
}
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));
}
/**
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
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
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
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));
}
/**
* 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));
}