Test the ordering of a set of objects. They should be ordered strictly monotonicly in the array. Also checks consistency of equals and hashCode with the ordering. This is the generic version. @param ator a comparator to use when doing test. @param compare an array of objects which should be in stric
(final Comparator<T> ator, final T[] compare, final boolean checkHash)
| 300 | * @param <T> type to compare. |
| 301 | */ |
| 302 | public static <T> void testOrder(final Comparator<T> ator, final T[] compare, final boolean checkHash) { |
| 303 | for (int i = 0; i < compare.length; ++i) { |
| 304 | for (int j = 0; j < i; ++j) { |
| 305 | //System.err.println(i+":"+j); |
| 306 | Assert.assertTrue(ator + ":" + compare[j] + ":" + compare[i], ator.compare(compare[j], compare[i]) < 0); |
| 307 | Assert.assertFalse(compare[j].equals(compare[i])); |
| 308 | Assert.assertTrue(String.valueOf(ator.compare(compare[i], compare[j])), ator.compare(compare[i], compare[j]) > 0); |
| 309 | Assert.assertFalse(compare[i].equals(compare[j])); |
| 310 | if (checkHash) { |
| 311 | Assert.assertFalse(compare[i].hashCode() == compare[j].hashCode()); |
| 312 | } |
| 313 | } |
| 314 | Assert.assertEquals(0, ator.compare(compare[i], compare[i])); |
| 315 | Assert.assertTrue(compare[i].equals(compare[i])); |
| 316 | Assert.assertFalse(compare[i].equals(null)); |
| 317 | } |
| 318 | } |
| 319 | |
| 320 | /** |
| 321 | * Test the ordering of a set of comparable objects. |
no test coverage detected