Fixed testing problem where race tests would sometimes fail because a boat did not finish
- Added an option to set the dnf chance, then set it to 0 is all tests #story[760]
This commit is contained in:
@@ -24,6 +24,7 @@ public abstract class Race implements Runnable {
|
||||
protected RaceController controller;
|
||||
protected int boatsFinished = 0;
|
||||
protected long totalTimeElapsed;
|
||||
private int dnfChance = 1; //%percentage chance a boat fails at each checkpoint
|
||||
|
||||
private int lastFPS = 20;
|
||||
|
||||
@@ -54,6 +55,16 @@ public abstract class Race implements Runnable {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the chance each boat has of failing at a gate or marker
|
||||
* @param chance percentage chance a boat has of failing per checkpoint.
|
||||
*/
|
||||
protected void setDnfChance(int chance) {
|
||||
if (chance >= 0 && chance <= 100) {
|
||||
dnfChance = chance;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void initialiseBoats() {
|
||||
|
||||
@@ -174,7 +185,7 @@ public abstract class Race implements Runnable {
|
||||
|
||||
private boolean doNotFinish() {
|
||||
Random rand = new Random();
|
||||
return rand.nextInt(4) < 1;
|
||||
return rand.nextInt(100) < dnfChance;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -31,6 +31,7 @@ public class RaceTest {
|
||||
|
||||
Race race = new ConstantVelocityRace(boats, legs, null, 5);
|
||||
race.disableTimer();
|
||||
race.setDnfChance(0);
|
||||
long timeStarted = System.currentTimeMillis();
|
||||
race.run();
|
||||
|
||||
@@ -49,8 +50,10 @@ public class RaceTest {
|
||||
legs.add(FINISH_LEG);
|
||||
|
||||
ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[1], legs, null, 1);
|
||||
race.setDnfChance(0);
|
||||
assertEquals(race.boatsFinished, 0);
|
||||
|
||||
|
||||
race.checkPosition(finishedBoat, 100000);
|
||||
assertEquals(race.boatsFinished, 1);
|
||||
assertEquals(finishedBoat.getTimeFinished(), 100000);
|
||||
@@ -68,6 +71,7 @@ public class RaceTest {
|
||||
legs.add(FINISH_LEG);
|
||||
|
||||
ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[1], legs, null, 1);
|
||||
race.setDnfChance(0);
|
||||
assertEquals(race.boatsFinished, 0);
|
||||
|
||||
race.checkPosition(unFinishedBoat, 100);
|
||||
@@ -84,6 +88,7 @@ public class RaceTest {
|
||||
legs.add(FINISH_LEG);
|
||||
|
||||
ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[1], legs, null, 1);
|
||||
race.setDnfChance(0);
|
||||
|
||||
BoatInRace unFinishedBoat = new BoatInRace("Test", 10, Color.ALICEBLUE, "tt");
|
||||
unFinishedBoat.setDistanceTravelledInLeg(100);
|
||||
@@ -134,6 +139,8 @@ public class RaceTest {
|
||||
legs.add(START_LEG);
|
||||
|
||||
ConstantVelocityRace race = new ConstantVelocityRace(boats, legs, null, scaleFactor);
|
||||
race.setDnfChance(0);
|
||||
|
||||
assertEquals(race.getStartingBoats().get(0).getScaledVelocity(), vel1 * scaleFactor, 1e-6);
|
||||
assertEquals(race.getStartingBoats().get(1).getScaledVelocity(), vel2 * scaleFactor, 1e-6);
|
||||
assertEquals(race.getStartingBoats().get(2).getScaledVelocity(), vel3 * scaleFactor, 1e-6);
|
||||
|
||||
Reference in New Issue
Block a user