Tests for race clock being scaled correctly added
#story[16] #test
This commit is contained in:
@@ -20,7 +20,7 @@ public abstract class Race implements Runnable {
|
|||||||
protected int boatsFinished = 0;
|
protected int boatsFinished = 0;
|
||||||
protected long totalTimeElapsed;
|
protected long totalTimeElapsed;
|
||||||
|
|
||||||
protected int scaleFactor = 1;
|
protected int scaleFactor = 15;
|
||||||
|
|
||||||
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
|
||||||
protected 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
|
||||||
@@ -52,8 +52,12 @@ public abstract class Race implements Runnable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Race(BoatInRace[] boats, ArrayList<Leg> legs, int scaleFactor) {
|
public Race(BoatInRace[] boats, ArrayList<Leg> legs, int scaleFactor) {
|
||||||
for (BoatInRace boat : boats) {
|
if (boats.length > 0) {
|
||||||
boat.setScaledVelocity(boat.getVelocity() * scaleFactor);
|
for (BoatInRace boat : boats) {
|
||||||
|
if (boat != null) {
|
||||||
|
boat.setScaledVelocity(boat.getVelocity() * scaleFactor);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
this.startingBoats = FXCollections.observableArrayList(boats);
|
this.startingBoats = FXCollections.observableArrayList(boats);
|
||||||
this.legs = legs;
|
this.legs = legs;
|
||||||
|
|||||||
@@ -30,16 +30,16 @@ public class RaceTest {
|
|||||||
new BoatInRace("AU", 2800, Color.BEIGE, "AU")
|
new BoatInRace("AU", 2800, Color.BEIGE, "AU")
|
||||||
};
|
};
|
||||||
ArrayList<Leg> legs = new ArrayList<>();
|
ArrayList<Leg> legs = new ArrayList<>();
|
||||||
legs.add(new Leg("Start", new GPSCoordinate(32.296577, -64.854304),new GPSCoordinate(32.293039, -64.843983),0));
|
legs.add(new Leg("Start", new GPSCoordinate(32.296577, -64.854304), new GPSCoordinate(32.293039, -64.843983), 0));
|
||||||
legs.add(new Leg("Start", new GPSCoordinate(32.293039, -64.843983),new GPSCoordinate(32.284680, -64.850045),1));
|
legs.add(new Leg("Start", new GPSCoordinate(32.293039, -64.843983), new GPSCoordinate(32.284680, -64.850045), 1));
|
||||||
Race race = new ConstantVelocityRace(boats, legs);
|
Race race = new ConstantVelocityRace(boats, legs);
|
||||||
race.disableTimer();
|
race.disableTimer();
|
||||||
|
|
||||||
// Boats should finish in an order determined by their velocity
|
// Boats should finish in an order determined by their velocity
|
||||||
Arrays.sort(boats, (a,b) -> (int)(b.getVelocity()-a.getVelocity()));
|
Arrays.sort(boats, (a, b) -> (int) (b.getVelocity() - a.getVelocity()));
|
||||||
race.run();
|
race.run();
|
||||||
|
|
||||||
for(int i = 0; i < boats.length; i++)
|
for (int i = 0; i < boats.length; i++)
|
||||||
assertTrue(boats[i].equals(race.getStartingBoats().get(i)));
|
assertTrue(boats[i].equals(race.getStartingBoats().get(i)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,7 +84,8 @@ public class RaceTest {
|
|||||||
Leg leg1 = new Leg("1", new GPSCoordinate(0, 0), new GPSCoordinate(1, 1), 0);
|
Leg leg1 = new Leg("1", new GPSCoordinate(0, 0), new GPSCoordinate(1, 1), 0);
|
||||||
Leg leg2 = new Leg("2", new GPSCoordinate(0, 0), new GPSCoordinate(1, 1), 1);
|
Leg leg2 = new Leg("2", new GPSCoordinate(0, 0), new GPSCoordinate(1, 1), 1);
|
||||||
|
|
||||||
legs.add(leg2); legs.add(leg2);
|
legs.add(leg2);
|
||||||
|
legs.add(leg2);
|
||||||
|
|
||||||
ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[1], legs);
|
ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[1], legs);
|
||||||
|
|
||||||
@@ -114,7 +115,7 @@ public class RaceTest {
|
|||||||
@Test
|
@Test
|
||||||
public void scalerScalesVelocityCorrectly() {
|
public void scalerScalesVelocityCorrectly() {
|
||||||
|
|
||||||
int scaleFactor = 0;
|
int scaleFactor = 3;
|
||||||
float vel1 = 0;
|
float vel1 = 0;
|
||||||
float vel2 = (float) 1.999;
|
float vel2 = (float) 1.999;
|
||||||
float vel3 = (float) 32.5;
|
float vel3 = (float) 32.5;
|
||||||
@@ -123,12 +124,29 @@ public class RaceTest {
|
|||||||
BoatInRace boat2 = new BoatInRace("test", vel2, Color.ALICEBLUE, "tt");
|
BoatInRace boat2 = new BoatInRace("test", vel2, Color.ALICEBLUE, "tt");
|
||||||
BoatInRace boat3 = new BoatInRace("test", vel3, Color.ALICEBLUE, "tt");
|
BoatInRace boat3 = new BoatInRace("test", vel3, Color.ALICEBLUE, "tt");
|
||||||
BoatInRace boat4 = new BoatInRace("test", vel4, Color.ALICEBLUE, "tt");
|
BoatInRace boat4 = new BoatInRace("test", vel4, Color.ALICEBLUE, "tt");
|
||||||
BoatInRace[] boats = new BoatInRace[] {boat1, boat2, boat3, boat4};
|
BoatInRace[] boats = new BoatInRace[]{boat1, boat2, boat3, boat4};
|
||||||
|
|
||||||
ConstantVelocityRace race = new ConstantVelocityRace(boats, new ArrayList<Leg>(), scaleFactor);
|
ConstantVelocityRace race = new ConstantVelocityRace(boats, new ArrayList<Leg>(), scaleFactor);
|
||||||
assertEquals(race.getStartingBoats().get(0).getScaledVelocity(), vel1 * scaleFactor, 1e-8);
|
assertEquals(race.getStartingBoats().get(0).getScaledVelocity(), vel1 * scaleFactor, 1e-6);
|
||||||
assertEquals(race.getStartingBoats().get(1).getScaledVelocity(), vel2 * scaleFactor, 1e-8);
|
assertEquals(race.getStartingBoats().get(1).getScaledVelocity(), vel2 * scaleFactor, 1e-6);
|
||||||
assertEquals(race.getStartingBoats().get(2).getScaledVelocity(), vel3 * scaleFactor, 1e-8);
|
assertEquals(race.getStartingBoats().get(2).getScaledVelocity(), vel3 * scaleFactor, 1e-6);
|
||||||
assertEquals(race.getStartingBoats().get(3).getScaledVelocity(), vel4 * scaleFactor, 1e-8);
|
assertEquals(race.getStartingBoats().get(3).getScaledVelocity(), vel4 * scaleFactor, 1e-6);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void scalerScalesRaceClockTo1MinCorrectly() {
|
||||||
|
int scaleFactor = 10;
|
||||||
|
ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[5], new ArrayList<Leg>(), scaleFactor);
|
||||||
|
race.totalTimeElapsed = 6000; //6 seconds
|
||||||
|
assertTrue(race.calcTimer().equals("Race clock: 00:01:00"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void scalerScalesRaceClockHoursMinutesAndSecondsCorrectly() {
|
||||||
|
int scaleFactor = 3;
|
||||||
|
ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[5], new ArrayList<Leg>(), scaleFactor);
|
||||||
|
race.totalTimeElapsed = 3213000;
|
||||||
|
assertTrue(race.calcTimer().equals("Race clock: 02:40:39"));
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user