Permalink
Browse files

preventing non-deterministic test failure in RelativeIso8601DateTest #…

…578 (#710)

adding a delta to the asserts in RelativeIso8601DateTest to fix #578
  • Loading branch information...
1 parent 7ab2531 commit b49763096bbf7544ebdc1ac9d2294ecf7ce8b1d9 @magicDGS magicDGS committed with lbergelson Oct 24, 2016
Showing with 7 additions and 3 deletions.
  1. +7 −3 src/test/java/htsjdk/samtools/util/RelativeIso8601DateTest.java
@@ -10,13 +10,17 @@
/** @author mccowan */
public class RelativeIso8601DateTest {
+
+ // 1 second resolution is ISO date
+ private final static double DELTA_FOR_TIME = 1000;
+
@Test
public void testLazyInstance() {
final RelativeIso8601Date lazy = RelativeIso8601Date.generateLazyNowInstance();
Assert.assertEquals(lazy.toString(), RelativeIso8601Date.LAZY_NOW_LABEL);
Assert.assertEquals(lazy.toString(), RelativeIso8601Date.LAZY_NOW_LABEL);
Assert.assertEquals(lazy.toString(), RelativeIso8601Date.LAZY_NOW_LABEL);
- Assert.assertEquals(lazy.getTime(), new Iso8601Date(new Date(System.currentTimeMillis())).getTime(), 1000); // 1 second resolution is ISO date
+ Assert.assertEquals(lazy.getTime(), new Iso8601Date(new Date(System.currentTimeMillis())).getTime(), DELTA_FOR_TIME);
// Assert no exception thrown; this should be valid, because toString should now return an iso-looking date.
new Iso8601Date(lazy.toString());
}
@@ -33,7 +37,7 @@ public void testNonLazyInstance() {
for (final RelativeIso8601Date nonLazy : testDates) {
Assert.assertFalse(nonLazy.toString().equals(RelativeIso8601Date.LAZY_NOW_LABEL));
- Assert.assertEquals((double) nonLazy.getTime(), (double) time);
+ Assert.assertEquals((double) nonLazy.getTime(), (double) time, DELTA_FOR_TIME);
// Assert no exception thrown; this should be valid, because toString return an iso-looking date.
new RelativeIso8601Date(nonLazy.toString());
}
@@ -44,6 +48,6 @@ public void equalityTest() {
final String s = new Iso8601Date(new Date(12345)).toString();
final Iso8601Date iso8601Date = new Iso8601Date(s);
final RelativeIso8601Date relativeIso8601Date = new RelativeIso8601Date(s);
- Assert.assertEquals(relativeIso8601Date.getTime(), iso8601Date.getTime());
+ Assert.assertEquals(relativeIso8601Date.getTime(), iso8601Date.getTime(), DELTA_FOR_TIME);
}
}

0 comments on commit b497630

Please sign in to comment.