Tests for race clock being scaled correctly added

#story[16] #test
main
Erika Savell 9 years ago
parent 944da81946
commit d23a80841a

@ -20,7 +20,7 @@ public abstract class Race implements Runnable {
protected int boatsFinished = 0;
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
protected int PRERACE_TIME = 10000;//Integer.MAX_VALUE; //time in milliseconds to pause during pre-race
@ -52,9 +52,13 @@ public abstract class Race implements Runnable {
}
public Race(BoatInRace[] boats, ArrayList<Leg> legs, int scaleFactor) {
if (boats.length > 0) {
for (BoatInRace boat : boats) {
if (boat != null) {
boat.setScaledVelocity(boat.getVelocity() * scaleFactor);
}
}
}
this.startingBoats = FXCollections.observableArrayList(boats);
this.legs = legs;
this.legs.add(new Leg("Finish", this.legs.size()));

@ -84,7 +84,8 @@ public class RaceTest {
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);
legs.add(leg2); legs.add(leg2);
legs.add(leg2);
legs.add(leg2);
ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[1], legs);
@ -114,7 +115,7 @@ public class RaceTest {
@Test
public void scalerScalesVelocityCorrectly() {
int scaleFactor = 0;
int scaleFactor = 3;
float vel1 = 0;
float vel2 = (float) 1.999;
float vel3 = (float) 32.5;
@ -126,9 +127,26 @@ public class RaceTest {
BoatInRace[] boats = new BoatInRace[]{boat1, boat2, boat3, boat4};
ConstantVelocityRace race = new ConstantVelocityRace(boats, new ArrayList<Leg>(), scaleFactor);
assertEquals(race.getStartingBoats().get(0).getScaledVelocity(), vel1 * scaleFactor, 1e-8);
assertEquals(race.getStartingBoats().get(1).getScaledVelocity(), vel2 * scaleFactor, 1e-8);
assertEquals(race.getStartingBoats().get(2).getScaledVelocity(), vel3 * scaleFactor, 1e-8);
assertEquals(race.getStartingBoats().get(3).getScaledVelocity(), vel4 * scaleFactor, 1e-8);
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);
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"));
}
}

Loading…
Cancel
Save