Test that boat velocities are being scaled correctly added

#story[16] #implement
main
Erika Savell 9 years ago
parent 4c7295998b
commit 944da81946

@ -30,6 +30,10 @@ public class ConstantVelocityRace extends Race {
super(startingBoats, marks); super(startingBoats, marks);
} }
public ConstantVelocityRace(BoatInRace[] startingBoats, ArrayList<Leg> marks, int scaleFactor) {
super(startingBoats, marks, scaleFactor);
}
protected void updatePosition(BoatInRace boat, int millisecondsElapsed) { protected void updatePosition(BoatInRace boat, int millisecondsElapsed) {
//distanceTravelled = velocity (nm p hr) * time taken to update loop //distanceTravelled = velocity (nm p hr) * time taken to update loop

@ -2,12 +2,9 @@ package seng302.Model;
import javafx.application.Platform; import javafx.application.Platform;
import javafx.beans.property.StringProperty;
import javafx.collections.FXCollections; import javafx.collections.FXCollections;
import javafx.collections.ObservableArray;
import javafx.collections.ObservableList; import javafx.collections.ObservableList;
import seng302.Controllers.RaceController; import seng302.Controllers.RaceController;
import seng302.GPSCoordinate;
import java.util.*; import java.util.*;
@ -22,8 +19,8 @@ public abstract class Race implements Runnable {
protected RaceController controller; protected RaceController controller;
protected int boatsFinished = 0; protected int boatsFinished = 0;
protected long totalTimeElapsed; protected long totalTimeElapsed;
protected int scale_factor = 15;
protected int scaleFactor = 1;
private int SLEEP_TIME = 100; //time in milliseconds to pause in a paced loop 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 = 10000;//Integer.MAX_VALUE; //time in milliseconds to pause during pre-race
@ -36,7 +33,7 @@ public abstract class Race implements Runnable {
*/ */
public Race(BoatInRace[] boats, ArrayList<Leg> legs, RaceController controller) { public Race(BoatInRace[] boats, ArrayList<Leg> legs, RaceController controller) {
for (BoatInRace boat : boats) { for (BoatInRace boat : boats) {
boat.setScaledVelocity(boat.getVelocity() * scale_factor); boat.setScaledVelocity(boat.getVelocity() * scaleFactor);
} }
this.startingBoats = FXCollections.observableArrayList(boats); this.startingBoats = FXCollections.observableArrayList(boats);
@ -54,6 +51,22 @@ public abstract class Race implements Runnable {
this(boats, marks, null); this(boats, marks, null);
} }
public Race(BoatInRace[] boats, ArrayList<Leg> legs, int scaleFactor) {
for (BoatInRace boat : boats) {
boat.setScaledVelocity(boat.getVelocity() * scaleFactor);
}
this.startingBoats = FXCollections.observableArrayList(boats);
this.legs = legs;
this.legs.add(new Leg("Finish", this.legs.size()));
this.scaleFactor = scaleFactor;
}
public void setScaleFactor(int scaleFactor) {
this.scaleFactor = scaleFactor;
}
/** /**
* Runnable for the thread. * Runnable for the thread.
*/ */
@ -122,7 +135,7 @@ public abstract class Race implements Runnable {
long hours; long hours;
currentTimeInSeconds = totalTimeElapsed / 1000; currentTimeInSeconds = totalTimeElapsed / 1000;
long scaledTimeInSeconds = currentTimeInSeconds * scale_factor; long scaledTimeInSeconds = currentTimeInSeconds * scaleFactor;
minutes = scaledTimeInSeconds / 60; minutes = scaledTimeInSeconds / 60;
remainingSeconds = scaledTimeInSeconds % 60; remainingSeconds = scaledTimeInSeconds % 60;
hours = minutes / 60; hours = minutes / 60;

@ -110,4 +110,25 @@ public class RaceTest {
assertTrue(System.currentTimeMillis() - timeStarted > 500); assertTrue(System.currentTimeMillis() - timeStarted > 500);
} }
@Test
public void scalerScalesVelocityCorrectly() {
int scaleFactor = 0;
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};
ConstantVelocityRace race = new ConstantVelocityRace(boats, new ArrayList<Leg>(), scaleFactor);
assertEquals(race.getStartingBoats().get(0).getScaledVelocity(), vel1 * scaleFactor, 1e-8);
assertEquals(race.getStartingBoats().get(1).getScaledVelocity(), vel2 * scaleFactor, 1e-8);
assertEquals(race.getStartingBoats().get(2).getScaledVelocity(), vel3 * scaleFactor, 1e-8);
assertEquals(race.getStartingBoats().get(3).getScaledVelocity(), vel4 * scaleFactor, 1e-8);
}
} }

Loading…
Cancel
Save