Added a small test for the timer function

-More needed once scaling is in effect

#test #story[16]
main
Erika Savell 9 years ago
parent 1c6bed7f37
commit 4c82a4594e

@ -25,7 +25,7 @@ public abstract class Race implements Runnable {
private int SLEEP_TIME = 100; //time in milliseconds to pause in a paced loop private int SLEEP_TIME = 100; //time in milliseconds to pause in a paced loop
private int PRERACE_TIME = 10000;//Integer.MAX_VALUE; //time in milliseconds to pause during pre-race protected int PRERACE_TIME = 10000;//Integer.MAX_VALUE; //time in milliseconds to pause during pre-race
private boolean timerEnabled = true; private boolean timerEnabled = true;
/** /**
@ -80,7 +80,7 @@ public abstract class Race implements Runnable {
} }
private void countdownTimer() { protected void countdownTimer() {
long currentTime = System.currentTimeMillis(); long currentTime = System.currentTimeMillis();
long startTime = currentTime + PRERACE_TIME; long startTime = currentTime + PRERACE_TIME;
long minutes; long minutes;
@ -97,7 +97,9 @@ public abstract class Race implements Runnable {
remainingSeconds = currentTimeInSeconds % 60; remainingSeconds = currentTimeInSeconds % 60;
hours = minutes / 60; hours = minutes / 60;
minutes = minutes % 60; minutes = minutes % 60;
updateTime(String.format("Time until race starts: %02d:%02d:%02d", hours, minutes, remainingSeconds)); if (controller != null) {
updateTime(String.format("Time until race starts: %02d:%02d:%02d", hours, minutes, remainingSeconds));
}
try { try {
timeLoopEnded = System.currentTimeMillis(); timeLoopEnded = System.currentTimeMillis();
Thread.sleep(SLEEP_TIME - (timeLoopEnded - currentTime)); Thread.sleep(SLEEP_TIME - (timeLoopEnded - currentTime));
@ -108,7 +110,7 @@ public abstract class Race implements Runnable {
} }
} }
private String calcTimer() { protected String calcTimer() {
long minutes; long minutes;
long currentTimeInSeconds; long currentTimeInSeconds;
long remainingSeconds; long remainingSeconds;
@ -122,7 +124,7 @@ public abstract class Race implements Runnable {
return String.format("Race clock: %02d:%02d:%02d", hours, minutes, remainingSeconds); return String.format("Race clock: %02d:%02d:%02d", hours, minutes, remainingSeconds);
} }
private void updateTime(String time){ protected void updateTime(String time){
Platform.runLater(() -> {controller.setTimer(time);}); Platform.runLater(() -> {controller.setTimer(time);});
} }

@ -98,4 +98,16 @@ public class RaceTest {
assertTrue(unFinishedBoat.getDistanceTravelledInLeg() < 100); assertTrue(unFinishedBoat.getDistanceTravelledInLeg() < 100);
} }
@Test
public void timerDelaysByHalfSecond() {
ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[1], new ArrayList<>());
race.PRERACE_TIME = 500;
long timeStarted = System.currentTimeMillis();
race.countdownTimer();
assertTrue(System.currentTimeMillis() - timeStarted > 500);
}
} }

Loading…
Cancel
Save