Amended and added tests to cope with marker change
#test #story[20]
This commit is contained in:
@@ -145,7 +145,6 @@ public class RaceController extends Controller{
|
||||
}
|
||||
BoatInRace[] boats = new BoatInRace[raceXMLReader.getBoats().size()];
|
||||
boats = raceXMLReader.getBoats().toArray(boats);
|
||||
//BoatInRace[] boats = generateAC35Competitors();
|
||||
|
||||
raceMap = new ResizableRaceCanvas();
|
||||
raceMap.setMouseTransparent(true);
|
||||
@@ -159,7 +158,6 @@ public class RaceController extends Controller{
|
||||
startScreen.setVisible(false);
|
||||
ongoingRacePane.setVisible(true);
|
||||
|
||||
//ArrayList<Leg> legs = generateBermudaCourseLegs();
|
||||
ArrayList<Leg> legs = raceXMLReader.getLegs();
|
||||
ConstantVelocityRace race = new ConstantVelocityRace(boats, legs, this, scaleFactor);
|
||||
|
||||
@@ -195,7 +193,6 @@ public class RaceController extends Controller{
|
||||
timer.setText(time);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the value for the fps label
|
||||
* @param fps fps that the label will be updated to
|
||||
|
||||
@@ -21,7 +21,7 @@ public class Boat {
|
||||
*/
|
||||
public Boat(String name, double velocity, String abbrev) {
|
||||
this.velocity = velocity;
|
||||
this.velocityProp = new SimpleStringProperty(String.valueOf(velocity* 1.94384));
|
||||
this.velocityProp = new SimpleStringProperty(String.valueOf(velocity));
|
||||
this.abbrev = abbrev;
|
||||
this.name = new SimpleStringProperty(name);
|
||||
}
|
||||
|
||||
@@ -73,34 +73,15 @@ public class Leg {
|
||||
}
|
||||
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void setDistance(double distance) {
|
||||
this.distance = distance;
|
||||
}
|
||||
|
||||
public Marker getStartMarker() {
|
||||
return startMarker;
|
||||
}
|
||||
|
||||
public void setStartMarker(Marker startMarker) {
|
||||
this.startMarker = startMarker;
|
||||
}
|
||||
|
||||
public Marker getEndMarker() {
|
||||
return endMarker;
|
||||
}
|
||||
|
||||
public void setEndMarker(Marker endMarker) {
|
||||
this.endMarker = endMarker;
|
||||
}
|
||||
|
||||
public void setLegNumber(int legNumber) {
|
||||
this.legNumber = legNumber;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the distance that the legs are in nautical miles (1.852 km).
|
||||
*
|
||||
|
||||
@@ -35,25 +35,6 @@ public class Marker {
|
||||
return averageGPSCoordinate;
|
||||
}
|
||||
|
||||
public void setAverageGPSCoordinate(GPSCoordinate averageGPSCoordinate) {
|
||||
this.averageGPSCoordinate = averageGPSCoordinate;
|
||||
}
|
||||
|
||||
public GPSCoordinate getMark1() {
|
||||
return mark1;
|
||||
}
|
||||
|
||||
public void setMark1(GPSCoordinate mark1) {
|
||||
this.mark1 = mark1;
|
||||
}
|
||||
|
||||
public GPSCoordinate getMark2() {
|
||||
return mark2;
|
||||
}
|
||||
|
||||
public void setMark2(GPSCoordinate mark2) {
|
||||
this.mark2 = mark2;
|
||||
}
|
||||
|
||||
private GPSCoordinate calculateAverage() {
|
||||
|
||||
|
||||
@@ -50,24 +50,24 @@ public abstract class Race implements Runnable {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for Race class
|
||||
* @param boats boats participating in the race.
|
||||
* @param legs legs that there are in the race.
|
||||
*/
|
||||
public Race(BoatInRace[] boats, ArrayList<Leg> legs, 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.scaleFactor = scaleFactor;
|
||||
}
|
||||
// /**
|
||||
// * Constructor for Race class
|
||||
// * @param boats boats participating in the race.
|
||||
// * @param legs legs that there are in the race.
|
||||
// */
|
||||
// public Race(BoatInRace[] boats, ArrayList<Leg> legs, 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.scaleFactor = scaleFactor;
|
||||
// }
|
||||
|
||||
|
||||
protected void initialiseBoats() {
|
||||
|
||||
@@ -2,37 +2,37 @@
|
||||
<boats>
|
||||
<boat>
|
||||
<name>ORACLE TEAM USA</name>
|
||||
<speed>300</speed>
|
||||
<speed>30</speed>
|
||||
<abbr>USA</abbr>
|
||||
<colour>BLUEVIOLET</colour>
|
||||
</boat>
|
||||
<boat>
|
||||
<name>Land Rover BAR</name>
|
||||
<speed>500</speed>
|
||||
<speed>50</speed>
|
||||
<abbr>BAR</abbr>
|
||||
<colour>BLACK</colour>
|
||||
</boat>
|
||||
<boat>
|
||||
<name>SoftBank Team Japan</name>
|
||||
<speed>400</speed>
|
||||
<speed>40</speed>
|
||||
<abbr>JAP</abbr>
|
||||
<colour>RED</colour>
|
||||
</boat>
|
||||
<boat>
|
||||
<name>Groupama Team France</name>
|
||||
<speed>350</speed>
|
||||
<speed>35</speed>
|
||||
<abbr>FRN</abbr>
|
||||
<colour>ORANGE</colour>
|
||||
</boat>
|
||||
<boat>
|
||||
<name>Artemis Racing</name>
|
||||
<speed>440</speed>
|
||||
<speed>44</speed>
|
||||
<abbr>ART</abbr>
|
||||
<colour>DARKOLIVEGREEN</colour>
|
||||
</boat>
|
||||
<boat>
|
||||
<name>Emirates Team New Zealand</name>
|
||||
<speed>620</speed>
|
||||
<speed>62</speed>
|
||||
<abbr>ENZ</abbr>
|
||||
<colour>LIMEGREEN</colour>
|
||||
</boat>
|
||||
|
||||
@@ -5,6 +5,7 @@ import org.junit.Test;
|
||||
import seng302.GPSCoordinate;
|
||||
|
||||
import static junit.framework.TestCase.assertEquals;
|
||||
import static junit.framework.TestCase.assertFalse;
|
||||
import static junit.framework.TestCase.assertTrue;
|
||||
|
||||
/**
|
||||
@@ -12,101 +13,104 @@ import static junit.framework.TestCase.assertTrue;
|
||||
*/
|
||||
public class BoatInRaceTest {
|
||||
|
||||
//
|
||||
// @Test
|
||||
// public void calculateDueNorthAzimuthReturns0() {
|
||||
// BoatInRace boat = new BoatInRace("Test", 1, Color.ALICEBLUE, "tt");
|
||||
// GPSCoordinate startPoint = new GPSCoordinate(0, 0);
|
||||
// GPSCoordinate endPoint = new GPSCoordinate(50, 0);
|
||||
// Leg start = new Leg("Start", startPoint, endPoint, 0);
|
||||
// boat.setCurrentLeg(start);
|
||||
// assertEquals(boat.calculateAzimuth(), 0, 1e-8);
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void calculateDueSouthAzimuthReturns180() {
|
||||
// BoatInRace boat = new BoatInRace("Test", 1, Color.ALICEBLUE, "tt");
|
||||
// GPSCoordinate startPoint = new GPSCoordinate(0, 0);
|
||||
// GPSCoordinate endPoint = new GPSCoordinate(-50, 0);
|
||||
// Leg start = new Leg("Start", startPoint, endPoint, 0);
|
||||
// boat.setCurrentLeg(start);
|
||||
// assertEquals(boat.calculateAzimuth(), 180, 1e-8);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// @Test
|
||||
// public void calculateDueEastAzimuthReturns90() {
|
||||
//
|
||||
// BoatInRace boat = new BoatInRace("Test", 1, Color.ALICEBLUE, "tt");
|
||||
// GPSCoordinate startPoint = new GPSCoordinate(0, 0);
|
||||
// GPSCoordinate endPoint = new GPSCoordinate(0, 50);
|
||||
// Leg start = new Leg("Start", startPoint, endPoint, 0);
|
||||
// boat.setCurrentLeg(start);
|
||||
// assertEquals(boat.calculateAzimuth(), 90, 1e-8);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// @Test
|
||||
// public void calculateDueWestAzimuthReturnsNegative90() {
|
||||
// BoatInRace boat = new BoatInRace("Test", 1, Color.ALICEBLUE, "tt");
|
||||
// GPSCoordinate startPoint = new GPSCoordinate(0, 0);
|
||||
// GPSCoordinate endPoint = new GPSCoordinate(0, -50);
|
||||
// Leg start = new Leg("Start", startPoint, endPoint, 0);
|
||||
// boat.setCurrentLeg(start);
|
||||
// assertEquals(boat.calculateAzimuth(), -90, 1e-8);
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void calculateDueNorthHeadingReturns0() {
|
||||
// BoatInRace boat = new BoatInRace("Test", 1, Color.ALICEBLUE, "tt");
|
||||
// GPSCoordinate startPoint = new GPSCoordinate(10, 0);
|
||||
// GPSCoordinate endPoint = new GPSCoordinate(50, 0);
|
||||
// Leg start = new Leg("Start", startPoint, endPoint, 0);
|
||||
// boat.setCurrentLeg(start);
|
||||
// assertEquals(boat.calculateHeading(), 0, 1e-8);
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void calculateDueEastHeadingReturns90() {
|
||||
// BoatInRace boat = new BoatInRace("Test", 1, Color.ALICEBLUE, "tt");
|
||||
// GPSCoordinate startPoint = new GPSCoordinate(0, 0);
|
||||
// GPSCoordinate endPoint = new GPSCoordinate(0, 50);
|
||||
// Leg start = new Leg("Start", startPoint, endPoint, 0);
|
||||
// boat.setCurrentLeg(start);
|
||||
// assertEquals(boat.calculateHeading(), 90, 1e-8);
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void calculateDueSouthHeadingReturns180() {
|
||||
// BoatInRace boat = new BoatInRace("Test", 1, Color.ALICEBLUE, "tt");
|
||||
// GPSCoordinate startPoint = new GPSCoordinate(10, 0);
|
||||
// GPSCoordinate endPoint = new GPSCoordinate(-50, 0);
|
||||
// Leg start = new Leg("Start", startPoint, endPoint, 0);
|
||||
// boat.setCurrentLeg(start);
|
||||
// assertEquals(boat.calculateHeading(), 180, 1e-8);
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void calculateDueWestHeadingReturns270() {
|
||||
// BoatInRace boat = new BoatInRace("Test", 1, Color.ALICEBLUE, "tt");
|
||||
// GPSCoordinate startPoint = new GPSCoordinate(0, 10);
|
||||
// GPSCoordinate endPoint = new GPSCoordinate(0, -50);
|
||||
// Leg start = new Leg("Start", startPoint, endPoint, 0);
|
||||
// boat.setCurrentLeg(start);
|
||||
// assertEquals(boat.calculateHeading(), 270, 1e-8);
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void createNewBoatCratesInstanceOfSuperClass() {
|
||||
//
|
||||
// BoatInRace testBoat = new BoatInRace("Boat", 20, Color.ALICEBLUE, "tt");
|
||||
// testBoat.setName("Name can change");
|
||||
// assertTrue(testBoat instanceof Boat);
|
||||
// assertTrue(testBoat.getCurrentLeg() == null);
|
||||
// assertTrue(testBoat.getCurrentPosition() == null);
|
||||
// assertTrue(testBoat.toString().contains("Name can change"));
|
||||
// assertEquals(testBoat.getVelocity(), 20.0);
|
||||
// }
|
||||
|
||||
private GPSCoordinate ORIGIN_COORDS = new GPSCoordinate(0, 0);
|
||||
private BoatInRace TEST_BOAT = new BoatInRace("Test", 1, Color.ALICEBLUE, "tt");
|
||||
|
||||
|
||||
@Test
|
||||
public void calculateDueNorthAzimuthReturns0() {
|
||||
|
||||
Marker startMarker = new Marker(ORIGIN_COORDS);
|
||||
Marker endMarker = new Marker(new GPSCoordinate(50, 0));
|
||||
Leg start = new Leg("Start", startMarker, endMarker, 0);
|
||||
TEST_BOAT.setCurrentLeg(start);
|
||||
assertEquals(TEST_BOAT.calculateAzimuth(), 0, 1e-8);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void calculateDueSouthAzimuthReturns180() {
|
||||
Marker startMarker = new Marker(ORIGIN_COORDS);
|
||||
Marker endMarker = new Marker(new GPSCoordinate(-50, 0));
|
||||
Leg start = new Leg("Start", startMarker, endMarker, 0);
|
||||
TEST_BOAT.setCurrentLeg(start);
|
||||
assertEquals(TEST_BOAT.calculateAzimuth(), 180, 1e-8);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void calculateDueEastAzimuthReturns90() {
|
||||
|
||||
Marker startMarker = new Marker(ORIGIN_COORDS);
|
||||
Marker endMarker = new Marker(new GPSCoordinate(0, 50));
|
||||
Leg start = new Leg("Start", startMarker, endMarker, 0);
|
||||
TEST_BOAT.setCurrentLeg(start);
|
||||
assertEquals(TEST_BOAT.calculateAzimuth(), 90, 1e-8);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void calculateDueWestAzimuthReturnsNegative90() {
|
||||
Marker startMarker = new Marker(ORIGIN_COORDS);
|
||||
Marker endMarker = new Marker(new GPSCoordinate(0, -50));
|
||||
Leg start = new Leg("Start", startMarker, endMarker, 0);
|
||||
TEST_BOAT.setCurrentLeg(start);
|
||||
assertEquals(TEST_BOAT.calculateAzimuth(), -90, 1e-8);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void calculateDueNorthHeadingReturns0() {
|
||||
|
||||
Marker startMarker = new Marker(ORIGIN_COORDS);
|
||||
Marker endMarker = new Marker(new GPSCoordinate(50, 0));
|
||||
Leg start = new Leg("Start", startMarker, endMarker, 0);
|
||||
TEST_BOAT.setCurrentLeg(start);
|
||||
assertEquals(TEST_BOAT.calculateHeading(), 0, 1e-8);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void calculateDueEastHeadingReturns90() {
|
||||
Marker startMarker = new Marker(ORIGIN_COORDS);
|
||||
Marker endMarker = new Marker(new GPSCoordinate(0, 50));
|
||||
Leg start = new Leg("Start", startMarker, endMarker, 0);
|
||||
TEST_BOAT.setCurrentLeg(start);
|
||||
assertEquals(TEST_BOAT.calculateHeading(), 90, 1e-8);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void calculateDueSouthHeadingReturns180() {
|
||||
Marker startMarker = new Marker(ORIGIN_COORDS);
|
||||
Marker endMarker = new Marker(new GPSCoordinate(-50, 0));
|
||||
Leg start = new Leg("Start", startMarker, endMarker, 0);
|
||||
TEST_BOAT.setCurrentLeg(start);
|
||||
assertEquals(TEST_BOAT.calculateHeading(), 180, 1e-8);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void calculateDueWestHeadingReturns270() {
|
||||
Marker startMarker = new Marker(ORIGIN_COORDS);
|
||||
Marker endMarker = new Marker(new GPSCoordinate(0, -50));
|
||||
Leg start = new Leg("Start", startMarker, endMarker, 0);
|
||||
TEST_BOAT.setCurrentLeg(start);
|
||||
assertEquals(TEST_BOAT.calculateHeading(), 270, 1e-8);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createNewBoatCratesInstanceOfSuperClass() {
|
||||
|
||||
BoatInRace testBoat = new BoatInRace("Boat", 20, Color.ALICEBLUE, "tt");
|
||||
testBoat.setName("Name can change");
|
||||
assertTrue(testBoat instanceof Boat);
|
||||
assertTrue(testBoat.getCurrentLeg() == null);
|
||||
assertTrue(testBoat.getCurrentPosition() == null);
|
||||
assertTrue(testBoat.toString().contains("Name can change"));
|
||||
assertEquals(testBoat.getVelocity(), 20.0);
|
||||
assertTrue(testBoat.getVelocityProp().toString().contains("20.0"));
|
||||
assertTrue(testBoat.getAbbrev().equals("tt"));
|
||||
assertTrue(testBoat.getColour().equals(Color.ALICEBLUE));
|
||||
assertFalse(testBoat.isFinished());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -7,130 +7,134 @@ import org.junit.Test;
|
||||
import seng302.Constants;
|
||||
import seng302.GPSCoordinate;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* Created by esa46 on 16/03/17.
|
||||
// */
|
||||
//public class ConstantVelocityRaceTest {
|
||||
//
|
||||
// Leg START_LEG = new Leg("Start", new GPSCoordinate(0, 0), new GPSCoordinate(1, 1),
|
||||
// new GPSCoordinate(50, 50), new GPSCoordinate(51, 51), 0);
|
||||
//
|
||||
// int ONE_HOUR = 3600000; //1 hour in milliseconds
|
||||
//
|
||||
//
|
||||
// @Test
|
||||
// public void updatePositionChangesDistanceTravelled() {
|
||||
//
|
||||
// BoatInRace boat = new BoatInRace("Test", 1, Color.ALICEBLUE, "tt");
|
||||
// boat.setCurrentLeg(START_LEG);
|
||||
// boat.setDistanceTravelledInLeg(0);
|
||||
// BoatInRace[] boats = new BoatInRace[]{boat};
|
||||
//
|
||||
// ArrayList<Leg> legs = new ArrayList<>();
|
||||
// legs.add(START_LEG);
|
||||
//
|
||||
// ConstantVelocityRace race = new ConstantVelocityRace(boats, legs, null, 1);
|
||||
//
|
||||
// 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");
|
||||
// boat.setCurrentLeg(START_LEG);
|
||||
// boat.setDistanceTravelledInLeg(0);
|
||||
// BoatInRace[] boats = new BoatInRace[]{boat};
|
||||
//
|
||||
// ArrayList<Leg> legs = new ArrayList<>();
|
||||
// legs.add(START_LEG);
|
||||
//
|
||||
// ConstantVelocityRace race = new ConstantVelocityRace(boats, legs, null, 1);
|
||||
//
|
||||
// race.updatePosition(boat, ONE_HOUR);
|
||||
// assertEquals(boat.getDistanceTravelledInLeg(), 0, 1e-8);
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void changesToDistanceTravelledAreAdditive() {
|
||||
// BoatInRace boat = new BoatInRace("Test", 5, Color.ALICEBLUE, "tt");
|
||||
// boat.setCurrentLeg(START_LEG);
|
||||
// boat.setDistanceTravelledInLeg(50);
|
||||
// BoatInRace[] boats = new BoatInRace[]{boat};
|
||||
// ArrayList<Leg> legs = new ArrayList<>();
|
||||
// legs.add(START_LEG);
|
||||
//
|
||||
// ConstantVelocityRace race = new ConstantVelocityRace(boats, legs, null, 1);
|
||||
//
|
||||
// race.updatePosition(boat, ONE_HOUR);
|
||||
// assertEquals(boat.getDistanceTravelledInLeg(), boat.getVelocity() + 50, 1e-8);
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void travelling10nmNorthGivesCorrectNewCoordinates() {
|
||||
// GPSCoordinate oldPos = new GPSCoordinate(0, 0);
|
||||
// GPSCoordinate newPos = ConstantVelocityRace.calculatePosition(oldPos, 10, 0);
|
||||
//
|
||||
// GeodeticCalculator calc = new GeodeticCalculator();
|
||||
// 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);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// @Test
|
||||
// public void travelling10nmEastGivesCorrectNewCoordinates() {
|
||||
// GPSCoordinate oldPos = new GPSCoordinate(0, 0);
|
||||
// GPSCoordinate newPos = ConstantVelocityRace.calculatePosition(oldPos, 10, 90);
|
||||
//
|
||||
// GeodeticCalculator calc = new GeodeticCalculator();
|
||||
// calc.setStartingGeographicPoint(0, 0);
|
||||
// calc.setDirection(90, 10 * Constants.NMToMetersConversion);
|
||||
//
|
||||
//
|
||||
// assertEquals(newPos.getLatitude(), 0, 1e-8);
|
||||
// assertEquals(newPos.getLatitude(), calc.getDestinationGeographicPoint().getY(), 1e-8);
|
||||
// assertEquals(newPos.getLongitude(), calc.getDestinationGeographicPoint().getX(), 1e-8);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// @Test
|
||||
// public void travelling10nmWestGivesCorrectNewCoordinates() {
|
||||
// GPSCoordinate oldPos = new GPSCoordinate(0, 0);
|
||||
// GPSCoordinate newPos = ConstantVelocityRace.calculatePosition(oldPos, 10, -90);
|
||||
//
|
||||
// GeodeticCalculator calc = new GeodeticCalculator();
|
||||
// calc.setStartingGeographicPoint(0, 0);
|
||||
// calc.setDirection(-90, 10 * Constants.NMToMetersConversion);
|
||||
//
|
||||
//
|
||||
// assertEquals(newPos.getLatitude(), 0, 1e-8);
|
||||
// assertEquals(newPos.getLatitude(), calc.getDestinationGeographicPoint().getY(), 1e-8);
|
||||
// assertEquals(newPos.getLongitude(), calc.getDestinationGeographicPoint().getX(), 1e-8);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// @Test
|
||||
// public void travelling10nmSouthGivesCorrectNewCoordinates() {
|
||||
// GPSCoordinate oldPos = new GPSCoordinate(0, 0);
|
||||
// GPSCoordinate newPos = ConstantVelocityRace.calculatePosition(oldPos, 10, 180);
|
||||
//
|
||||
// GeodeticCalculator calc = new GeodeticCalculator();
|
||||
// calc.setStartingGeographicPoint(0, 0);
|
||||
// calc.setDirection(180, 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);
|
||||
// }
|
||||
//
|
||||
//}
|
||||
*/
|
||||
public class ConstantVelocityRaceTest {
|
||||
|
||||
Marker START_MARKER = new Marker(new GPSCoordinate(0, 0));
|
||||
Marker END_MARKER = new Marker(new GPSCoordinate(10, 10));
|
||||
Leg START_LEG = new Leg("Start", START_MARKER, END_MARKER, 0);
|
||||
|
||||
int ONE_HOUR = 3600000; //1 hour in milliseconds
|
||||
|
||||
|
||||
private ArrayList<Leg> generateLegsArray() {
|
||||
ArrayList<Leg> legs = new ArrayList<>();
|
||||
legs.add(START_LEG);
|
||||
return legs;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updatePositionChangesDistanceTravelled() {
|
||||
ArrayList<Leg> legs = generateLegsArray();
|
||||
BoatInRace boat = new BoatInRace("Test", 1, Color.ALICEBLUE, "tt");
|
||||
boat.setCurrentLeg(legs.get(0));
|
||||
boat.setDistanceTravelledInLeg(0);
|
||||
BoatInRace[] boats = new BoatInRace[]{boat};
|
||||
|
||||
ConstantVelocityRace race = new ConstantVelocityRace(boats, legs, null, 1);
|
||||
|
||||
race.updatePosition(boat, ONE_HOUR);
|
||||
assertEquals(boat.getDistanceTravelledInLeg(), boat.getVelocity(), 1e-8);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void updatePositionHandlesNoChangeToDistanceTravelled() {
|
||||
|
||||
ArrayList<Leg> legs = generateLegsArray();
|
||||
BoatInRace boat = new BoatInRace("Test", 0, Color.ALICEBLUE, "tt");
|
||||
boat.setCurrentLeg(legs.get(0));
|
||||
boat.setDistanceTravelledInLeg(0);
|
||||
BoatInRace[] boats = new BoatInRace[]{boat};
|
||||
|
||||
ConstantVelocityRace race = new ConstantVelocityRace(boats, legs, null, 1);
|
||||
|
||||
race.updatePosition(boat, ONE_HOUR);
|
||||
assertEquals(boat.getDistanceTravelledInLeg(), 0, 1e-8);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void changesToDistanceTravelledAreAdditive() {
|
||||
|
||||
ArrayList<Leg> legs = generateLegsArray();
|
||||
BoatInRace boat = new BoatInRace("Test", 5, Color.ALICEBLUE, "tt");
|
||||
boat.setCurrentLeg(legs.get(0));
|
||||
boat.setDistanceTravelledInLeg(50);
|
||||
BoatInRace[] boats = new BoatInRace[]{boat};
|
||||
|
||||
ConstantVelocityRace race = new ConstantVelocityRace(boats, legs, null, 1);
|
||||
|
||||
race.updatePosition(boat, ONE_HOUR);
|
||||
assertEquals(boat.getDistanceTravelledInLeg(), boat.getVelocity() + 50, 1e-8);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void travelling10nmNorthGivesCorrectNewCoordinates() {
|
||||
GPSCoordinate oldPos = new GPSCoordinate(0, 0);
|
||||
GPSCoordinate newPos = ConstantVelocityRace.calculatePosition(oldPos, 10, 0);
|
||||
|
||||
GeodeticCalculator calc = new GeodeticCalculator();
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void travelling10nmEastGivesCorrectNewCoordinates() {
|
||||
GPSCoordinate oldPos = new GPSCoordinate(0, 0);
|
||||
GPSCoordinate newPos = ConstantVelocityRace.calculatePosition(oldPos, 10, 90);
|
||||
|
||||
GeodeticCalculator calc = new GeodeticCalculator();
|
||||
calc.setStartingGeographicPoint(0, 0);
|
||||
calc.setDirection(90, 10 * Constants.NMToMetersConversion);
|
||||
|
||||
|
||||
assertEquals(newPos.getLatitude(), 0, 1e-8);
|
||||
assertEquals(newPos.getLatitude(), calc.getDestinationGeographicPoint().getY(), 1e-8);
|
||||
assertEquals(newPos.getLongitude(), calc.getDestinationGeographicPoint().getX(), 1e-8);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void travelling10nmWestGivesCorrectNewCoordinates() {
|
||||
GPSCoordinate oldPos = new GPSCoordinate(0, 0);
|
||||
GPSCoordinate newPos = ConstantVelocityRace.calculatePosition(oldPos, 10, -90);
|
||||
|
||||
GeodeticCalculator calc = new GeodeticCalculator();
|
||||
calc.setStartingGeographicPoint(0, 0);
|
||||
calc.setDirection(-90, 10 * Constants.NMToMetersConversion);
|
||||
|
||||
|
||||
assertEquals(newPos.getLatitude(), 0, 1e-8);
|
||||
assertEquals(newPos.getLatitude(), calc.getDestinationGeographicPoint().getY(), 1e-8);
|
||||
assertEquals(newPos.getLongitude(), calc.getDestinationGeographicPoint().getX(), 1e-8);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void travelling10nmSouthGivesCorrectNewCoordinates() {
|
||||
GPSCoordinate oldPos = new GPSCoordinate(0, 0);
|
||||
GPSCoordinate newPos = ConstantVelocityRace.calculatePosition(oldPos, 10, 180);
|
||||
|
||||
GeodeticCalculator calc = new GeodeticCalculator();
|
||||
calc.setStartingGeographicPoint(0, 0);
|
||||
calc.setDirection(180, 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -5,67 +5,74 @@ import org.junit.Test;
|
||||
import seng302.Constants;
|
||||
import seng302.GPSCoordinate;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.geom.Point2D;
|
||||
|
||||
import static junit.framework.TestCase.assertEquals;
|
||||
|
||||
/**
|
||||
* Created by esa46 on 22/03/17.
|
||||
*/
|
||||
public class LegTest {
|
||||
//
|
||||
// @Test
|
||||
// public void calculateDistanceHandles5nmNorth() {
|
||||
// GeodeticCalculator calc = new GeodeticCalculator();
|
||||
// calc.setStartingGeographicPoint(0, 0);
|
||||
// calc.setDirection(0, 5 * Constants.NMToMetersConversion);
|
||||
//
|
||||
// GPSCoordinate startPoint = new GPSCoordinate(0, 0);
|
||||
// GPSCoordinate endPoint = new GPSCoordinate(calc.getDestinationGeographicPoint().getY(), calc.getDestinationGeographicPoint().getX());
|
||||
// Leg test = new Leg("Test", startPoint, endPoint, 0);
|
||||
// assertEquals(test.getDistance(), 5, 1e-8);
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void calculateDistanceHandles12nmEast() {
|
||||
// GeodeticCalculator calc = new GeodeticCalculator();
|
||||
// calc.setStartingGeographicPoint(0, 0);
|
||||
// calc.setDirection(90, 12 * Constants.NMToMetersConversion);
|
||||
//
|
||||
// GPSCoordinate startPoint = new GPSCoordinate(0, 0);
|
||||
// GPSCoordinate endPoint = new GPSCoordinate(calc.getDestinationGeographicPoint().getY(), calc.getDestinationGeographicPoint().getX());
|
||||
// Leg test = new Leg("Test", startPoint, endPoint, 0);
|
||||
// assertEquals(test.getDistance(), 12, 1e-8);
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void calculateDistanceHandlesHalfnmSouth() {
|
||||
// GeodeticCalculator calc = new GeodeticCalculator();
|
||||
// calc.setStartingGeographicPoint(0, 0);
|
||||
// calc.setDirection(180, 0.5 * Constants.NMToMetersConversion);
|
||||
//
|
||||
// GPSCoordinate startPoint = new GPSCoordinate(0, 0);
|
||||
// GPSCoordinate endPoint = new GPSCoordinate(calc.getDestinationGeographicPoint().getY(), calc.getDestinationGeographicPoint().getX());
|
||||
// Leg test = new Leg("Test", startPoint, endPoint, 0);
|
||||
// assertEquals(test.getDistance(), 0.5, 1e-8);
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void calculateDistanceHandlesPoint1nmWest() {
|
||||
// GeodeticCalculator calc = new GeodeticCalculator();
|
||||
// calc.setStartingGeographicPoint(0, 0);
|
||||
// calc.setDirection(-90, 0.1 * Constants.NMToMetersConversion);
|
||||
//
|
||||
// GPSCoordinate startPoint = new GPSCoordinate(0, 0);
|
||||
// GPSCoordinate endPoint = new GPSCoordinate(calc.getDestinationGeographicPoint().getY(), calc.getDestinationGeographicPoint().getX());
|
||||
// Leg test = new Leg("Test", startPoint, endPoint, 0);
|
||||
// assertEquals(test.getDistance(), 0.1, 1e-8);
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void calculateDistanceHandlesZeroDifference() {
|
||||
// GPSCoordinate startPoint = new GPSCoordinate(0, 0);
|
||||
// GPSCoordinate endPoint = new GPSCoordinate(0, 0);
|
||||
// Leg test = new Leg("Test", startPoint, endPoint, 0);
|
||||
// assertEquals(test.getDistance(), 0, 1e-8);
|
||||
// }
|
||||
|
||||
private Marker ORIGIN_MARKER = new Marker(new GPSCoordinate(0, 0));
|
||||
|
||||
@Test
|
||||
public void calculateDistanceHandles5nmNorth() {
|
||||
GeodeticCalculator calc = new GeodeticCalculator();
|
||||
calc.setStartingGeographicPoint(0, 0);
|
||||
calc.setDirection(0, 5 * Constants.NMToMetersConversion);
|
||||
|
||||
Marker endMarker = getEndMarker(calc.getDestinationGeographicPoint());
|
||||
Leg test = new Leg("Test", ORIGIN_MARKER, endMarker, 0);
|
||||
assertEquals(test.getDistance(), 5, 1e-8);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void calculateDistanceHandles12nmEast() {
|
||||
GeodeticCalculator calc = new GeodeticCalculator();
|
||||
calc.setStartingGeographicPoint(0, 0);
|
||||
calc.setDirection(90, 12 * Constants.NMToMetersConversion);
|
||||
|
||||
Marker endMarker = getEndMarker(calc.getDestinationGeographicPoint());
|
||||
Leg test = new Leg("Test", ORIGIN_MARKER, endMarker, 0);
|
||||
assertEquals(test.getDistance(), 12, 1e-8);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void calculateDistanceHandlesHalfnmSouth() {
|
||||
GeodeticCalculator calc = new GeodeticCalculator();
|
||||
calc.setStartingGeographicPoint(0, 0);
|
||||
calc.setDirection(180, 0.5 * Constants.NMToMetersConversion);
|
||||
|
||||
Marker endMarker = getEndMarker(calc.getDestinationGeographicPoint());
|
||||
Leg test = new Leg("Test", ORIGIN_MARKER, endMarker, 0);
|
||||
assertEquals(test.getDistance(), 0.5, 1e-8);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void calculateDistanceHandlesPoint1nmWest() {
|
||||
GeodeticCalculator calc = new GeodeticCalculator();
|
||||
calc.setStartingGeographicPoint(0, 0);
|
||||
calc.setDirection(-90, 0.1 * Constants.NMToMetersConversion);
|
||||
|
||||
Marker endMarker = getEndMarker(calc.getDestinationGeographicPoint());
|
||||
Leg test = new Leg("Test", ORIGIN_MARKER, endMarker, 0);
|
||||
assertEquals(test.getDistance(), 0.1, 1e-8);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void calculateDistanceHandlesZeroDifference() {
|
||||
|
||||
Leg test = new Leg("Test", ORIGIN_MARKER, ORIGIN_MARKER, 0);
|
||||
assertEquals(test.getDistance(), 0, 1e-8);
|
||||
}
|
||||
|
||||
private Marker getEndMarker(Point2D point) {
|
||||
|
||||
GPSCoordinate coords = new GPSCoordinate(point.getY(), point.getX());
|
||||
|
||||
return new Marker(coords);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// 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"));
|
||||
//
|
||||
// }
|
||||
//}
|
||||
@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<>();
|
||||
|
||||
|
||||
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"));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user