|
|
|
|
@ -18,179 +18,179 @@ 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);
|
|
|
|
|
|
|
|
|
|
@Ignore
|
|
|
|
|
@Test
|
|
|
|
|
public void timerCanBeDisabled() {
|
|
|
|
|
BoatInRace boat1 = new BoatInRace("Test 1", 10000, Color.ALICEBLUE, "t1", 1);
|
|
|
|
|
BoatInRace boat2 = new BoatInRace("Test 2", 10000, Color.BURLYWOOD, "t2", 2);
|
|
|
|
|
//BoatInRace[] boats = new BoatInRace[]{boat1, boat2};
|
|
|
|
|
List<BoatInRace> boats = new ArrayList<>();
|
|
|
|
|
boats.add(boat1);
|
|
|
|
|
boats.add(boat2);
|
|
|
|
|
|
|
|
|
|
ArrayList<Leg> legs = new ArrayList<>();
|
|
|
|
|
legs.add(START_LEG);
|
|
|
|
|
legs.add(FINISH_LEG);
|
|
|
|
|
|
|
|
|
|
Race race = new Race(boats, legs, 5, System.out);
|
|
|
|
|
race.setDnfChance(0);
|
|
|
|
|
long timeStarted = System.currentTimeMillis();
|
|
|
|
|
race.run();
|
|
|
|
|
assertTrue(System.currentTimeMillis() - timeStarted < 4000);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void checkPositionUpdatesNumberFinishedBoats() {
|
|
|
|
|
|
|
|
|
|
BoatInRace finishedBoat = new BoatInRace("Test", 1000, Color.ALICEBLUE, "tt", 1);
|
|
|
|
|
finishedBoat.setDistanceTravelledInLeg(500);
|
|
|
|
|
|
|
|
|
|
finishedBoat.setCurrentLeg(FINISH_LEG);
|
|
|
|
|
|
|
|
|
|
ArrayList<BoatInRace> boats = new ArrayList<>();
|
|
|
|
|
boats.add(finishedBoat);
|
|
|
|
|
|
|
|
|
|
ArrayList<Leg> legs = new ArrayList<>();
|
|
|
|
|
legs.add(FINISH_LEG);
|
|
|
|
|
|
|
|
|
|
Race race = new Race(boats, legs, 1, System.out);
|
|
|
|
|
race.setDnfChance(0);
|
|
|
|
|
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", 1);
|
|
|
|
|
unFinishedBoat.setDistanceTravelledInLeg(0);
|
|
|
|
|
|
|
|
|
|
unFinishedBoat.setCurrentLeg(FINISH_LEG);
|
|
|
|
|
|
|
|
|
|
ArrayList<BoatInRace> boats = new ArrayList<>();
|
|
|
|
|
boats.add(unFinishedBoat);
|
|
|
|
|
|
|
|
|
|
ArrayList<Leg> legs = new ArrayList<>();
|
|
|
|
|
legs.add(FINISH_LEG);
|
|
|
|
|
|
|
|
|
|
Race race = new Race(boats, legs, 1, System.out);
|
|
|
|
|
race.setDnfChance(0);
|
|
|
|
|
assertEquals(race.boatsFinished, 0);
|
|
|
|
|
|
|
|
|
|
race.checkPosition(unFinishedBoat, 100);
|
|
|
|
|
assertEquals(race.boatsFinished, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void distanceTravelledBeforeUpdatingLegIsRetained() {
|
|
|
|
|
|
|
|
|
|
ArrayList<BoatInRace> boats = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
ArrayList<Leg> legs = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
legs.add(START_LEG);
|
|
|
|
|
legs.add(FINISH_LEG);
|
|
|
|
|
|
|
|
|
|
Race race = new Race(boats, legs, 1, System.out);
|
|
|
|
|
race.setDnfChance(0);
|
|
|
|
|
|
|
|
|
|
BoatInRace unFinishedBoat = new BoatInRace("Test", 10, Color.ALICEBLUE, "tt", 1);
|
|
|
|
|
unFinishedBoat.setDistanceTravelledInLeg(100);
|
|
|
|
|
unFinishedBoat.setCurrentLeg(START_LEG);
|
|
|
|
|
|
|
|
|
|
race.checkPosition(unFinishedBoat, 100);
|
|
|
|
|
assertEquals(unFinishedBoat.getCurrentLeg().getName(), "Finish");
|
|
|
|
|
assertTrue(unFinishedBoat.getDistanceTravelledInLeg() > 0);
|
|
|
|
|
assertTrue(unFinishedBoat.getDistanceTravelledInLeg() < 100);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// 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);
|
|
|
|
|
//
|
|
|
|
|
// @Ignore
|
|
|
|
|
// @Test
|
|
|
|
|
// public void timerDelaysByHalfSecond() throws InterruptedException {
|
|
|
|
|
// public void timerCanBeDisabled() {
|
|
|
|
|
// BoatInRace boat1 = new BoatInRace("Test 1", 10000, Color.ALICEBLUE, "t1", 1);
|
|
|
|
|
// BoatInRace boat2 = new BoatInRace("Test 2", 10000, Color.BURLYWOOD, "t2", 2);
|
|
|
|
|
// //BoatInRace[] boats = new BoatInRace[]{boat1, boat2};
|
|
|
|
|
// List<BoatInRace> boats = new ArrayList<>();
|
|
|
|
|
// boats.add(boat1);
|
|
|
|
|
// boats.add(boat2);
|
|
|
|
|
//
|
|
|
|
|
// ArrayList<Leg> legs = new ArrayList<>();
|
|
|
|
|
// legs.add(START_LEG);
|
|
|
|
|
// legs.add(FINISH_LEG);
|
|
|
|
|
//
|
|
|
|
|
// Race race = new Race(boats, legs, 5, System.out);
|
|
|
|
|
// race.setDnfChance(0);
|
|
|
|
|
// long timeStarted = System.currentTimeMillis();
|
|
|
|
|
// race.run();
|
|
|
|
|
// assertTrue(System.currentTimeMillis() - timeStarted < 4000);
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// @Test
|
|
|
|
|
// public void checkPositionUpdatesNumberFinishedBoats() {
|
|
|
|
|
//
|
|
|
|
|
// BoatInRace finishedBoat = new BoatInRace("Test", 1000, Color.ALICEBLUE, "tt", 1);
|
|
|
|
|
// finishedBoat.setDistanceTravelledInLeg(500);
|
|
|
|
|
//
|
|
|
|
|
// finishedBoat.setCurrentLeg(FINISH_LEG);
|
|
|
|
|
//
|
|
|
|
|
// ArrayList<BoatInRace> boats = new ArrayList<>();
|
|
|
|
|
// boats.add(finishedBoat);
|
|
|
|
|
//
|
|
|
|
|
// ArrayList<Leg> legs = new ArrayList<>();
|
|
|
|
|
// legs.add(FINISH_LEG);
|
|
|
|
|
//
|
|
|
|
|
// Race race = new Race(boats, legs, 1, System.out);
|
|
|
|
|
// race.setDnfChance(0);
|
|
|
|
|
// 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", 1);
|
|
|
|
|
// unFinishedBoat.setDistanceTravelledInLeg(0);
|
|
|
|
|
//
|
|
|
|
|
// unFinishedBoat.setCurrentLeg(FINISH_LEG);
|
|
|
|
|
//
|
|
|
|
|
// ArrayList<BoatInRace> boats = new ArrayList<>();
|
|
|
|
|
// boats.add(unFinishedBoat);
|
|
|
|
|
//
|
|
|
|
|
// ArrayList<Leg> legs = new ArrayList<>();
|
|
|
|
|
// legs.add(FINISH_LEG);
|
|
|
|
|
//
|
|
|
|
|
// Race race = new Race(boats, legs, 1, System.out);
|
|
|
|
|
// race.setDnfChance(0);
|
|
|
|
|
// assertEquals(race.boatsFinished, 0);
|
|
|
|
|
//
|
|
|
|
|
// race.checkPosition(unFinishedBoat, 100);
|
|
|
|
|
// assertEquals(race.boatsFinished, 0);
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// @Test
|
|
|
|
|
// public void distanceTravelledBeforeUpdatingLegIsRetained() {
|
|
|
|
|
//
|
|
|
|
|
// ArrayList<BoatInRace> boats = new ArrayList<>();
|
|
|
|
|
//
|
|
|
|
|
// ArrayList<Leg> legs = new ArrayList<>();
|
|
|
|
|
//
|
|
|
|
|
// legs.add(START_LEG);
|
|
|
|
|
// legs.add(FINISH_LEG);
|
|
|
|
|
//
|
|
|
|
|
// Race race = new Race(boats, legs, 1);
|
|
|
|
|
// race.PRERACE_TIME = 500;
|
|
|
|
|
// Race race = new Race(boats, legs, 1, System.out);
|
|
|
|
|
// race.setDnfChance(0);
|
|
|
|
|
//
|
|
|
|
|
// long timeStarted = System.currentTimeMillis();
|
|
|
|
|
// race.countdownTimer();
|
|
|
|
|
// BoatInRace unFinishedBoat = new BoatInRace("Test", 10, Color.ALICEBLUE, "tt", 1);
|
|
|
|
|
// unFinishedBoat.setDistanceTravelledInLeg(100);
|
|
|
|
|
// unFinishedBoat.setCurrentLeg(START_LEG);
|
|
|
|
|
//
|
|
|
|
|
// race.checkPosition(unFinishedBoat, 100);
|
|
|
|
|
// assertEquals(unFinishedBoat.getCurrentLeg().getName(), "Finish");
|
|
|
|
|
// assertTrue(unFinishedBoat.getDistanceTravelledInLeg() > 0);
|
|
|
|
|
// assertTrue(unFinishedBoat.getDistanceTravelledInLeg() < 100);
|
|
|
|
|
//
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
//// @Ignore
|
|
|
|
|
//// @Test
|
|
|
|
|
//// public void timerDelaysByHalfSecond() throws InterruptedException {
|
|
|
|
|
////
|
|
|
|
|
//// ArrayList<BoatInRace> boats = new ArrayList<>();
|
|
|
|
|
////
|
|
|
|
|
//// ArrayList<Leg> legs = new ArrayList<>();
|
|
|
|
|
//// legs.add(START_LEG);
|
|
|
|
|
////
|
|
|
|
|
//// Race race = new Race(boats, legs, 1);
|
|
|
|
|
//// race.PRERACE_TIME = 500;
|
|
|
|
|
////
|
|
|
|
|
//// long timeStarted = System.currentTimeMillis();
|
|
|
|
|
//// race.countdownTimer();
|
|
|
|
|
////
|
|
|
|
|
//// Thread.sleep(500);
|
|
|
|
|
////
|
|
|
|
|
//// assertTrue(System.currentTimeMillis() - timeStarted > 500);
|
|
|
|
|
//// //System.out.println(System.currentTimeMillis() - timeStarted);
|
|
|
|
|
////
|
|
|
|
|
//// }
|
|
|
|
|
//
|
|
|
|
|
// Thread.sleep(500);
|
|
|
|
|
// @Test
|
|
|
|
|
// public void scalerScalesVelocityCorrectly() {
|
|
|
|
|
//
|
|
|
|
|
// assertTrue(System.currentTimeMillis() - timeStarted > 500);
|
|
|
|
|
// //System.out.println(System.currentTimeMillis() - timeStarted);
|
|
|
|
|
// 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", 1);
|
|
|
|
|
// BoatInRace boat2 = new BoatInRace("test", vel2, Color.ALICEBLUE, "tt", 2);
|
|
|
|
|
// BoatInRace boat3 = new BoatInRace("test", vel3, Color.ALICEBLUE, "tt", 3);
|
|
|
|
|
// BoatInRace boat4 = new BoatInRace("test", vel4, Color.ALICEBLUE, "tt", 4);
|
|
|
|
|
// ArrayList<BoatInRace> boats = new ArrayList<>();
|
|
|
|
|
// boats.add(boat1);
|
|
|
|
|
// boats.add(boat2);
|
|
|
|
|
// boats.add(boat3);
|
|
|
|
|
// boats.add(boat4);
|
|
|
|
|
//
|
|
|
|
|
// ArrayList<Leg> legs = new ArrayList<>();
|
|
|
|
|
// legs.add(START_LEG);
|
|
|
|
|
//
|
|
|
|
|
// Race race = new Race(boats, legs, scaleFactor, System.out);
|
|
|
|
|
// 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);
|
|
|
|
|
// assertEquals(race.getStartingBoats().get(3).getScaledVelocity(), vel4 * scaleFactor, 1e-6);
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// @Test
|
|
|
|
|
// public void scalerScalesRaceClockTo1MinCorrectly() {
|
|
|
|
|
// int scaleFactor = 10;
|
|
|
|
|
//
|
|
|
|
|
// ArrayList<BoatInRace> boats = new ArrayList<>();
|
|
|
|
|
//
|
|
|
|
|
// ArrayList<Leg> legs = new ArrayList<>();
|
|
|
|
|
// legs.add(START_LEG);
|
|
|
|
|
//
|
|
|
|
|
// Race race = new Race(boats, legs, scaleFactor, System.out);
|
|
|
|
|
// race.totalTimeElapsed = 6000; //6 seconds
|
|
|
|
|
// assertTrue(race.calcTimer().equals("Race clock: 00:01:00"));
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// @Test
|
|
|
|
|
// public void scalerScalesRaceClockHoursMinutesAndSecondsCorrectly() {
|
|
|
|
|
// int scaleFactor = 3;
|
|
|
|
|
//
|
|
|
|
|
// ArrayList<BoatInRace> boats = new ArrayList<>();
|
|
|
|
|
//
|
|
|
|
|
// ArrayList<Leg> legs = new ArrayList<>();
|
|
|
|
|
// legs.add(START_LEG);
|
|
|
|
|
//
|
|
|
|
|
// Race race = new Race(boats, legs, scaleFactor, System.out);
|
|
|
|
|
// race.totalTimeElapsed = 3213000;
|
|
|
|
|
// assertTrue(race.calcTimer().equals("Race clock: 02:40:39"));
|
|
|
|
|
//
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
@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", 1);
|
|
|
|
|
BoatInRace boat2 = new BoatInRace("test", vel2, Color.ALICEBLUE, "tt", 2);
|
|
|
|
|
BoatInRace boat3 = new BoatInRace("test", vel3, Color.ALICEBLUE, "tt", 3);
|
|
|
|
|
BoatInRace boat4 = new BoatInRace("test", vel4, Color.ALICEBLUE, "tt", 4);
|
|
|
|
|
ArrayList<BoatInRace> boats = new ArrayList<>();
|
|
|
|
|
boats.add(boat1);
|
|
|
|
|
boats.add(boat2);
|
|
|
|
|
boats.add(boat3);
|
|
|
|
|
boats.add(boat4);
|
|
|
|
|
|
|
|
|
|
ArrayList<Leg> legs = new ArrayList<>();
|
|
|
|
|
legs.add(START_LEG);
|
|
|
|
|
|
|
|
|
|
Race race = new Race(boats, legs, scaleFactor, System.out);
|
|
|
|
|
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);
|
|
|
|
|
assertEquals(race.getStartingBoats().get(3).getScaledVelocity(), vel4 * scaleFactor, 1e-6);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void scalerScalesRaceClockTo1MinCorrectly() {
|
|
|
|
|
int scaleFactor = 10;
|
|
|
|
|
|
|
|
|
|
ArrayList<BoatInRace> boats = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
ArrayList<Leg> legs = new ArrayList<>();
|
|
|
|
|
legs.add(START_LEG);
|
|
|
|
|
|
|
|
|
|
Race race = new Race(boats, legs, scaleFactor, System.out);
|
|
|
|
|
race.totalTimeElapsed = 6000; //6 seconds
|
|
|
|
|
assertTrue(race.calcTimer().equals("Race clock: 00:01:00"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void scalerScalesRaceClockHoursMinutesAndSecondsCorrectly() {
|
|
|
|
|
int scaleFactor = 3;
|
|
|
|
|
|
|
|
|
|
ArrayList<BoatInRace> boats = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
ArrayList<Leg> legs = new ArrayList<>();
|
|
|
|
|
legs.add(START_LEG);
|
|
|
|
|
|
|
|
|
|
Race race = new Race(boats, legs, scaleFactor, System.out);
|
|
|
|
|
race.totalTimeElapsed = 3213000;
|
|
|
|
|
assertTrue(race.calcTimer().equals("Race clock: 02:40:39"));
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|