|
|
|
|
@ -16,6 +16,9 @@ import static org.junit.Assert.assertTrue;
|
|
|
|
|
public class RaceTest {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Leg START_LEG = new Leg("Start", new GPSCoordinate(0, 0), new GPSCoordinate(1, 1),
|
|
|
|
|
new GPSCoordinate(50, 50), new GPSCoordinate(51, 51), 0);
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void finishOrderDeterminedByVelocity() {
|
|
|
|
|
BoatInRace[] boats = {
|
|
|
|
|
@ -23,7 +26,9 @@ public class RaceTest {
|
|
|
|
|
new BoatInRace("AU", 2800, Color.BEIGE, "AU")
|
|
|
|
|
};
|
|
|
|
|
ArrayList<Leg> legs = new ArrayList<>();
|
|
|
|
|
legs.add(new Leg("Start", new GPSCoordinate(32.296577, -64.854304), new GPSCoordinate(32.293039, -64.843983), 0));
|
|
|
|
|
GPSCoordinate startCoord = new GPSCoordinate(32.296577, -64.854304);
|
|
|
|
|
GPSCoordinate endCoord = new GPSCoordinate(32.293039, -64.843983);
|
|
|
|
|
legs.add(new Leg("Start", startCoord, startCoord, endCoord, endCoord, 0));
|
|
|
|
|
legs.add(new Leg("Start", new GPSCoordinate(32.293039, -64.843983), new GPSCoordinate(32.284680, -64.850045), 1));
|
|
|
|
|
Race race = new ConstantVelocityRace(boats, legs, null, 1);
|
|
|
|
|
race.disableTimer();
|
|
|
|
|
@ -42,10 +47,14 @@ public class RaceTest {
|
|
|
|
|
|
|
|
|
|
BoatInRace finishedBoat = new BoatInRace("Test", 1000, Color.ALICEBLUE, "tt");
|
|
|
|
|
finishedBoat.setDistanceTravelledInLeg(500);
|
|
|
|
|
Leg leg = new Leg("Finish", new GPSCoordinate(0, 0), new GPSCoordinate(1, 1), 0);
|
|
|
|
|
Leg leg = new Leg("Finish", new GPSCoordinate(0, 0), new GPSCoordinate(0.5, 0.5),
|
|
|
|
|
new GPSCoordinate(1, 1), new GPSCoordinate(1.5, 1.5), 0);
|
|
|
|
|
finishedBoat.setCurrentLeg(leg);
|
|
|
|
|
|
|
|
|
|
ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[1], new ArrayList<Leg>(), null, 1);
|
|
|
|
|
ArrayList<Leg> legs = new ArrayList<>();
|
|
|
|
|
legs.add(leg);
|
|
|
|
|
|
|
|
|
|
ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[1], legs, null, 1);
|
|
|
|
|
assertEquals(race.boatsFinished, 0);
|
|
|
|
|
|
|
|
|
|
race.checkPosition(finishedBoat, 100);
|
|
|
|
|
@ -58,10 +67,14 @@ public class RaceTest {
|
|
|
|
|
|
|
|
|
|
BoatInRace unFinishedBoat = new BoatInRace("Test", 10, Color.ALICEBLUE, "tt");
|
|
|
|
|
unFinishedBoat.setDistanceTravelledInLeg(0);
|
|
|
|
|
Leg leg = new Leg("Finish", new GPSCoordinate(0, 0), new GPSCoordinate(1, 1), 0);
|
|
|
|
|
Leg leg = new Leg("Finish", new GPSCoordinate(0, 0), new GPSCoordinate(0.1, 0.1),
|
|
|
|
|
new GPSCoordinate(1, 1), new GPSCoordinate(1.1, 1.1), 0);
|
|
|
|
|
unFinishedBoat.setCurrentLeg(leg);
|
|
|
|
|
|
|
|
|
|
ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[1], new ArrayList<Leg>(), null, 1);
|
|
|
|
|
ArrayList<Leg> legs = new ArrayList<>();
|
|
|
|
|
legs.add(leg);
|
|
|
|
|
|
|
|
|
|
ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[1], legs, null, 1);
|
|
|
|
|
assertEquals(race.boatsFinished, 0);
|
|
|
|
|
|
|
|
|
|
race.checkPosition(unFinishedBoat, 100);
|
|
|
|
|
@ -74,10 +87,12 @@ public class RaceTest {
|
|
|
|
|
|
|
|
|
|
ArrayList<Leg> legs = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
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 leg1 = new Leg("1", new GPSCoordinate(0, 0), new GPSCoordinate(0.5, 0.5),
|
|
|
|
|
new GPSCoordinate(1, 1), new GPSCoordinate(1.5, 1.5), 0);
|
|
|
|
|
Leg leg2 = new Leg("2", new GPSCoordinate(0, 0), new GPSCoordinate(0.5, 0.5),
|
|
|
|
|
new GPSCoordinate(1, 1), new GPSCoordinate(1.5, 1.5), 1);
|
|
|
|
|
|
|
|
|
|
legs.add(leg2);
|
|
|
|
|
legs.add(leg1);
|
|
|
|
|
legs.add(leg2);
|
|
|
|
|
|
|
|
|
|
ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[1], legs, null, 1);
|
|
|
|
|
@ -95,7 +110,11 @@ public class RaceTest {
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void timerDelaysByHalfSecond() {
|
|
|
|
|
ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[1], new ArrayList<>(), null, 1);
|
|
|
|
|
|
|
|
|
|
ArrayList<Leg> legs = new ArrayList<>();
|
|
|
|
|
legs.add(START_LEG);
|
|
|
|
|
|
|
|
|
|
ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[1], legs, null, 1);
|
|
|
|
|
race.PRERACE_TIME = 500;
|
|
|
|
|
|
|
|
|
|
long timeStarted = System.currentTimeMillis();
|
|
|
|
|
@ -119,7 +138,10 @@ public class RaceTest {
|
|
|
|
|
BoatInRace boat4 = new BoatInRace("test", vel4, Color.ALICEBLUE, "tt");
|
|
|
|
|
BoatInRace[] boats = new BoatInRace[]{boat1, boat2, boat3, boat4};
|
|
|
|
|
|
|
|
|
|
ConstantVelocityRace race = new ConstantVelocityRace(boats, new ArrayList<Leg>(), null, scaleFactor);
|
|
|
|
|
ArrayList<Leg> legs = new ArrayList<>();
|
|
|
|
|
legs.add(START_LEG);
|
|
|
|
|
|
|
|
|
|
ConstantVelocityRace race = new ConstantVelocityRace(boats, legs, null, scaleFactor);
|
|
|
|
|
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);
|
|
|
|
|
@ -129,7 +151,11 @@ public class RaceTest {
|
|
|
|
|
@Test
|
|
|
|
|
public void scalerScalesRaceClockTo1MinCorrectly() {
|
|
|
|
|
int scaleFactor = 10;
|
|
|
|
|
ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[5], new ArrayList<Leg>(), null, scaleFactor);
|
|
|
|
|
|
|
|
|
|
ArrayList<Leg> legs = new ArrayList<>();
|
|
|
|
|
legs.add(START_LEG);
|
|
|
|
|
|
|
|
|
|
ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[5], legs, null, scaleFactor);
|
|
|
|
|
race.totalTimeElapsed = 6000; //6 seconds
|
|
|
|
|
assertTrue(race.calcTimer().equals("Race clock: 00:01:00"));
|
|
|
|
|
}
|
|
|
|
|
@ -137,7 +163,10 @@ public class RaceTest {
|
|
|
|
|
@Test
|
|
|
|
|
public void scalerScalesRaceClockHoursMinutesAndSecondsCorrectly() {
|
|
|
|
|
int scaleFactor = 3;
|
|
|
|
|
ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[5], new ArrayList<Leg>(), null, scaleFactor);
|
|
|
|
|
ArrayList<Leg> legs = new ArrayList<>();
|
|
|
|
|
legs.add(START_LEG);
|
|
|
|
|
|
|
|
|
|
ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[5], legs, null, scaleFactor);
|
|
|
|
|
race.totalTimeElapsed = 3213000;
|
|
|
|
|
assertTrue(race.calcTimer().equals("Race clock: 02:40:39"));
|
|
|
|
|
|
|
|
|
|
|