Added a small test for the timer function
-More needed once scaling is in effect #test #story[16]
This commit is contained in:
@@ -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 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;
|
||||
|
||||
/**
|
||||
@@ -80,7 +80,7 @@ public abstract class Race implements Runnable {
|
||||
}
|
||||
|
||||
|
||||
private void countdownTimer() {
|
||||
protected void countdownTimer() {
|
||||
long currentTime = System.currentTimeMillis();
|
||||
long startTime = currentTime + PRERACE_TIME;
|
||||
long minutes;
|
||||
@@ -97,7 +97,9 @@ public abstract class Race implements Runnable {
|
||||
remainingSeconds = currentTimeInSeconds % 60;
|
||||
hours = 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 {
|
||||
timeLoopEnded = System.currentTimeMillis();
|
||||
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 currentTimeInSeconds;
|
||||
long remainingSeconds;
|
||||
@@ -122,7 +124,7 @@ public abstract class Race implements Runnable {
|
||||
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);});
|
||||
}
|
||||
|
||||
@@ -98,4 +98,16 @@ public class RaceTest {
|
||||
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);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user