Amended and added tests to cope with marker change

#test #story[20]
main
Erika Savell 9 years ago
parent 40a6801477
commit 495158a621

@ -145,7 +145,6 @@ public class RaceController extends Controller{
} }
BoatInRace[] boats = new BoatInRace[raceXMLReader.getBoats().size()]; BoatInRace[] boats = new BoatInRace[raceXMLReader.getBoats().size()];
boats = raceXMLReader.getBoats().toArray(boats); boats = raceXMLReader.getBoats().toArray(boats);
//BoatInRace[] boats = generateAC35Competitors();
raceMap = new ResizableRaceCanvas(); raceMap = new ResizableRaceCanvas();
raceMap.setMouseTransparent(true); raceMap.setMouseTransparent(true);
@ -159,7 +158,6 @@ public class RaceController extends Controller{
startScreen.setVisible(false); startScreen.setVisible(false);
ongoingRacePane.setVisible(true); ongoingRacePane.setVisible(true);
//ArrayList<Leg> legs = generateBermudaCourseLegs();
ArrayList<Leg> legs = raceXMLReader.getLegs(); ArrayList<Leg> legs = raceXMLReader.getLegs();
ConstantVelocityRace race = new ConstantVelocityRace(boats, legs, this, scaleFactor); ConstantVelocityRace race = new ConstantVelocityRace(boats, legs, this, scaleFactor);
@ -195,7 +193,6 @@ public class RaceController extends Controller{
timer.setText(time); timer.setText(time);
} }
/** /**
* Set the value for the fps label * Set the value for the fps label
* @param fps fps that the label will be updated to * @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) { public Boat(String name, double velocity, String abbrev) {
this.velocity = velocity; this.velocity = velocity;
this.velocityProp = new SimpleStringProperty(String.valueOf(velocity* 1.94384)); this.velocityProp = new SimpleStringProperty(String.valueOf(velocity));
this.abbrev = abbrev; this.abbrev = abbrev;
this.name = new SimpleStringProperty(name); 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() { public Marker getStartMarker() {
return startMarker; return startMarker;
} }
public void setStartMarker(Marker startMarker) {
this.startMarker = startMarker;
}
public Marker getEndMarker() { public Marker getEndMarker() {
return endMarker; 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). * Calculates the distance that the legs are in nautical miles (1.852 km).
* *

@ -35,25 +35,6 @@ public class Marker {
return averageGPSCoordinate; 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() { private GPSCoordinate calculateAverage() {

@ -50,24 +50,24 @@ public abstract class Race implements Runnable {
} }
} }
/** // /**
* Constructor for Race class // * Constructor for Race class
* @param boats boats participating in the race. // * @param boats boats participating in the race.
* @param legs legs that there are in the race. // * @param legs legs that there are in the race.
*/ // */
public Race(BoatInRace[] boats, ArrayList<Leg> legs, int scaleFactor) { // public Race(BoatInRace[] boats, ArrayList<Leg> legs, int scaleFactor) {
if (boats.length > 0) { // if (boats.length > 0) {
for (BoatInRace boat : boats) { // for (BoatInRace boat : boats) {
if (boat != null) { // if (boat != null) {
boat.setScaledVelocity(boat.getVelocity() * scaleFactor); // boat.setScaledVelocity(boat.getVelocity() * scaleFactor);
} // }
} // }
} // }
this.startingBoats = FXCollections.observableArrayList(boats); // this.startingBoats = FXCollections.observableArrayList(boats);
this.legs = legs; // this.legs = legs;
this.legs.add(new Leg("Finish", this.legs.size())); // this.legs.add(new Leg("Finish", this.legs.size()));
this.scaleFactor = scaleFactor; // this.scaleFactor = scaleFactor;
} // }
protected void initialiseBoats() { protected void initialiseBoats() {

@ -2,37 +2,37 @@
<boats> <boats>
<boat> <boat>
<name>ORACLE TEAM USA</name> <name>ORACLE TEAM USA</name>
<speed>300</speed> <speed>30</speed>
<abbr>USA</abbr> <abbr>USA</abbr>
<colour>BLUEVIOLET</colour> <colour>BLUEVIOLET</colour>
</boat> </boat>
<boat> <boat>
<name>Land Rover BAR</name> <name>Land Rover BAR</name>
<speed>500</speed> <speed>50</speed>
<abbr>BAR</abbr> <abbr>BAR</abbr>
<colour>BLACK</colour> <colour>BLACK</colour>
</boat> </boat>
<boat> <boat>
<name>SoftBank Team Japan</name> <name>SoftBank Team Japan</name>
<speed>400</speed> <speed>40</speed>
<abbr>JAP</abbr> <abbr>JAP</abbr>
<colour>RED</colour> <colour>RED</colour>
</boat> </boat>
<boat> <boat>
<name>Groupama Team France</name> <name>Groupama Team France</name>
<speed>350</speed> <speed>35</speed>
<abbr>FRN</abbr> <abbr>FRN</abbr>
<colour>ORANGE</colour> <colour>ORANGE</colour>
</boat> </boat>
<boat> <boat>
<name>Artemis Racing</name> <name>Artemis Racing</name>
<speed>440</speed> <speed>44</speed>
<abbr>ART</abbr> <abbr>ART</abbr>
<colour>DARKOLIVEGREEN</colour> <colour>DARKOLIVEGREEN</colour>
</boat> </boat>
<boat> <boat>
<name>Emirates Team New Zealand</name> <name>Emirates Team New Zealand</name>
<speed>620</speed> <speed>62</speed>
<abbr>ENZ</abbr> <abbr>ENZ</abbr>
<colour>LIMEGREEN</colour> <colour>LIMEGREEN</colour>
</boat> </boat>

@ -5,6 +5,7 @@ import org.junit.Test;
import seng302.GPSCoordinate; import seng302.GPSCoordinate;
import static junit.framework.TestCase.assertEquals; import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.assertFalse;
import static junit.framework.TestCase.assertTrue; import static junit.framework.TestCase.assertTrue;
/** /**
@ -12,101 +13,104 @@ import static junit.framework.TestCase.assertTrue;
*/ */
public class BoatInRaceTest { public class BoatInRaceTest {
//
// @Test private GPSCoordinate ORIGIN_COORDS = new GPSCoordinate(0, 0);
// public void calculateDueNorthAzimuthReturns0() { private BoatInRace TEST_BOAT = new BoatInRace("Test", 1, Color.ALICEBLUE, "tt");
// BoatInRace boat = new BoatInRace("Test", 1, Color.ALICEBLUE, "tt");
// GPSCoordinate startPoint = new GPSCoordinate(0, 0);
// GPSCoordinate endPoint = new GPSCoordinate(50, 0); @Test
// Leg start = new Leg("Start", startPoint, endPoint, 0); public void calculateDueNorthAzimuthReturns0() {
// boat.setCurrentLeg(start);
// assertEquals(boat.calculateAzimuth(), 0, 1e-8); Marker startMarker = new Marker(ORIGIN_COORDS);
// } Marker endMarker = new Marker(new GPSCoordinate(50, 0));
// Leg start = new Leg("Start", startMarker, endMarker, 0);
// @Test TEST_BOAT.setCurrentLeg(start);
// public void calculateDueSouthAzimuthReturns180() { assertEquals(TEST_BOAT.calculateAzimuth(), 0, 1e-8);
// BoatInRace boat = new BoatInRace("Test", 1, Color.ALICEBLUE, "tt"); }
// GPSCoordinate startPoint = new GPSCoordinate(0, 0);
// GPSCoordinate endPoint = new GPSCoordinate(-50, 0); @Test
// Leg start = new Leg("Start", startPoint, endPoint, 0); public void calculateDueSouthAzimuthReturns180() {
// boat.setCurrentLeg(start); Marker startMarker = new Marker(ORIGIN_COORDS);
// assertEquals(boat.calculateAzimuth(), 180, 1e-8); 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() {
//
// BoatInRace boat = new BoatInRace("Test", 1, Color.ALICEBLUE, "tt"); @Test
// GPSCoordinate startPoint = new GPSCoordinate(0, 0); public void calculateDueEastAzimuthReturns90() {
// GPSCoordinate endPoint = new GPSCoordinate(0, 50);
// Leg start = new Leg("Start", startPoint, endPoint, 0); Marker startMarker = new Marker(ORIGIN_COORDS);
// boat.setCurrentLeg(start); Marker endMarker = new Marker(new GPSCoordinate(0, 50));
// assertEquals(boat.calculateAzimuth(), 90, 1e-8); Leg start = new Leg("Start", startMarker, endMarker, 0);
// } TEST_BOAT.setCurrentLeg(start);
// assertEquals(TEST_BOAT.calculateAzimuth(), 90, 1e-8);
// }
// @Test
// public void calculateDueWestAzimuthReturnsNegative90() {
// BoatInRace boat = new BoatInRace("Test", 1, Color.ALICEBLUE, "tt"); @Test
// GPSCoordinate startPoint = new GPSCoordinate(0, 0); public void calculateDueWestAzimuthReturnsNegative90() {
// GPSCoordinate endPoint = new GPSCoordinate(0, -50); Marker startMarker = new Marker(ORIGIN_COORDS);
// Leg start = new Leg("Start", startPoint, endPoint, 0); Marker endMarker = new Marker(new GPSCoordinate(0, -50));
// boat.setCurrentLeg(start); Leg start = new Leg("Start", startMarker, endMarker, 0);
// assertEquals(boat.calculateAzimuth(), -90, 1e-8); TEST_BOAT.setCurrentLeg(start);
// assertEquals(TEST_BOAT.calculateAzimuth(), -90, 1e-8);
// }
// }
// @Test
// public void calculateDueNorthHeadingReturns0() { @Test
// BoatInRace boat = new BoatInRace("Test", 1, Color.ALICEBLUE, "tt"); public void calculateDueNorthHeadingReturns0() {
// GPSCoordinate startPoint = new GPSCoordinate(10, 0);
// GPSCoordinate endPoint = new GPSCoordinate(50, 0); Marker startMarker = new Marker(ORIGIN_COORDS);
// Leg start = new Leg("Start", startPoint, endPoint, 0); Marker endMarker = new Marker(new GPSCoordinate(50, 0));
// boat.setCurrentLeg(start); Leg start = new Leg("Start", startMarker, endMarker, 0);
// assertEquals(boat.calculateHeading(), 0, 1e-8); TEST_BOAT.setCurrentLeg(start);
// } assertEquals(TEST_BOAT.calculateHeading(), 0, 1e-8);
// }
// @Test
// public void calculateDueEastHeadingReturns90() {
// BoatInRace boat = new BoatInRace("Test", 1, Color.ALICEBLUE, "tt"); @Test
// GPSCoordinate startPoint = new GPSCoordinate(0, 0); public void calculateDueEastHeadingReturns90() {
// GPSCoordinate endPoint = new GPSCoordinate(0, 50); Marker startMarker = new Marker(ORIGIN_COORDS);
// Leg start = new Leg("Start", startPoint, endPoint, 0); Marker endMarker = new Marker(new GPSCoordinate(0, 50));
// boat.setCurrentLeg(start); Leg start = new Leg("Start", startMarker, endMarker, 0);
// assertEquals(boat.calculateHeading(), 90, 1e-8); TEST_BOAT.setCurrentLeg(start);
// } assertEquals(TEST_BOAT.calculateHeading(), 90, 1e-8);
// }
// @Test
// public void calculateDueSouthHeadingReturns180() { @Test
// BoatInRace boat = new BoatInRace("Test", 1, Color.ALICEBLUE, "tt"); public void calculateDueSouthHeadingReturns180() {
// GPSCoordinate startPoint = new GPSCoordinate(10, 0); Marker startMarker = new Marker(ORIGIN_COORDS);
// GPSCoordinate endPoint = new GPSCoordinate(-50, 0); Marker endMarker = new Marker(new GPSCoordinate(-50, 0));
// Leg start = new Leg("Start", startPoint, endPoint, 0); Leg start = new Leg("Start", startMarker, endMarker, 0);
// boat.setCurrentLeg(start); TEST_BOAT.setCurrentLeg(start);
// assertEquals(boat.calculateHeading(), 180, 1e-8); assertEquals(TEST_BOAT.calculateHeading(), 180, 1e-8);
// } }
//
// @Test @Test
// public void calculateDueWestHeadingReturns270() { public void calculateDueWestHeadingReturns270() {
// BoatInRace boat = new BoatInRace("Test", 1, Color.ALICEBLUE, "tt"); Marker startMarker = new Marker(ORIGIN_COORDS);
// GPSCoordinate startPoint = new GPSCoordinate(0, 10); Marker endMarker = new Marker(new GPSCoordinate(0, -50));
// GPSCoordinate endPoint = new GPSCoordinate(0, -50); Leg start = new Leg("Start", startMarker, endMarker, 0);
// Leg start = new Leg("Start", startPoint, endPoint, 0); TEST_BOAT.setCurrentLeg(start);
// boat.setCurrentLeg(start); assertEquals(TEST_BOAT.calculateHeading(), 270, 1e-8);
// assertEquals(boat.calculateHeading(), 270, 1e-8); }
// }
// @Test
// @Test public void createNewBoatCratesInstanceOfSuperClass() {
// public void createNewBoatCratesInstanceOfSuperClass() {
// BoatInRace testBoat = new BoatInRace("Boat", 20, Color.ALICEBLUE, "tt");
// BoatInRace testBoat = new BoatInRace("Boat", 20, Color.ALICEBLUE, "tt"); testBoat.setName("Name can change");
// testBoat.setName("Name can change"); assertTrue(testBoat instanceof Boat);
// assertTrue(testBoat instanceof Boat); assertTrue(testBoat.getCurrentLeg() == null);
// assertTrue(testBoat.getCurrentLeg() == null); assertTrue(testBoat.getCurrentPosition() == null);
// assertTrue(testBoat.getCurrentPosition() == null); assertTrue(testBoat.toString().contains("Name can change"));
// assertTrue(testBoat.toString().contains("Name can change")); assertEquals(testBoat.getVelocity(), 20.0);
// 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.Constants;
import seng302.GPSCoordinate; import seng302.GPSCoordinate;
import java.lang.reflect.Array;
import java.util.ArrayList; import java.util.ArrayList;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
/** /**
* Created by esa46 on 16/03/17. * Created by esa46 on 16/03/17.
// */ */
//public class ConstantVelocityRaceTest { public class ConstantVelocityRaceTest {
//
// Leg START_LEG = new Leg("Start", new GPSCoordinate(0, 0), new GPSCoordinate(1, 1), Marker START_MARKER = new Marker(new GPSCoordinate(0, 0));
// new GPSCoordinate(50, 50), new GPSCoordinate(51, 51), 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
// int ONE_HOUR = 3600000; //1 hour in milliseconds
//
// @Test
// public void updatePositionChangesDistanceTravelled() { private ArrayList<Leg> generateLegsArray() {
// ArrayList<Leg> legs = new ArrayList<>();
// BoatInRace boat = new BoatInRace("Test", 1, Color.ALICEBLUE, "tt"); legs.add(START_LEG);
// boat.setCurrentLeg(START_LEG); return legs;
// boat.setDistanceTravelledInLeg(0); }
// BoatInRace[] boats = new BoatInRace[]{boat};
// @Test
// ArrayList<Leg> legs = new ArrayList<>(); public void updatePositionChangesDistanceTravelled() {
// legs.add(START_LEG); ArrayList<Leg> legs = generateLegsArray();
// BoatInRace boat = new BoatInRace("Test", 1, Color.ALICEBLUE, "tt");
// ConstantVelocityRace race = new ConstantVelocityRace(boats, legs, null, 1); boat.setCurrentLeg(legs.get(0));
// boat.setDistanceTravelledInLeg(0);
// race.updatePosition(boat, ONE_HOUR); BoatInRace[] boats = new BoatInRace[]{boat};
// assertEquals(boat.getDistanceTravelledInLeg(), boat.getVelocity(), 1e-8);
// } ConstantVelocityRace race = new ConstantVelocityRace(boats, legs, null, 1);
//
// @Test race.updatePosition(boat, ONE_HOUR);
// public void updatePositionHandlesNoChangeToDistanceTravelled() { assertEquals(boat.getDistanceTravelledInLeg(), boat.getVelocity(), 1e-8);
// }
// BoatInRace boat = new BoatInRace("Test", 0, Color.ALICEBLUE, "tt");
// boat.setCurrentLeg(START_LEG);
// boat.setDistanceTravelledInLeg(0); @Test
// BoatInRace[] boats = new BoatInRace[]{boat}; public void updatePositionHandlesNoChangeToDistanceTravelled() {
//
// ArrayList<Leg> legs = new ArrayList<>(); ArrayList<Leg> legs = generateLegsArray();
// legs.add(START_LEG); BoatInRace boat = new BoatInRace("Test", 0, Color.ALICEBLUE, "tt");
// boat.setCurrentLeg(legs.get(0));
// ConstantVelocityRace race = new ConstantVelocityRace(boats, legs, null, 1); boat.setDistanceTravelledInLeg(0);
// BoatInRace[] boats = new BoatInRace[]{boat};
// race.updatePosition(boat, ONE_HOUR);
// assertEquals(boat.getDistanceTravelledInLeg(), 0, 1e-8); ConstantVelocityRace race = new ConstantVelocityRace(boats, legs, null, 1);
// }
// race.updatePosition(boat, ONE_HOUR);
// @Test assertEquals(boat.getDistanceTravelledInLeg(), 0, 1e-8);
// public void changesToDistanceTravelledAreAdditive() { }
// BoatInRace boat = new BoatInRace("Test", 5, Color.ALICEBLUE, "tt");
// boat.setCurrentLeg(START_LEG); @Test
// boat.setDistanceTravelledInLeg(50); public void changesToDistanceTravelledAreAdditive() {
// BoatInRace[] boats = new BoatInRace[]{boat};
// ArrayList<Leg> legs = new ArrayList<>(); ArrayList<Leg> legs = generateLegsArray();
// legs.add(START_LEG); BoatInRace boat = new BoatInRace("Test", 5, Color.ALICEBLUE, "tt");
// boat.setCurrentLeg(legs.get(0));
// ConstantVelocityRace race = new ConstantVelocityRace(boats, legs, null, 1); boat.setDistanceTravelledInLeg(50);
// BoatInRace[] boats = new BoatInRace[]{boat};
// race.updatePosition(boat, ONE_HOUR);
// assertEquals(boat.getDistanceTravelledInLeg(), boat.getVelocity() + 50, 1e-8); ConstantVelocityRace race = new ConstantVelocityRace(boats, legs, null, 1);
// }
// race.updatePosition(boat, ONE_HOUR);
// @Test assertEquals(boat.getDistanceTravelledInLeg(), boat.getVelocity() + 50, 1e-8);
// public void travelling10nmNorthGivesCorrectNewCoordinates() { }
// GPSCoordinate oldPos = new GPSCoordinate(0, 0);
// GPSCoordinate newPos = ConstantVelocityRace.calculatePosition(oldPos, 10, 0); @Test
// public void travelling10nmNorthGivesCorrectNewCoordinates() {
// GeodeticCalculator calc = new GeodeticCalculator(); GPSCoordinate oldPos = new GPSCoordinate(0, 0);
// calc.setStartingGeographicPoint(0, 0); GPSCoordinate newPos = ConstantVelocityRace.calculatePosition(oldPos, 10, 0);
// calc.setDirection(0, 10 * Constants.NMToMetersConversion);
// GeodeticCalculator calc = new GeodeticCalculator();
// assertEquals(newPos.getLongitude(), 0, 1e-8); calc.setStartingGeographicPoint(0, 0);
// assertEquals(newPos.getLatitude(), calc.getDestinationGeographicPoint().getY(), 1e-8); calc.setDirection(0, 10 * Constants.NMToMetersConversion);
// assertEquals(newPos.getLongitude(), calc.getDestinationGeographicPoint().getX(), 1e-8);
// } 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); @Test
// public void travelling10nmEastGivesCorrectNewCoordinates() {
// GeodeticCalculator calc = new GeodeticCalculator(); GPSCoordinate oldPos = new GPSCoordinate(0, 0);
// calc.setStartingGeographicPoint(0, 0); GPSCoordinate newPos = ConstantVelocityRace.calculatePosition(oldPos, 10, 90);
// calc.setDirection(90, 10 * Constants.NMToMetersConversion);
// GeodeticCalculator calc = new GeodeticCalculator();
// calc.setStartingGeographicPoint(0, 0);
// assertEquals(newPos.getLatitude(), 0, 1e-8); calc.setDirection(90, 10 * Constants.NMToMetersConversion);
// assertEquals(newPos.getLatitude(), calc.getDestinationGeographicPoint().getY(), 1e-8);
// assertEquals(newPos.getLongitude(), calc.getDestinationGeographicPoint().getX(), 1e-8);
// } 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); @Test
// public void travelling10nmWestGivesCorrectNewCoordinates() {
// GeodeticCalculator calc = new GeodeticCalculator(); GPSCoordinate oldPos = new GPSCoordinate(0, 0);
// calc.setStartingGeographicPoint(0, 0); GPSCoordinate newPos = ConstantVelocityRace.calculatePosition(oldPos, 10, -90);
// calc.setDirection(-90, 10 * Constants.NMToMetersConversion);
// GeodeticCalculator calc = new GeodeticCalculator();
// calc.setStartingGeographicPoint(0, 0);
// assertEquals(newPos.getLatitude(), 0, 1e-8); calc.setDirection(-90, 10 * Constants.NMToMetersConversion);
// assertEquals(newPos.getLatitude(), calc.getDestinationGeographicPoint().getY(), 1e-8);
// assertEquals(newPos.getLongitude(), calc.getDestinationGeographicPoint().getX(), 1e-8);
// } 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); @Test
// public void travelling10nmSouthGivesCorrectNewCoordinates() {
// GeodeticCalculator calc = new GeodeticCalculator(); GPSCoordinate oldPos = new GPSCoordinate(0, 0);
// calc.setStartingGeographicPoint(0, 0); GPSCoordinate newPos = ConstantVelocityRace.calculatePosition(oldPos, 10, 180);
// calc.setDirection(180, 10 * Constants.NMToMetersConversion);
// GeodeticCalculator calc = new GeodeticCalculator();
// calc.setStartingGeographicPoint(0, 0);
// assertEquals(newPos.getLongitude(), 0, 1e-8); calc.setDirection(180, 10 * Constants.NMToMetersConversion);
// assertEquals(newPos.getLatitude(), calc.getDestinationGeographicPoint().getY(), 1e-8);
// assertEquals(newPos.getLongitude(), calc.getDestinationGeographicPoint().getX(), 1e-8);
// } 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.Constants;
import seng302.GPSCoordinate; import seng302.GPSCoordinate;
import java.awt.*;
import java.awt.geom.Point2D;
import static junit.framework.TestCase.assertEquals; import static junit.framework.TestCase.assertEquals;
/** /**
* Created by esa46 on 22/03/17. * Created by esa46 on 22/03/17.
*/ */
public class LegTest { 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. * Created by esa46 on 15/03/17.
*/ */
public class RaceTest { 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);
}
@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);
// Leg START_LEG = new Leg("Start", new GPSCoordinate(0, 0), new GPSCoordinate(1, 1), legs.add(FINISH_LEG);
// new GPSCoordinate(50, 50), new GPSCoordinate(51, 51), 0);
// ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[1], legs, null, 1);
// @Test
// @Ignore BoatInRace unFinishedBoat = new BoatInRace("Test", 10, Color.ALICEBLUE, "tt");
// public void finishOrderDeterminedByVelocity() { unFinishedBoat.setDistanceTravelledInLeg(100);
// BoatInRace[] boats = { unFinishedBoat.setCurrentLeg(START_LEG);
// new BoatInRace("NZ", 2000, Color.BEIGE, "NZ"),
// new BoatInRace("AU", 2800, Color.BEIGE, "AU") race.checkPosition(unFinishedBoat, 100);
// }; assertEquals(unFinishedBoat.getCurrentLeg().getName(), "Finish");
// ArrayList<Leg> legs = new ArrayList<>(); assertTrue(unFinishedBoat.getDistanceTravelledInLeg() > 0);
// GPSCoordinate startCoord = new GPSCoordinate(32.296577, -64.854304); assertTrue(unFinishedBoat.getDistanceTravelledInLeg() < 100);
// 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); @Test
// race.disableTimer(); public void timerDelaysByHalfSecond() {
//
// // Boats should finish in an order determined by their velocity ArrayList<Leg> legs = new ArrayList<>();
// Arrays.sort(boats, (a, b) -> (int) (b.getVelocity() - a.getVelocity())); legs.add(START_LEG);
// race.run();
// ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[1], legs, null, 1);
// for (int i = 0; i < boats.length; i++) race.PRERACE_TIME = 500;
// assertTrue(boats[i].equals(race.getStartingBoats().get(i)));
// } long timeStarted = System.currentTimeMillis();
// race.countdownTimer();
//
// @Test assertTrue(System.currentTimeMillis() - timeStarted > 500);
// public void checkPositionUpdatesNumberFinishedBoats() {
// }
// BoatInRace finishedBoat = new BoatInRace("Test", 1000, Color.ALICEBLUE, "tt");
// finishedBoat.setDistanceTravelledInLeg(500); @Test
// Leg leg = new Leg("Finish", new GPSCoordinate(0, 0), new GPSCoordinate(0.5, 0.5), public void scalerScalesVelocityCorrectly() {
// new GPSCoordinate(1, 1), new GPSCoordinate(1.5, 1.5), 0);
// finishedBoat.setCurrentLeg(leg); int scaleFactor = 3;
// float vel1 = 0;
// ArrayList<Leg> legs = new ArrayList<>(); float vel2 = (float) 1.999;
// legs.add(leg); float vel3 = (float) 32.5;
// float vel4 = 500;
// ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[1], legs, null, 1); BoatInRace boat1 = new BoatInRace("test", vel1, Color.ALICEBLUE, "tt");
// assertEquals(race.boatsFinished, 0); BoatInRace boat2 = new BoatInRace("test", vel2, Color.ALICEBLUE, "tt");
// BoatInRace boat3 = new BoatInRace("test", vel3, Color.ALICEBLUE, "tt");
// race.checkPosition(finishedBoat, 100); BoatInRace boat4 = new BoatInRace("test", vel4, Color.ALICEBLUE, "tt");
// assertEquals(race.boatsFinished, 1); BoatInRace[] boats = new BoatInRace[]{boat1, boat2, boat3, boat4};
// assertEquals(finishedBoat.getTimeFinished(), 100);
// } ArrayList<Leg> legs = new ArrayList<>();
// legs.add(START_LEG);
// @Test
// public void checkPositionDoesntUpdateNumberFinishedBoats() { ConstantVelocityRace race = new ConstantVelocityRace(boats, legs, null, scaleFactor);
// assertEquals(race.getStartingBoats().get(0).getScaledVelocity(), vel1 * scaleFactor, 1e-6);
// BoatInRace unFinishedBoat = new BoatInRace("Test", 10, Color.ALICEBLUE, "tt"); assertEquals(race.getStartingBoats().get(1).getScaledVelocity(), vel2 * scaleFactor, 1e-6);
// unFinishedBoat.setDistanceTravelledInLeg(0); assertEquals(race.getStartingBoats().get(2).getScaledVelocity(), vel3 * scaleFactor, 1e-6);
// Leg leg = new Leg("Finish", new GPSCoordinate(0, 0), new GPSCoordinate(0.1, 0.1), assertEquals(race.getStartingBoats().get(3).getScaledVelocity(), vel4 * scaleFactor, 1e-6);
// new GPSCoordinate(1, 1), new GPSCoordinate(1.1, 1.1), 0); }
// unFinishedBoat.setCurrentLeg(leg);
// @Test
// ArrayList<Leg> legs = new ArrayList<>(); public void scalerScalesRaceClockTo1MinCorrectly() {
// legs.add(leg); int scaleFactor = 10;
//
// ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[1], legs, null, 1); ArrayList<Leg> legs = new ArrayList<>();
// assertEquals(race.boatsFinished, 0); legs.add(START_LEG);
//
// race.checkPosition(unFinishedBoat, 100); ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[5], legs, null, scaleFactor);
// assertEquals(race.boatsFinished, 0); race.totalTimeElapsed = 6000; //6 seconds
// } assertTrue(race.calcTimer().equals("Race clock: 00:01:00"));
// }
//
// @Test @Test
// public void distanceTravelledBeforeUpdatingLegIsRetained() { public void scalerScalesRaceClockHoursMinutesAndSecondsCorrectly() {
// int scaleFactor = 3;
// ArrayList<Leg> legs = new ArrayList<>(); ArrayList<Leg> legs = new ArrayList<>();
// legs.add(START_LEG);
// 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); ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[5], legs, null, scaleFactor);
// Leg leg2 = new Leg("2", new GPSCoordinate(0, 0), new GPSCoordinate(0.5, 0.5), race.totalTimeElapsed = 3213000;
// new GPSCoordinate(1, 1), new GPSCoordinate(1.5, 1.5), 1); assertTrue(race.calcTimer().equals("Race clock: 02:40:39"));
//
// 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"));
//
// }
//}

Loading…
Cancel
Save