Fixing merge and resulting failing tests

#fix #story[16]
main
Erika Savell 9 years ago
parent ac558746a0
commit f5ba7c95c8

@ -14,7 +14,6 @@ public class Boat {
private StringProperty name;
private double velocity;
private double scaledVelocity;
private StringProperty velocityProp;
private String abbrev;
@ -51,14 +50,6 @@ public class Boat {
}
public double getScaledVelocity() {
return scaledVelocity;
}
public void setScaledVelocity(double velocity) {
this.scaledVelocity = velocity;
}
/**
*
* @return The Name of the boat.

@ -15,6 +15,7 @@ import seng302.GPSCoordinate;
public class BoatInRace extends Boat {
private Leg currentLeg;
private double scaledVelocity;
private double distanceTravelledInLeg;
private GPSCoordinate currentPosition;
private long timeFinished;
@ -34,6 +35,14 @@ public class BoatInRace extends Boat {
currentLegName = new SimpleStringProperty("");
}
public double getScaledVelocity() {
return scaledVelocity;
}
public void setScaledVelocity(double velocity) {
this.scaledVelocity = velocity;
}
/**
*
* @return Returns the current position of the boat in a GPSCoordinate Class.

@ -23,17 +23,9 @@ public class ConstantVelocityRace extends Race {
*/
public ConstantVelocityRace(BoatInRace[] startingBoats, ArrayList<Leg> marks, RaceController controller, int scaleFactor) {
super(startingBoats, marks, controller);
setScaleFactor(scaleFactor);
super(startingBoats, marks, controller, scaleFactor);
}
public ConstantVelocityRace(BoatInRace[] startingBoats, ArrayList<Leg> marks) {
super(startingBoats, marks);
}
public ConstantVelocityRace(BoatInRace[] startingBoats, ArrayList<Leg> marks, int scaleFactor) {
super(startingBoats, marks, scaleFactor);
}
protected void updatePosition(BoatInRace boat, int millisecondsElapsed) {
@ -43,7 +35,6 @@ public class ConstantVelocityRace extends Race {
boolean finish = boat.getCurrentLeg().getName().equals("Finish");
if (!finish) {
boat.setDistanceTravelledInLeg(totalDistanceTravelled);
boat.setCurrentPosition(calculatePosition(boat.getCurrentLeg().getStartGraphCoordinate(),
totalDistanceTravelled, boat.calculateAzimuth()));

@ -28,7 +28,6 @@ public class Leg {
this.endGPSCoordinate = end;
this.legNumber = number;
this.distance = calculateDistance();
System.out.println("Distance of leg " + name + " is " + Double.toString(distance));
}
/**

@ -20,10 +20,10 @@ public abstract class Race implements Runnable {
protected int boatsFinished = 0;
protected long totalTimeElapsed;
protected int scaleFactor = 15;
protected int scaleFactor;
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
protected int PRERACE_TIME = 100;//Integer.MAX_VALUE; //time in milliseconds to pause during pre-race
private boolean timerEnabled = true;
/**
@ -31,26 +31,27 @@ public abstract class Race implements Runnable {
* @param boats Takes in an array of boats that are participating in the race.
* @param legs Number of marks in order that the boats pass in order to complete the race.
*/
public Race(BoatInRace[] boats, ArrayList<Leg> legs, RaceController controller) {
public Race(BoatInRace[] boats, ArrayList<Leg> legs, RaceController controller, 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()));
this.controller = controller;
this.scaleFactor = scaleFactor;
}
/**
* Constructor for Race class
* @param boats boats participating in the race.
* @param marks legs that there are in the race.
* @param legs legs that there are in the race.
*/
public Race(BoatInRace[] boats, ArrayList<Leg> marks) {
this(boats, marks, null);
}
public Race(BoatInRace[] boats, ArrayList<Leg> legs, int scaleFactor) {
if (boats.length > 0) {
for (BoatInRace boat : boats) {
@ -66,11 +67,6 @@ public abstract class Race implements Runnable {
}
public void setScaleFactor(int scaleFactor) {
this.scaleFactor = scaleFactor;
}
/**
* Runnable for the thread.
*/
@ -90,12 +86,8 @@ public abstract class Race implements Runnable {
*/
private void preRace() {
//show the boats participating.
System.out.println("Boats Participating:");
System.out.println("====================");
for (int i = 0; i < startingBoats.size(); i++) {
if (startingBoats.get(i) != null) {
System.out.println(i + 1 + ". " + startingBoats.get(i).getName() + ", Speed: "
+ Math.round(startingBoats.get(i).getVelocity() * 1.94384) + "kn");
startingBoats.get(i).setCurrentLeg(legs.get(0));
}
}
@ -123,7 +115,7 @@ public abstract class Race implements Runnable {
hours = minutes / 60;
minutes = minutes % 60;
if (controller != null) {
updateTime(String.format("Time until race starts: -%02d:%02d:%02d", hours, minutes, remainingSeconds));
updateTime(String.format("Race clock: -%02d:%02d:%02d", hours, minutes, remainingSeconds));
}
}
try {

@ -60,7 +60,7 @@
</Label>
</children>
</GridPane>
<SplitPane fx:id="ongoingRacePane" dividerPositions="0.5" visible="false" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<SplitPane fx:id="ongoingRacePane" dividerPositions="0.70" visible="false" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<items>
<AnchorPane fx:id="canvasBase" prefHeight="581.0" prefWidth="537.0">
<children>

@ -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"));

Loading…
Cancel
Save