Fixing merge and resulting failing tests
#fix #story[16]
This commit is contained in:
@@ -18,49 +18,50 @@ import static org.junit.Assert.assertEquals;
|
||||
*/
|
||||
public class ConstantVelocityRaceTest {
|
||||
|
||||
Leg START_LEG = new Leg("Start", new GPSCoordinate(0, 0), new GPSCoordinate(50, 50), 0);
|
||||
int ONE_HOUR = 3600000; //1 hour in milliseconds
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void updatePositionChangesDistanceTravelled() {
|
||||
|
||||
BoatInRace boat = new BoatInRace("Test", 1, Color.ALICEBLUE, "tt");
|
||||
Leg start = new Leg("Start", new GPSCoordinate(0, 0), new GPSCoordinate(50, 50), 0);
|
||||
boat.setCurrentLeg(start);
|
||||
boat.setCurrentLeg(START_LEG);
|
||||
boat.setDistanceTravelledInLeg(0);
|
||||
int timeElapsed = 3600000; //1 hr
|
||||
BoatInRace[] boats = new BoatInRace[]{boat};
|
||||
|
||||
ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[1], new ArrayList<Leg>());
|
||||
ConstantVelocityRace race = new ConstantVelocityRace(boats, new ArrayList<Leg>(), null, 1);
|
||||
|
||||
race.updatePosition(boat, timeElapsed);
|
||||
assertEquals(boat.getDistanceTravelledInLeg(), boat.getVelocity() * timeElapsed / 3600000, 1e-8);
|
||||
race.updatePosition(boat, ONE_HOUR);
|
||||
assertEquals(boat.getDistanceTravelledInLeg(), boat.getVelocity(), 1e-8);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updatePositionHandlesNoChangeToDistanceTravelled() {
|
||||
|
||||
BoatInRace boat = new BoatInRace("Test", 0, Color.ALICEBLUE, "tt");
|
||||
Leg start = new Leg("Start", new GPSCoordinate(0, 0), new GPSCoordinate(50, 50), 0);
|
||||
boat.setCurrentLeg(start);
|
||||
boat.setCurrentLeg(START_LEG);
|
||||
boat.setDistanceTravelledInLeg(0);
|
||||
int timeElapsed = 3600000; //1 hr
|
||||
BoatInRace[] boats = new BoatInRace[]{boat};
|
||||
|
||||
ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[1], new ArrayList<Leg>());
|
||||
ConstantVelocityRace race = new ConstantVelocityRace(boats, new ArrayList<Leg>(), null, 1);
|
||||
|
||||
race.updatePosition(boat, timeElapsed);
|
||||
race.updatePosition(boat, ONE_HOUR);
|
||||
assertEquals(boat.getDistanceTravelledInLeg(), 0, 1e-8);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void changesToDistanceTravelledAreAdditive() {
|
||||
BoatInRace boat = new BoatInRace("Test", 5, Color.ALICEBLUE, "tt");
|
||||
Leg start = new Leg("Start", new GPSCoordinate(0, 0), new GPSCoordinate(50, 50), 0);
|
||||
boat.setCurrentLeg(start);
|
||||
boat.setCurrentLeg(START_LEG);
|
||||
boat.setDistanceTravelledInLeg(50);
|
||||
int timeElapsed = 3600000; //1 hr
|
||||
BoatInRace[] boats = new BoatInRace[]{boat};
|
||||
|
||||
ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[1], new ArrayList<Leg>());
|
||||
ConstantVelocityRace race = new ConstantVelocityRace(boats, new ArrayList<Leg>(), null, 1);
|
||||
|
||||
race.updatePosition(boat, timeElapsed);
|
||||
assertEquals(boat.getDistanceTravelledInLeg(), boat.getVelocity() * timeElapsed / 3600000 + 50, 1e-8);
|
||||
race.updatePosition(boat, ONE_HOUR);
|
||||
assertEquals(boat.getDistanceTravelledInLeg(), boat.getVelocity() + 50, 1e-8);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -72,7 +73,6 @@ public class ConstantVelocityRaceTest {
|
||||
calc.setStartingGeographicPoint(0, 0);
|
||||
calc.setDirection(0, 10 * Constants.NMToMetersConversion);
|
||||
|
||||
|
||||
assertEquals(newPos.getLongitude(), 0, 1e-8);
|
||||
assertEquals(newPos.getLatitude(), calc.getDestinationGeographicPoint().getY(), 1e-8);
|
||||
assertEquals(newPos.getLongitude(), calc.getDestinationGeographicPoint().getX(), 1e-8);
|
||||
|
||||
@@ -32,7 +32,7 @@ public class RaceTest {
|
||||
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.293039, -64.843983), new GPSCoordinate(32.284680, -64.850045), 1));
|
||||
Race race = new ConstantVelocityRace(boats, legs);
|
||||
Race race = new ConstantVelocityRace(boats, legs, null, 1);
|
||||
race.disableTimer();
|
||||
|
||||
// Boats should finish in an order determined by their velocity
|
||||
@@ -52,7 +52,7 @@ public class RaceTest {
|
||||
Leg leg = new Leg("Finish", new GPSCoordinate(0, 0), new GPSCoordinate(1, 1), 0);
|
||||
finishedBoat.setCurrentLeg(leg);
|
||||
|
||||
ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[1], new ArrayList<Leg>());
|
||||
ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[1], new ArrayList<Leg>(), null, 1);
|
||||
assertEquals(race.boatsFinished, 0);
|
||||
|
||||
race.checkPosition(finishedBoat, 100);
|
||||
@@ -68,7 +68,7 @@ public class RaceTest {
|
||||
Leg leg = new Leg("Finish", new GPSCoordinate(0, 0), new GPSCoordinate(1, 1), 0);
|
||||
unFinishedBoat.setCurrentLeg(leg);
|
||||
|
||||
ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[1], new ArrayList<Leg>());
|
||||
ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[1], new ArrayList<Leg>(), null, 1);
|
||||
assertEquals(race.boatsFinished, 0);
|
||||
|
||||
race.checkPosition(unFinishedBoat, 100);
|
||||
@@ -87,7 +87,7 @@ public class RaceTest {
|
||||
legs.add(leg2);
|
||||
legs.add(leg2);
|
||||
|
||||
ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[1], legs);
|
||||
ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[1], legs, null, 1);
|
||||
|
||||
BoatInRace unFinishedBoat = new BoatInRace("Test", 10, Color.ALICEBLUE, "tt");
|
||||
unFinishedBoat.setDistanceTravelledInLeg(100);
|
||||
@@ -102,7 +102,7 @@ public class RaceTest {
|
||||
|
||||
@Test
|
||||
public void timerDelaysByHalfSecond() {
|
||||
ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[1], new ArrayList<>());
|
||||
ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[1], new ArrayList<>(), null, 1);
|
||||
race.PRERACE_TIME = 500;
|
||||
|
||||
long timeStarted = System.currentTimeMillis();
|
||||
@@ -126,7 +126,7 @@ 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>(), scaleFactor);
|
||||
ConstantVelocityRace race = new ConstantVelocityRace(boats, new ArrayList<Leg>(), 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);
|
||||
@@ -136,7 +136,7 @@ public class RaceTest {
|
||||
@Test
|
||||
public void scalerScalesRaceClockTo1MinCorrectly() {
|
||||
int scaleFactor = 10;
|
||||
ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[5], new ArrayList<Leg>(), scaleFactor);
|
||||
ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[5], new ArrayList<Leg>(), null, scaleFactor);
|
||||
race.totalTimeElapsed = 6000; //6 seconds
|
||||
assertTrue(race.calcTimer().equals("Race clock: 00:01:00"));
|
||||
}
|
||||
@@ -144,7 +144,7 @@ public class RaceTest {
|
||||
@Test
|
||||
public void scalerScalesRaceClockHoursMinutesAndSecondsCorrectly() {
|
||||
int scaleFactor = 3;
|
||||
ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[5], new ArrayList<Leg>(), scaleFactor);
|
||||
ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[5], new ArrayList<Leg>(), null, scaleFactor);
|
||||
race.totalTimeElapsed = 3213000;
|
||||
assertTrue(race.calcTimer().equals("Race clock: 02:40:39"));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user