Skip to content

Commit

Permalink
Correctly handle when current-1 is negative. (#150)
Browse files Browse the repository at this point in the history
Truncation is towards 0, whereas we want floor.
  • Loading branch information
brian-brazil authored and frank-weinberg committed Sep 13, 2018
1 parent 6ece88b commit 584897b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,9 @@ protected boolean isDisplayChange(long current, long last) {
//the frontend rounds values that are not full seconds to the earlier second
//i.e. 3600ms will be displayed as 3s on a count up clock and as 4s on a count down clock.
if (isCountDirectionDown()) {
return ((current-1)/1000 != (last-1)/1000);
return Math.floor(((float)current-1)/1000) != Math.floor(((float)last-1)/1000);
} else {
return (current/1000 != last/1000);
return Math.floor((float)current/1000) != Math.floor((float)last/1000);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,24 @@ public void testRunning() {
advance(2000);
assertEquals(2000, clock.getTimeElapsed());
}

@Test
public void testRunningDownHasZeroTimeEvent() {
clock.setCountDirectionDown(true);
clock.setMaximumTime(1000);
clock.setTime(1000);

clock.addScoreBoardListener(new ConditionalScoreBoardListener(clock, Clock.EVENT_TIME, listener));
clock.start();
advance(200);
advance(200);
advance(200);
advance(200);
advance(200);
assertEquals(1, collectedEvents.size());
ScoreBoardEvent event = collectedEvents.poll();
assertEquals(0, ((Long)event.getValue()).longValue());
}

@Test
public void testStartNext() {
Expand Down

0 comments on commit 584897b

Please sign in to comment.