Skip to content

Commit

Permalink
preventing non-deterministic test failure in RelativeIso8601DateTest #…
Browse files Browse the repository at this point in the history
…578 (#710)

adding a delta to the asserts in RelativeIso8601DateTest to fix #578
  • Loading branch information
magicDGS authored and lbergelson committed Oct 24, 2016
1 parent 7ab2531 commit b497630
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/test/java/htsjdk/samtools/util/RelativeIso8601DateTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand All @@ -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());
}
Expand All @@ -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.