|
|
|
|
@ -15,164 +15,149 @@ import static org.junit.Assert.assertTrue;
|
|
|
|
|
* Created by esa46 on 15/03/17.
|
|
|
|
|
*/
|
|
|
|
|
public class RaceTest {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Leg START_LEG = new Leg("Start", new Marker(new GPSCoordinate(0, 0)), new Marker(new GPSCoordinate(1, 1)), 0);
|
|
|
|
|
Leg FINISH_LEG = new Leg("Finish", new Marker(new GPSCoordinate(1, 1)), new Marker(new GPSCoordinate(2, 2)), 0);
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void timerCanBeDisabled() {
|
|
|
|
|
BoatInRace boat1 = new BoatInRace("Test 1", 10000, Color.ALICEBLUE, "t1");
|
|
|
|
|
BoatInRace boat2 = new BoatInRace("Test 2", 10000, Color.BURLYWOOD, "t2");
|
|
|
|
|
BoatInRace[] boats = new BoatInRace[]{boat1, boat2};
|
|
|
|
|
|
|
|
|
|
ArrayList<Leg> legs = new ArrayList<>();
|
|
|
|
|
legs.add(START_LEG); legs.add(FINISH_LEG);
|
|
|
|
|
|
|
|
|
|
Race race = new ConstantVelocityRace(boats, legs, null, 5);
|
|
|
|
|
race.disableTimer();
|
|
|
|
|
long timeStarted = System.currentTimeMillis();
|
|
|
|
|
race.run();
|
|
|
|
|
|
|
|
|
|
assertTrue(System.currentTimeMillis() - timeStarted < 4000);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void checkPositionUpdatesNumberFinishedBoats() {
|
|
|
|
|
|
|
|
|
|
BoatInRace finishedBoat = new BoatInRace("Test", 1000, Color.ALICEBLUE, "tt");
|
|
|
|
|
finishedBoat.setDistanceTravelledInLeg(500);
|
|
|
|
|
|
|
|
|
|
finishedBoat.setCurrentLeg(FINISH_LEG);
|
|
|
|
|
|
|
|
|
|
ArrayList<Leg> legs = new ArrayList<>();
|
|
|
|
|
legs.add(FINISH_LEG);
|
|
|
|
|
|
|
|
|
|
ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[1], legs, null, 1);
|
|
|
|
|
assertEquals(race.boatsFinished, 0);
|
|
|
|
|
|
|
|
|
|
race.checkPosition(finishedBoat, 100000);
|
|
|
|
|
assertEquals(race.boatsFinished, 1);
|
|
|
|
|
assertEquals(finishedBoat.getTimeFinished(), 100000);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void checkPositionDoesntUpdateNumberFinishedBoats() {
|
|
|
|
|
|
|
|
|
|
BoatInRace unFinishedBoat = new BoatInRace("Test", 10, Color.ALICEBLUE, "tt");
|
|
|
|
|
unFinishedBoat.setDistanceTravelledInLeg(0);
|
|
|
|
|
|
|
|
|
|
unFinishedBoat.setCurrentLeg(FINISH_LEG);
|
|
|
|
|
|
|
|
|
|
ArrayList<Leg> legs = new ArrayList<>();
|
|
|
|
|
legs.add(FINISH_LEG);
|
|
|
|
|
|
|
|
|
|
ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[1], legs, null, 1);
|
|
|
|
|
assertEquals(race.boatsFinished, 0);
|
|
|
|
|
|
|
|
|
|
race.checkPosition(unFinishedBoat, 100);
|
|
|
|
|
assertEquals(race.boatsFinished, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void distanceTravelledBeforeUpdatingLegIsRetained() {
|
|
|
|
|
|
|
|
|
|
ArrayList<Leg> legs = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Leg START_LEG = new Leg("Start", new GPSCoordinate(0, 0), new GPSCoordinate(1, 1),
|
|
|
|
|
// new GPSCoordinate(50, 50), new GPSCoordinate(51, 51), 0);
|
|
|
|
|
//
|
|
|
|
|
// @Test
|
|
|
|
|
// @Ignore
|
|
|
|
|
// public void finishOrderDeterminedByVelocity() {
|
|
|
|
|
// BoatInRace[] boats = {
|
|
|
|
|
// new BoatInRace("NZ", 2000, Color.BEIGE, "NZ"),
|
|
|
|
|
// new BoatInRace("AU", 2800, Color.BEIGE, "AU")
|
|
|
|
|
// };
|
|
|
|
|
// ArrayList<Leg> legs = new ArrayList<>();
|
|
|
|
|
// 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();
|
|
|
|
|
//
|
|
|
|
|
// // Boats should finish in an order determined by their velocity
|
|
|
|
|
// Arrays.sort(boats, (a, b) -> (int) (b.getVelocity() - a.getVelocity()));
|
|
|
|
|
// race.run();
|
|
|
|
|
//
|
|
|
|
|
// for (int i = 0; i < boats.length; i++)
|
|
|
|
|
// assertTrue(boats[i].equals(race.getStartingBoats().get(i)));
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
// @Test
|
|
|
|
|
// public void checkPositionUpdatesNumberFinishedBoats() {
|
|
|
|
|
//
|
|
|
|
|
// BoatInRace finishedBoat = new BoatInRace("Test", 1000, Color.ALICEBLUE, "tt");
|
|
|
|
|
// finishedBoat.setDistanceTravelledInLeg(500);
|
|
|
|
|
// 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);
|
|
|
|
|
//
|
|
|
|
|
// 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);
|
|
|
|
|
// assertEquals(race.boatsFinished, 1);
|
|
|
|
|
// assertEquals(finishedBoat.getTimeFinished(), 100);
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// @Test
|
|
|
|
|
// public void checkPositionDoesntUpdateNumberFinishedBoats() {
|
|
|
|
|
//
|
|
|
|
|
// BoatInRace unFinishedBoat = new BoatInRace("Test", 10, Color.ALICEBLUE, "tt");
|
|
|
|
|
// unFinishedBoat.setDistanceTravelledInLeg(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);
|
|
|
|
|
//
|
|
|
|
|
// 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);
|
|
|
|
|
// assertEquals(race.boatsFinished, 0);
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
// @Test
|
|
|
|
|
// public void distanceTravelledBeforeUpdatingLegIsRetained() {
|
|
|
|
|
//
|
|
|
|
|
// ArrayList<Leg> legs = new ArrayList<>();
|
|
|
|
|
//
|
|
|
|
|
// 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(leg1);
|
|
|
|
|
// legs.add(leg2);
|
|
|
|
|
//
|
|
|
|
|
// ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[1], legs, null, 1);
|
|
|
|
|
//
|
|
|
|
|
// BoatInRace unFinishedBoat = new BoatInRace("Test", 10, Color.ALICEBLUE, "tt");
|
|
|
|
|
// unFinishedBoat.setDistanceTravelledInLeg(100);
|
|
|
|
|
// unFinishedBoat.setCurrentLeg(leg1);
|
|
|
|
|
//
|
|
|
|
|
// race.checkPosition(unFinishedBoat, 100);
|
|
|
|
|
// assertEquals(unFinishedBoat.getCurrentLeg().getName(), "2");
|
|
|
|
|
// assertTrue(unFinishedBoat.getDistanceTravelledInLeg() > 0);
|
|
|
|
|
// assertTrue(unFinishedBoat.getDistanceTravelledInLeg() < 100);
|
|
|
|
|
//
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// @Test
|
|
|
|
|
// public void timerDelaysByHalfSecond() {
|
|
|
|
|
//
|
|
|
|
|
// 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();
|
|
|
|
|
// race.countdownTimer();
|
|
|
|
|
//
|
|
|
|
|
// assertTrue(System.currentTimeMillis() - timeStarted > 500);
|
|
|
|
|
//
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// @Test
|
|
|
|
|
// public void scalerScalesVelocityCorrectly() {
|
|
|
|
|
//
|
|
|
|
|
// int scaleFactor = 3;
|
|
|
|
|
// float vel1 = 0;
|
|
|
|
|
// float vel2 = (float) 1.999;
|
|
|
|
|
// float vel3 = (float) 32.5;
|
|
|
|
|
// float vel4 = 500;
|
|
|
|
|
// BoatInRace boat1 = new BoatInRace("test", vel1, Color.ALICEBLUE, "tt");
|
|
|
|
|
// BoatInRace boat2 = new BoatInRace("test", vel2, Color.ALICEBLUE, "tt");
|
|
|
|
|
// BoatInRace boat3 = new BoatInRace("test", vel3, Color.ALICEBLUE, "tt");
|
|
|
|
|
// BoatInRace boat4 = new BoatInRace("test", vel4, Color.ALICEBLUE, "tt");
|
|
|
|
|
// BoatInRace[] boats = new BoatInRace[]{boat1, boat2, boat3, boat4};
|
|
|
|
|
//
|
|
|
|
|
// 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);
|
|
|
|
|
// assertEquals(race.getStartingBoats().get(3).getScaledVelocity(), vel4 * scaleFactor, 1e-6);
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// @Test
|
|
|
|
|
// public void scalerScalesRaceClockTo1MinCorrectly() {
|
|
|
|
|
// int scaleFactor = 10;
|
|
|
|
|
//
|
|
|
|
|
// 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"));
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// @Test
|
|
|
|
|
// public void scalerScalesRaceClockHoursMinutesAndSecondsCorrectly() {
|
|
|
|
|
// int scaleFactor = 3;
|
|
|
|
|
// 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"));
|
|
|
|
|
//
|
|
|
|
|
// }
|
|
|
|
|
//}
|
|
|
|
|
legs.add(START_LEG);
|
|
|
|
|
legs.add(FINISH_LEG);
|
|
|
|
|
|
|
|
|
|
ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[1], legs, null, 1);
|
|
|
|
|
|
|
|
|
|
BoatInRace unFinishedBoat = new BoatInRace("Test", 10, Color.ALICEBLUE, "tt");
|
|
|
|
|
unFinishedBoat.setDistanceTravelledInLeg(100);
|
|
|
|
|
unFinishedBoat.setCurrentLeg(START_LEG);
|
|
|
|
|
|
|
|
|
|
race.checkPosition(unFinishedBoat, 100);
|
|
|
|
|
assertEquals(unFinishedBoat.getCurrentLeg().getName(), "Finish");
|
|
|
|
|
assertTrue(unFinishedBoat.getDistanceTravelledInLeg() > 0);
|
|
|
|
|
assertTrue(unFinishedBoat.getDistanceTravelledInLeg() < 100);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void timerDelaysByHalfSecond() {
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
race.countdownTimer();
|
|
|
|
|
|
|
|
|
|
assertTrue(System.currentTimeMillis() - timeStarted > 500);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void scalerScalesVelocityCorrectly() {
|
|
|
|
|
|
|
|
|
|
int scaleFactor = 3;
|
|
|
|
|
float vel1 = 0;
|
|
|
|
|
float vel2 = (float) 1.999;
|
|
|
|
|
float vel3 = (float) 32.5;
|
|
|
|
|
float vel4 = 500;
|
|
|
|
|
BoatInRace boat1 = new BoatInRace("test", vel1, Color.ALICEBLUE, "tt");
|
|
|
|
|
BoatInRace boat2 = new BoatInRace("test", vel2, Color.ALICEBLUE, "tt");
|
|
|
|
|
BoatInRace boat3 = new BoatInRace("test", vel3, Color.ALICEBLUE, "tt");
|
|
|
|
|
BoatInRace boat4 = new BoatInRace("test", vel4, Color.ALICEBLUE, "tt");
|
|
|
|
|
BoatInRace[] boats = new BoatInRace[]{boat1, boat2, boat3, boat4};
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
assertEquals(race.getStartingBoats().get(3).getScaledVelocity(), vel4 * scaleFactor, 1e-6);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void scalerScalesRaceClockTo1MinCorrectly() {
|
|
|
|
|
int scaleFactor = 10;
|
|
|
|
|
|
|
|
|
|
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"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void scalerScalesRaceClockHoursMinutesAndSecondsCorrectly() {
|
|
|
|
|
int scaleFactor = 3;
|
|
|
|
|
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"));
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|