Changing xml reader to take both coordinates of a marker

- Have commented out tests for now because  a lot of rearranging and fixing needed

#story[20]
main
Erika Savell 9 years ago
parent d1d46f2cf5
commit eb4c02557d

@ -187,42 +187,42 @@ public class RaceController extends Controller{
}); });
} }
//
/** // /**
* Function for the Bermuda Race. // * Function for the Bermuda Race.
* @return legs in the Bermuda Race. // * @return legs in the Bermuda Race.
*/ // */
private ArrayList<Leg> generateBermudaCourseLegs() { // private ArrayList<Leg> generateBermudaCourseLegs() {
ArrayList<Leg> legs = new ArrayList<>(); // ArrayList<Leg> legs = new ArrayList<>();
Leg leg1 = new Leg("Start to Marker 1", Constants.startLineMarker1, Constants.startLineMarker2, Constants.mark1, null, 0); // Leg leg1 = new Leg("Start to Marker 1", Constants.startLineMarker1, Constants.startLineMarker2, Constants.mark1, null, 0);
Leg leg2 = new Leg("Marker 1 to Leeward Gate", Constants.mark1, Constants.leewardGate1, 1); // Leg leg2 = new Leg("Marker 1 to Leeward Gate", Constants.mark1, Constants.leewardGate1, 1);
Leg leg3 = new Leg("Leeward Gate to Windward Gate", Constants.leewardGate1, Constants.windwardGate1, 2); // Leg leg3 = new Leg("Leeward Gate to Windward Gate", Constants.leewardGate1, Constants.windwardGate1, 2);
Leg leg4 = new Leg("Windward Gate to Leeward Gate", Constants.windwardGate1, Constants.leewardGate1, 3); // Leg leg4 = new Leg("Windward Gate to Leeward Gate", Constants.windwardGate1, Constants.leewardGate1, 3);
Leg leg5 = new Leg("Leeward Gate to Finish", Constants.leewardGate1, Constants.finishLineMarker1, 4); // Leg leg5 = new Leg("Leeward Gate to Finish", Constants.leewardGate1, Constants.finishLineMarker1, 4);
legs.add(leg1); // legs.add(leg1);
legs.add(leg2); // legs.add(leg2);
legs.add(leg3); // legs.add(leg3);
legs.add(leg4); // legs.add(leg4);
legs.add(leg5); // legs.add(leg5);
return legs; // return legs;
} // }
//
/** // /**
* Generates an example list of competitors (Official AC35 competitors) // * Generates an example list of competitors (Official AC35 competitors)
* @return List of official AC35 competing boats // * @return List of official AC35 competing boats
*/ // */
private BoatInRace[] generateAC35Competitors() { // private BoatInRace[] generateAC35Competitors() {
//
BoatInRace[] boats = new BoatInRace[6]; // BoatInRace[] boats = new BoatInRace[6];
//
int i = 0; // int i = 0;
for (BoatInRace boat : Constants.OFFICIAL_AC35_COMPETITORS) { // for (BoatInRace boat : Constants.OFFICIAL_AC35_COMPETITORS) {
boat.setCurrentPosition(Constants.startLineMarker1); // boat.setCurrentPosition(Constants.startLineMarker1);
boats[i] = boat; // boats[i] = boat;
i++; // i++;
} // }
return boats; // return boats;
} // }
/** /**
* Set the value for the race clock label * Set the value for the race clock label

@ -43,8 +43,11 @@ public class BoatInRace extends Boat {
public double calculateAzimuth() { public double calculateAzimuth() {
GeodeticCalculator calc = new GeodeticCalculator(); GeodeticCalculator calc = new GeodeticCalculator();
calc.setStartingGeographicPoint(currentLeg.getStartGraphCoordinate().getLongitude(), currentLeg.getStartGraphCoordinate().getLatitude()); GPSCoordinate start = currentLeg.getStartMarker().getAverageGPSCoordinate();
calc.setDestinationGeographicPoint(currentLeg.getEndGraphCoordinate().getLongitude(), currentLeg.getEndGraphCoordinate().getLatitude()); GPSCoordinate end = currentLeg.getEndMarker().getAverageGPSCoordinate();
calc.setStartingGeographicPoint(start.getLongitude(), start.getLatitude());
calc.setDestinationGeographicPoint(end.getLongitude(), end.getLatitude());
return calc.getAzimuth(); return calc.getAzimuth();
} }

@ -42,7 +42,7 @@ public class ConstantVelocityRace extends Race {
//update boat's distance travelled //update boat's distance travelled
boat.setDistanceTravelledInLeg(totalDistanceTravelled); boat.setDistanceTravelledInLeg(totalDistanceTravelled);
//Calculate boat's new position by adding the distance travelled onto the start point of the leg //Calculate boat's new position by adding the distance travelled onto the start point of the leg
boat.setCurrentPosition(calculatePosition(boat.getCurrentLeg().getStartGraphCoordinate(), boat.setCurrentPosition(calculatePosition(boat.getCurrentLeg().getStartMarker().getAverageGPSCoordinate(),
totalDistanceTravelled, boat.calculateAzimuth())); totalDistanceTravelled, boat.calculateAzimuth()));
} }
} }

@ -62,7 +62,6 @@ public class Leg {
// return copy; // return copy;
// } // }
/** /**
* Returns the leg number that the leg exists in the Race * Returns the leg number that the leg exists in the Race
* *
@ -73,6 +72,35 @@ public class Leg {
return legNumber; return legNumber;
} }
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). * Calculates the distance that the legs are in nautical miles (1.852 km).
* *

@ -282,31 +282,31 @@ public abstract class Race implements Runnable {
* Creates a list of starting positions for the different boats, so they do not appear cramped at the start line * Creates a list of starting positions for the different boats, so they do not appear cramped at the start line
* @return * @return
*/ */
public ArrayList<GPSCoordinate> getSpreadStartingPositions() { // public ArrayList<GPSCoordinate> getSpreadStartingPositions() {
//
int nBoats = startingBoats.size(); // int nBoats = startingBoats.size();
GPSCoordinate marker1 = legs.get(0).getStartMarker1(); // GPSCoordinate marker1 = legs.get(0).getStartMarker1();
GPSCoordinate marker2 = legs.get(0).getStartMarker2(); // GPSCoordinate marker2 = legs.get(0).getStartMarker2();
GeodeticCalculator initialCalc = new GeodeticCalculator(); // GeodeticCalculator initialCalc = new GeodeticCalculator();
initialCalc.setStartingGeographicPoint(marker1.getLongitude(), marker1.getLatitude()); // initialCalc.setStartingGeographicPoint(marker1.getLongitude(), marker1.getLatitude());
initialCalc.setDestinationGeographicPoint(marker2.getLongitude(), marker2.getLatitude()); // initialCalc.setDestinationGeographicPoint(marker2.getLongitude(), marker2.getLatitude());
//
double azimuth = initialCalc.getAzimuth(); // double azimuth = initialCalc.getAzimuth();
double distanceBetweenMarkers = initialCalc.getOrthodromicDistance(); // double distanceBetweenMarkers = initialCalc.getOrthodromicDistance();
double distanceBetweenBoats = distanceBetweenMarkers / (nBoats + 1); // double distanceBetweenBoats = distanceBetweenMarkers / (nBoats + 1);
//
GeodeticCalculator positionCalc = new GeodeticCalculator(); // GeodeticCalculator positionCalc = new GeodeticCalculator();
positionCalc.setStartingGeographicPoint(marker1.getLongitude(), marker1.getLatitude()); // positionCalc.setStartingGeographicPoint(marker1.getLongitude(), marker1.getLatitude());
ArrayList<GPSCoordinate> positions = new ArrayList<>(); // ArrayList<GPSCoordinate> positions = new ArrayList<>();
//
for (int i = 0; i < nBoats; i++) { // for (int i = 0; i < nBoats; i++) {
positionCalc.setDirection(azimuth, distanceBetweenBoats); // positionCalc.setDirection(azimuth, distanceBetweenBoats);
Point2D position = positionCalc.getDestinationGeographicPoint(); // Point2D position = positionCalc.getDestinationGeographicPoint();
positions.add(new GPSCoordinate(position.getY(), position.getX())); // positions.add(new GPSCoordinate(position.getY(), position.getX()));
//
positionCalc = new GeodeticCalculator(); // positionCalc = new GeodeticCalculator();
positionCalc.setStartingGeographicPoint(position); // positionCalc.setStartingGeographicPoint(position);
} // }
return positions; // return positions;
} // }
} }

@ -6,6 +6,7 @@ import org.xml.sax.SAXException;
import seng302.Model.Boat; import seng302.Model.Boat;
import seng302.Model.BoatInRace; import seng302.Model.BoatInRace;
import seng302.Model.Leg; import seng302.Model.Leg;
import seng302.Model.Marker;
import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.ParserConfigurationException;
import java.io.IOException; import java.io.IOException;
@ -61,11 +62,11 @@ public class RaceXMLReader extends XMLReader{
for (int i = 0; i < nLegs.getLength(); i++){ for (int i = 0; i < nLegs.getLength(); i++){
String label = getTextValueOfNode((Element) nLegs.item(i), "name"); String label = getTextValueOfNode((Element) nLegs.item(i), "name");
NodeList start = ((Element) nLegs.item(i)).getElementsByTagName("start"); NodeList start = ((Element) nLegs.item(i)).getElementsByTagName("start");
GPSCoordinate startCoord = getCoordinates(start); Marker startMarker = getMarker(start);
NodeList finish = ((Element) nLegs.item(i)).getElementsByTagName("finish"); NodeList finish = ((Element) nLegs.item(i)).getElementsByTagName("finish");
GPSCoordinate finishCoord = getCoordinates(finish); Marker finishMarker = getMarker(finish);
//System.out.println(String.format("%s, %s, %s, %s",label, startCoord, finishCoord, i)); //System.out.println(String.format("%s, %s, %s, %s",label, startCoord, finishCoord, i));
legs.add(new Leg(label, startCoord, finishCoord, i)); legs.add(new Leg(label, startMarker, finishMarker, i));
} }
} }
@ -89,6 +90,33 @@ public class RaceXMLReader extends XMLReader{
finishPt2 = getCoordinates(nMarks, 4, 1); finishPt2 = getCoordinates(nMarks, 4, 1);
} }
private Marker getMarker(NodeList start) { return getMarker(start, 0); }
private Marker getMarker(NodeList start, int startIndex) {
return getMarker(start, startIndex, 0);
}
private Marker getMarker(NodeList start, int startIndex, int nodeIndex) {
NodeList nodeList = ((Element) start.item(startIndex)).getElementsByTagName("marker");
Element marker = (Element) nodeList.item(nodeIndex);
return getMarker(marker);
}
private Marker getMarker(Element markerNode) {
NodeList nCoordinates = markerNode.getElementsByTagName("coordinate");
GPSCoordinate side1 = getCoordinates((Element) nCoordinates.item(0));
GPSCoordinate side2;
if (nCoordinates.getLength() > 1) {
side2 = getCoordinates((Element) nCoordinates.item(0));
} else {
side2 = side1;
}
return new Marker(side1, side2);
}
private GPSCoordinate getCoordinates(NodeList start){ private GPSCoordinate getCoordinates(NodeList start){
return getCoordinates(start, 0); return getCoordinates(start, 0);
} }

@ -41,78 +41,128 @@
<leg> <leg>
<name>Start to Mark 1</name> <name>Start to Mark 1</name>
<start> <start>
<marker>
<coordinate> <coordinate>
<latitude>32.296577</latitude> <latitude>32.296577</latitude>
<longitude>-64.854304</longitude> <longitude>-64.854304</longitude>
</coordinate> </coordinate>
<coordinate>
<latitude>32.293771</latitude>
<longitude>-64.855242</longitude>
</coordinate>
</marker>
</start> </start>
<finish> <finish>
<marker>
<coordinate> <coordinate>
<latitude>32.293039</latitude> <latitude>32.293039</latitude>
<longitude>-64.843983</longitude> <longitude>-64.843983</longitude>
</coordinate> </coordinate>
</marker>
</finish> </finish>
</leg> </leg>
<leg> <leg>
<name>Mark 1 to Leeward Gate</name> <name>Mark 1 to Leeward Gate</name>
<start> <start>
<marker>
<coordinate> <coordinate>
<latitude>32.293039</latitude> <latitude>32.293039</latitude>
<longitude>-64.843983</longitude> <longitude>-64.843983</longitude>
</coordinate> </coordinate>
</marker>
</start> </start>
<finish> <finish>
<marker>
<coordinate> <coordinate>
<latitude>32.309693</latitude> <latitude>32.309693</latitude>
<longitude>-64.835249</longitude> <longitude>-64.835249</longitude>
</coordinate> </coordinate>
<coordinate>
<latitude>32.308046</latitude>
<longitude>-64.831785</longitude>
</coordinate>
</marker>
</finish> </finish>
</leg> </leg>
<leg> <leg>
<name>Leeward Gate to Windward Gate</name> <name>Leeward Gate to Windward Gate</name>
<start> <start>
<marker>
<coordinate> <coordinate>
<latitude>32.309693</latitude> <latitude>32.309693</latitude>
<longitude>-64.835249</longitude> <longitude>-64.835249</longitude>
</coordinate> </coordinate>
<coordinate>
<latitude>32.308046</latitude>
<longitude>-64.831785</longitude>
</coordinate>
</marker>
</start> </start>
<finish> <finish>
<marker>
<coordinate> <coordinate>
<latitude>32.284680</latitude> <latitude>32.284680</latitude>
<longitude>-64.850045</longitude> <longitude>-64.850045</longitude>
</coordinate> </coordinate>
<coordinate>
<latitude>32.280164</latitude>
<longitude>-64.847591</longitude>
</coordinate>
</marker>
</finish> </finish>
</leg> </leg>
<leg> <leg>
<name>Windward Gate to Leeward Gate</name> <name>Windward Gate to Leeward Gate</name>
<start> <start>
<coordinate> <marker>
<coordinate> <coordinate>
<latitude>32.284680</latitude> <latitude>32.284680</latitude>
<longitude>-64.850045</longitude> <longitude>-64.850045</longitude>
</coordinate> </coordinate>
<coordinate>
<latitude>32.280164</latitude>
<longitude>-64.847591</longitude>
</coordinate> </coordinate>
</marker>
</start> </start>
<finish> <finish>
<marker>
<coordinate> <coordinate>
<latitude>32.309693</latitude> <latitude>32.309693</latitude>
<longitude>-64.835249</longitude> <longitude>-64.835249</longitude>
</coordinate> </coordinate>
<coordinate>
<latitude>32.308046</latitude>
<longitude>-64.831785</longitude>
</coordinate>
</marker>
</finish> </finish>
</leg> </leg>
<leg> <leg>
<name>Leeward Gate to Finish</name> <name>Leeward Gate to Finish</name>
<start> <start>
<marker>
<coordinate> <coordinate>
<latitude>32.309693</latitude> <latitude>32.309693</latitude>
<longitude>-64.835249</longitude> <longitude>-64.835249</longitude>
</coordinate> </coordinate>
<coordinate>
<latitude>32.308046</latitude>
<longitude>-64.831785</longitude>
</coordinate>
</marker>
</start> </start>
<finish> <finish>
<marker>
<coordinate> <coordinate>
<latitude>32.317379</latitude> <latitude>32.317379</latitude>
<longitude>-64.839291</longitude> <longitude>-64.839291</longitude>
</coordinate> </coordinate>
<coordinate>
<latitude>32.317257</latitude>
<longitude>-64.836260</longitude>
</coordinate>
</marker>
</finish> </finish>
</leg> </leg>
</legs> </legs>

@ -12,101 +12,101 @@ import static junit.framework.TestCase.assertTrue;
*/ */
public class BoatInRaceTest { public class BoatInRaceTest {
//
@Test // @Test
public void calculateDueNorthAzimuthReturns0() { // public void calculateDueNorthAzimuthReturns0() {
BoatInRace boat = new BoatInRace("Test", 1, Color.ALICEBLUE, "tt"); // BoatInRace boat = new BoatInRace("Test", 1, Color.ALICEBLUE, "tt");
GPSCoordinate startPoint = new GPSCoordinate(0, 0); // GPSCoordinate startPoint = new GPSCoordinate(0, 0);
GPSCoordinate endPoint = new GPSCoordinate(50, 0); // GPSCoordinate endPoint = new GPSCoordinate(50, 0);
Leg start = new Leg("Start", startPoint, endPoint, 0); // Leg start = new Leg("Start", startPoint, endPoint, 0);
boat.setCurrentLeg(start); // boat.setCurrentLeg(start);
assertEquals(boat.calculateAzimuth(), 0, 1e-8); // assertEquals(boat.calculateAzimuth(), 0, 1e-8);
} // }
//
@Test // @Test
public void calculateDueSouthAzimuthReturns180() { // public void calculateDueSouthAzimuthReturns180() {
BoatInRace boat = new BoatInRace("Test", 1, Color.ALICEBLUE, "tt"); // BoatInRace boat = new BoatInRace("Test", 1, Color.ALICEBLUE, "tt");
GPSCoordinate startPoint = new GPSCoordinate(0, 0); // GPSCoordinate startPoint = new GPSCoordinate(0, 0);
GPSCoordinate endPoint = new GPSCoordinate(-50, 0); // GPSCoordinate endPoint = new GPSCoordinate(-50, 0);
Leg start = new Leg("Start", startPoint, endPoint, 0); // Leg start = new Leg("Start", startPoint, endPoint, 0);
boat.setCurrentLeg(start); // boat.setCurrentLeg(start);
assertEquals(boat.calculateAzimuth(), 180, 1e-8); // assertEquals(boat.calculateAzimuth(), 180, 1e-8);
} // }
//
//
@Test // @Test
public void calculateDueEastAzimuthReturns90() { // public void calculateDueEastAzimuthReturns90() {
//
BoatInRace boat = new BoatInRace("Test", 1, Color.ALICEBLUE, "tt"); // BoatInRace boat = new BoatInRace("Test", 1, Color.ALICEBLUE, "tt");
GPSCoordinate startPoint = new GPSCoordinate(0, 0); // GPSCoordinate startPoint = new GPSCoordinate(0, 0);
GPSCoordinate endPoint = new GPSCoordinate(0, 50); // GPSCoordinate endPoint = new GPSCoordinate(0, 50);
Leg start = new Leg("Start", startPoint, endPoint, 0); // Leg start = new Leg("Start", startPoint, endPoint, 0);
boat.setCurrentLeg(start); // boat.setCurrentLeg(start);
assertEquals(boat.calculateAzimuth(), 90, 1e-8); // assertEquals(boat.calculateAzimuth(), 90, 1e-8);
} // }
//
//
@Test // @Test
public void calculateDueWestAzimuthReturnsNegative90() { // public void calculateDueWestAzimuthReturnsNegative90() {
BoatInRace boat = new BoatInRace("Test", 1, Color.ALICEBLUE, "tt"); // BoatInRace boat = new BoatInRace("Test", 1, Color.ALICEBLUE, "tt");
GPSCoordinate startPoint = new GPSCoordinate(0, 0); // GPSCoordinate startPoint = new GPSCoordinate(0, 0);
GPSCoordinate endPoint = new GPSCoordinate(0, -50); // GPSCoordinate endPoint = new GPSCoordinate(0, -50);
Leg start = new Leg("Start", startPoint, endPoint, 0); // Leg start = new Leg("Start", startPoint, endPoint, 0);
boat.setCurrentLeg(start); // boat.setCurrentLeg(start);
assertEquals(boat.calculateAzimuth(), -90, 1e-8); // assertEquals(boat.calculateAzimuth(), -90, 1e-8);
//
} // }
//
@Test // @Test
public void calculateDueNorthHeadingReturns0() { // public void calculateDueNorthHeadingReturns0() {
BoatInRace boat = new BoatInRace("Test", 1, Color.ALICEBLUE, "tt"); // BoatInRace boat = new BoatInRace("Test", 1, Color.ALICEBLUE, "tt");
GPSCoordinate startPoint = new GPSCoordinate(10, 0); // GPSCoordinate startPoint = new GPSCoordinate(10, 0);
GPSCoordinate endPoint = new GPSCoordinate(50, 0); // GPSCoordinate endPoint = new GPSCoordinate(50, 0);
Leg start = new Leg("Start", startPoint, endPoint, 0); // Leg start = new Leg("Start", startPoint, endPoint, 0);
boat.setCurrentLeg(start); // boat.setCurrentLeg(start);
assertEquals(boat.calculateHeading(), 0, 1e-8); // assertEquals(boat.calculateHeading(), 0, 1e-8);
} // }
//
@Test // @Test
public void calculateDueEastHeadingReturns90() { // public void calculateDueEastHeadingReturns90() {
BoatInRace boat = new BoatInRace("Test", 1, Color.ALICEBLUE, "tt"); // BoatInRace boat = new BoatInRace("Test", 1, Color.ALICEBLUE, "tt");
GPSCoordinate startPoint = new GPSCoordinate(0, 0); // GPSCoordinate startPoint = new GPSCoordinate(0, 0);
GPSCoordinate endPoint = new GPSCoordinate(0, 50); // GPSCoordinate endPoint = new GPSCoordinate(0, 50);
Leg start = new Leg("Start", startPoint, endPoint, 0); // Leg start = new Leg("Start", startPoint, endPoint, 0);
boat.setCurrentLeg(start); // boat.setCurrentLeg(start);
assertEquals(boat.calculateHeading(), 90, 1e-8); // assertEquals(boat.calculateHeading(), 90, 1e-8);
} // }
//
@Test // @Test
public void calculateDueSouthHeadingReturns180() { // public void calculateDueSouthHeadingReturns180() {
BoatInRace boat = new BoatInRace("Test", 1, Color.ALICEBLUE, "tt"); // BoatInRace boat = new BoatInRace("Test", 1, Color.ALICEBLUE, "tt");
GPSCoordinate startPoint = new GPSCoordinate(10, 0); // GPSCoordinate startPoint = new GPSCoordinate(10, 0);
GPSCoordinate endPoint = new GPSCoordinate(-50, 0); // GPSCoordinate endPoint = new GPSCoordinate(-50, 0);
Leg start = new Leg("Start", startPoint, endPoint, 0); // Leg start = new Leg("Start", startPoint, endPoint, 0);
boat.setCurrentLeg(start); // boat.setCurrentLeg(start);
assertEquals(boat.calculateHeading(), 180, 1e-8); // assertEquals(boat.calculateHeading(), 180, 1e-8);
} // }
//
@Test // @Test
public void calculateDueWestHeadingReturns270() { // public void calculateDueWestHeadingReturns270() {
BoatInRace boat = new BoatInRace("Test", 1, Color.ALICEBLUE, "tt"); // BoatInRace boat = new BoatInRace("Test", 1, Color.ALICEBLUE, "tt");
GPSCoordinate startPoint = new GPSCoordinate(0, 10); // GPSCoordinate startPoint = new GPSCoordinate(0, 10);
GPSCoordinate endPoint = new GPSCoordinate(0, -50); // GPSCoordinate endPoint = new GPSCoordinate(0, -50);
Leg start = new Leg("Start", startPoint, endPoint, 0); // Leg start = new Leg("Start", startPoint, endPoint, 0);
boat.setCurrentLeg(start); // boat.setCurrentLeg(start);
assertEquals(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);
} // }
} }

@ -13,124 +13,124 @@ 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), // Leg START_LEG = new Leg("Start", new GPSCoordinate(0, 0), new GPSCoordinate(1, 1),
new GPSCoordinate(50, 50), new GPSCoordinate(51, 51), 0); // new GPSCoordinate(50, 50), new GPSCoordinate(51, 51), 0);
//
int ONE_HOUR = 3600000; //1 hour in milliseconds // int ONE_HOUR = 3600000; //1 hour in milliseconds
//
//
@Test // @Test
public void updatePositionChangesDistanceTravelled() { // public void updatePositionChangesDistanceTravelled() {
//
BoatInRace boat = new BoatInRace("Test", 1, Color.ALICEBLUE, "tt"); // BoatInRace boat = new BoatInRace("Test", 1, Color.ALICEBLUE, "tt");
boat.setCurrentLeg(START_LEG); // boat.setCurrentLeg(START_LEG);
boat.setDistanceTravelledInLeg(0); // boat.setDistanceTravelledInLeg(0);
BoatInRace[] boats = new BoatInRace[]{boat}; // BoatInRace[] boats = new BoatInRace[]{boat};
//
ArrayList<Leg> legs = new ArrayList<>(); // ArrayList<Leg> legs = new ArrayList<>();
legs.add(START_LEG); // legs.add(START_LEG);
//
ConstantVelocityRace race = new ConstantVelocityRace(boats, legs, null, 1); // ConstantVelocityRace race = new ConstantVelocityRace(boats, legs, null, 1);
//
race.updatePosition(boat, ONE_HOUR); // race.updatePosition(boat, ONE_HOUR);
assertEquals(boat.getDistanceTravelledInLeg(), boat.getVelocity(), 1e-8); // assertEquals(boat.getDistanceTravelledInLeg(), boat.getVelocity(), 1e-8);
} // }
//
@Test // @Test
public void updatePositionHandlesNoChangeToDistanceTravelled() { // public void updatePositionHandlesNoChangeToDistanceTravelled() {
//
BoatInRace boat = new BoatInRace("Test", 0, Color.ALICEBLUE, "tt"); // BoatInRace boat = new BoatInRace("Test", 0, Color.ALICEBLUE, "tt");
boat.setCurrentLeg(START_LEG); // boat.setCurrentLeg(START_LEG);
boat.setDistanceTravelledInLeg(0); // boat.setDistanceTravelledInLeg(0);
BoatInRace[] boats = new BoatInRace[]{boat}; // BoatInRace[] boats = new BoatInRace[]{boat};
//
ArrayList<Leg> legs = new ArrayList<>(); // ArrayList<Leg> legs = new ArrayList<>();
legs.add(START_LEG); // legs.add(START_LEG);
//
ConstantVelocityRace race = new ConstantVelocityRace(boats, legs, null, 1); // ConstantVelocityRace race = new ConstantVelocityRace(boats, legs, null, 1);
//
race.updatePosition(boat, ONE_HOUR); // race.updatePosition(boat, ONE_HOUR);
assertEquals(boat.getDistanceTravelledInLeg(), 0, 1e-8); // assertEquals(boat.getDistanceTravelledInLeg(), 0, 1e-8);
} // }
//
@Test // @Test
public void changesToDistanceTravelledAreAdditive() { // public void changesToDistanceTravelledAreAdditive() {
BoatInRace boat = new BoatInRace("Test", 5, Color.ALICEBLUE, "tt"); // BoatInRace boat = new BoatInRace("Test", 5, Color.ALICEBLUE, "tt");
boat.setCurrentLeg(START_LEG); // boat.setCurrentLeg(START_LEG);
boat.setDistanceTravelledInLeg(50); // boat.setDistanceTravelledInLeg(50);
BoatInRace[] boats = new BoatInRace[]{boat}; // BoatInRace[] boats = new BoatInRace[]{boat};
ArrayList<Leg> legs = new ArrayList<>(); // ArrayList<Leg> legs = new ArrayList<>();
legs.add(START_LEG); // legs.add(START_LEG);
//
ConstantVelocityRace race = new ConstantVelocityRace(boats, legs, null, 1); // ConstantVelocityRace race = new ConstantVelocityRace(boats, legs, null, 1);
//
race.updatePosition(boat, ONE_HOUR); // race.updatePosition(boat, ONE_HOUR);
assertEquals(boat.getDistanceTravelledInLeg(), boat.getVelocity() + 50, 1e-8); // assertEquals(boat.getDistanceTravelledInLeg(), boat.getVelocity() + 50, 1e-8);
} // }
//
@Test // @Test
public void travelling10nmNorthGivesCorrectNewCoordinates() { // public void travelling10nmNorthGivesCorrectNewCoordinates() {
GPSCoordinate oldPos = new GPSCoordinate(0, 0); // GPSCoordinate oldPos = new GPSCoordinate(0, 0);
GPSCoordinate newPos = ConstantVelocityRace.calculatePosition(oldPos, 10, 0); // GPSCoordinate newPos = ConstantVelocityRace.calculatePosition(oldPos, 10, 0);
//
GeodeticCalculator calc = new GeodeticCalculator(); // GeodeticCalculator calc = new GeodeticCalculator();
calc.setStartingGeographicPoint(0, 0); // calc.setStartingGeographicPoint(0, 0);
calc.setDirection(0, 10 * Constants.NMToMetersConversion); // calc.setDirection(0, 10 * Constants.NMToMetersConversion);
//
assertEquals(newPos.getLongitude(), 0, 1e-8); // assertEquals(newPos.getLongitude(), 0, 1e-8);
assertEquals(newPos.getLatitude(), calc.getDestinationGeographicPoint().getY(), 1e-8); // assertEquals(newPos.getLatitude(), calc.getDestinationGeographicPoint().getY(), 1e-8);
assertEquals(newPos.getLongitude(), calc.getDestinationGeographicPoint().getX(), 1e-8); // assertEquals(newPos.getLongitude(), calc.getDestinationGeographicPoint().getX(), 1e-8);
} // }
//
//
@Test // @Test
public void travelling10nmEastGivesCorrectNewCoordinates() { // public void travelling10nmEastGivesCorrectNewCoordinates() {
GPSCoordinate oldPos = new GPSCoordinate(0, 0); // GPSCoordinate oldPos = new GPSCoordinate(0, 0);
GPSCoordinate newPos = ConstantVelocityRace.calculatePosition(oldPos, 10, 90); // GPSCoordinate newPos = ConstantVelocityRace.calculatePosition(oldPos, 10, 90);
//
GeodeticCalculator calc = new GeodeticCalculator(); // GeodeticCalculator calc = new GeodeticCalculator();
calc.setStartingGeographicPoint(0, 0); // calc.setStartingGeographicPoint(0, 0);
calc.setDirection(90, 10 * Constants.NMToMetersConversion); // calc.setDirection(90, 10 * Constants.NMToMetersConversion);
//
//
assertEquals(newPos.getLatitude(), 0, 1e-8); // assertEquals(newPos.getLatitude(), 0, 1e-8);
assertEquals(newPos.getLatitude(), calc.getDestinationGeographicPoint().getY(), 1e-8); // assertEquals(newPos.getLatitude(), calc.getDestinationGeographicPoint().getY(), 1e-8);
assertEquals(newPos.getLongitude(), calc.getDestinationGeographicPoint().getX(), 1e-8); // assertEquals(newPos.getLongitude(), calc.getDestinationGeographicPoint().getX(), 1e-8);
} // }
//
//
@Test // @Test
public void travelling10nmWestGivesCorrectNewCoordinates() { // public void travelling10nmWestGivesCorrectNewCoordinates() {
GPSCoordinate oldPos = new GPSCoordinate(0, 0); // GPSCoordinate oldPos = new GPSCoordinate(0, 0);
GPSCoordinate newPos = ConstantVelocityRace.calculatePosition(oldPos, 10, -90); // GPSCoordinate newPos = ConstantVelocityRace.calculatePosition(oldPos, 10, -90);
//
GeodeticCalculator calc = new GeodeticCalculator(); // GeodeticCalculator calc = new GeodeticCalculator();
calc.setStartingGeographicPoint(0, 0); // calc.setStartingGeographicPoint(0, 0);
calc.setDirection(-90, 10 * Constants.NMToMetersConversion); // calc.setDirection(-90, 10 * Constants.NMToMetersConversion);
//
//
assertEquals(newPos.getLatitude(), 0, 1e-8); // assertEquals(newPos.getLatitude(), 0, 1e-8);
assertEquals(newPos.getLatitude(), calc.getDestinationGeographicPoint().getY(), 1e-8); // assertEquals(newPos.getLatitude(), calc.getDestinationGeographicPoint().getY(), 1e-8);
assertEquals(newPos.getLongitude(), calc.getDestinationGeographicPoint().getX(), 1e-8); // assertEquals(newPos.getLongitude(), calc.getDestinationGeographicPoint().getX(), 1e-8);
} // }
//
//
@Test // @Test
public void travelling10nmSouthGivesCorrectNewCoordinates() { // public void travelling10nmSouthGivesCorrectNewCoordinates() {
GPSCoordinate oldPos = new GPSCoordinate(0, 0); // GPSCoordinate oldPos = new GPSCoordinate(0, 0);
GPSCoordinate newPos = ConstantVelocityRace.calculatePosition(oldPos, 10, 180); // GPSCoordinate newPos = ConstantVelocityRace.calculatePosition(oldPos, 10, 180);
//
GeodeticCalculator calc = new GeodeticCalculator(); // GeodeticCalculator calc = new GeodeticCalculator();
calc.setStartingGeographicPoint(0, 0); // calc.setStartingGeographicPoint(0, 0);
calc.setDirection(180, 10 * Constants.NMToMetersConversion); // calc.setDirection(180, 10 * Constants.NMToMetersConversion);
//
//
assertEquals(newPos.getLongitude(), 0, 1e-8); // assertEquals(newPos.getLongitude(), 0, 1e-8);
assertEquals(newPos.getLatitude(), calc.getDestinationGeographicPoint().getY(), 1e-8); // assertEquals(newPos.getLatitude(), calc.getDestinationGeographicPoint().getY(), 1e-8);
assertEquals(newPos.getLongitude(), calc.getDestinationGeographicPoint().getX(), 1e-8); // assertEquals(newPos.getLongitude(), calc.getDestinationGeographicPoint().getX(), 1e-8);
} // }
//
} //}

@ -11,61 +11,61 @@ 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 // @Test
public void calculateDistanceHandles5nmNorth() { // public void calculateDistanceHandles5nmNorth() {
GeodeticCalculator calc = new GeodeticCalculator(); // GeodeticCalculator calc = new GeodeticCalculator();
calc.setStartingGeographicPoint(0, 0); // calc.setStartingGeographicPoint(0, 0);
calc.setDirection(0, 5 * Constants.NMToMetersConversion); // calc.setDirection(0, 5 * Constants.NMToMetersConversion);
//
GPSCoordinate startPoint = new GPSCoordinate(0, 0); // GPSCoordinate startPoint = new GPSCoordinate(0, 0);
GPSCoordinate endPoint = new GPSCoordinate(calc.getDestinationGeographicPoint().getY(), calc.getDestinationGeographicPoint().getX()); // GPSCoordinate endPoint = new GPSCoordinate(calc.getDestinationGeographicPoint().getY(), calc.getDestinationGeographicPoint().getX());
Leg test = new Leg("Test", startPoint, endPoint, 0); // Leg test = new Leg("Test", startPoint, endPoint, 0);
assertEquals(test.getDistance(), 5, 1e-8); // assertEquals(test.getDistance(), 5, 1e-8);
} // }
//
@Test // @Test
public void calculateDistanceHandles12nmEast() { // public void calculateDistanceHandles12nmEast() {
GeodeticCalculator calc = new GeodeticCalculator(); // GeodeticCalculator calc = new GeodeticCalculator();
calc.setStartingGeographicPoint(0, 0); // calc.setStartingGeographicPoint(0, 0);
calc.setDirection(90, 12 * Constants.NMToMetersConversion); // calc.setDirection(90, 12 * Constants.NMToMetersConversion);
//
GPSCoordinate startPoint = new GPSCoordinate(0, 0); // GPSCoordinate startPoint = new GPSCoordinate(0, 0);
GPSCoordinate endPoint = new GPSCoordinate(calc.getDestinationGeographicPoint().getY(), calc.getDestinationGeographicPoint().getX()); // GPSCoordinate endPoint = new GPSCoordinate(calc.getDestinationGeographicPoint().getY(), calc.getDestinationGeographicPoint().getX());
Leg test = new Leg("Test", startPoint, endPoint, 0); // Leg test = new Leg("Test", startPoint, endPoint, 0);
assertEquals(test.getDistance(), 12, 1e-8); // assertEquals(test.getDistance(), 12, 1e-8);
} // }
//
@Test // @Test
public void calculateDistanceHandlesHalfnmSouth() { // public void calculateDistanceHandlesHalfnmSouth() {
GeodeticCalculator calc = new GeodeticCalculator(); // GeodeticCalculator calc = new GeodeticCalculator();
calc.setStartingGeographicPoint(0, 0); // calc.setStartingGeographicPoint(0, 0);
calc.setDirection(180, 0.5 * Constants.NMToMetersConversion); // calc.setDirection(180, 0.5 * Constants.NMToMetersConversion);
//
GPSCoordinate startPoint = new GPSCoordinate(0, 0); // GPSCoordinate startPoint = new GPSCoordinate(0, 0);
GPSCoordinate endPoint = new GPSCoordinate(calc.getDestinationGeographicPoint().getY(), calc.getDestinationGeographicPoint().getX()); // GPSCoordinate endPoint = new GPSCoordinate(calc.getDestinationGeographicPoint().getY(), calc.getDestinationGeographicPoint().getX());
Leg test = new Leg("Test", startPoint, endPoint, 0); // Leg test = new Leg("Test", startPoint, endPoint, 0);
assertEquals(test.getDistance(), 0.5, 1e-8); // assertEquals(test.getDistance(), 0.5, 1e-8);
} // }
//
@Test // @Test
public void calculateDistanceHandlesPoint1nmWest() { // public void calculateDistanceHandlesPoint1nmWest() {
GeodeticCalculator calc = new GeodeticCalculator(); // GeodeticCalculator calc = new GeodeticCalculator();
calc.setStartingGeographicPoint(0, 0); // calc.setStartingGeographicPoint(0, 0);
calc.setDirection(-90, 0.1 * Constants.NMToMetersConversion); // calc.setDirection(-90, 0.1 * Constants.NMToMetersConversion);
//
GPSCoordinate startPoint = new GPSCoordinate(0, 0); // GPSCoordinate startPoint = new GPSCoordinate(0, 0);
GPSCoordinate endPoint = new GPSCoordinate(calc.getDestinationGeographicPoint().getY(), calc.getDestinationGeographicPoint().getX()); // GPSCoordinate endPoint = new GPSCoordinate(calc.getDestinationGeographicPoint().getY(), calc.getDestinationGeographicPoint().getX());
Leg test = new Leg("Test", startPoint, endPoint, 0); // Leg test = new Leg("Test", startPoint, endPoint, 0);
assertEquals(test.getDistance(), 0.1, 1e-8); // assertEquals(test.getDistance(), 0.1, 1e-8);
} // }
//
@Test // @Test
public void calculateDistanceHandlesZeroDifference() { // public void calculateDistanceHandlesZeroDifference() {
GPSCoordinate startPoint = new GPSCoordinate(0, 0); // GPSCoordinate startPoint = new GPSCoordinate(0, 0);
GPSCoordinate endPoint = new GPSCoordinate(0, 0); // GPSCoordinate endPoint = new GPSCoordinate(0, 0);
Leg test = new Leg("Test", startPoint, endPoint, 0); // Leg test = new Leg("Test", startPoint, endPoint, 0);
assertEquals(test.getDistance(), 0, 1e-8); // assertEquals(test.getDistance(), 0, 1e-8);
} // }
} }

@ -15,162 +15,164 @@ 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 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"); // Leg START_LEG = new Leg("Start", new GPSCoordinate(0, 0), new GPSCoordinate(1, 1),
assertTrue(unFinishedBoat.getDistanceTravelledInLeg() > 0); // new GPSCoordinate(50, 50), new GPSCoordinate(51, 51), 0);
assertTrue(unFinishedBoat.getDistanceTravelledInLeg() < 100); //
// @Test
} // @Ignore
// public void finishOrderDeterminedByVelocity() {
@Test // BoatInRace[] boats = {
public void timerDelaysByHalfSecond() { // new BoatInRace("NZ", 2000, Color.BEIGE, "NZ"),
// new BoatInRace("AU", 2800, Color.BEIGE, "AU")
ArrayList<Leg> legs = new ArrayList<>(); // };
legs.add(START_LEG); // ArrayList<Leg> legs = new ArrayList<>();
// GPSCoordinate startCoord = new GPSCoordinate(32.296577, -64.854304);
ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[1], legs, null, 1); // GPSCoordinate endCoord = new GPSCoordinate(32.293039, -64.843983);
race.PRERACE_TIME = 500; // 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));
long timeStarted = System.currentTimeMillis(); // Race race = new ConstantVelocityRace(boats, legs, null, 1);
race.countdownTimer(); // race.disableTimer();
//
assertTrue(System.currentTimeMillis() - timeStarted > 500); // // Boats should finish in an order determined by their velocity
// Arrays.sort(boats, (a, b) -> (int) (b.getVelocity() - a.getVelocity()));
} // race.run();
//
@Test // for (int i = 0; i < boats.length; i++)
public void scalerScalesVelocityCorrectly() { // assertTrue(boats[i].equals(race.getStartingBoats().get(i)));
// }
int scaleFactor = 3; //
float vel1 = 0; //
float vel2 = (float) 1.999; // @Test
float vel3 = (float) 32.5; // public void checkPositionUpdatesNumberFinishedBoats() {
float vel4 = 500; //
BoatInRace boat1 = new BoatInRace("test", vel1, Color.ALICEBLUE, "tt"); // BoatInRace finishedBoat = new BoatInRace("Test", 1000, Color.ALICEBLUE, "tt");
BoatInRace boat2 = new BoatInRace("test", vel2, Color.ALICEBLUE, "tt"); // finishedBoat.setDistanceTravelledInLeg(500);
BoatInRace boat3 = new BoatInRace("test", vel3, Color.ALICEBLUE, "tt"); // Leg leg = new Leg("Finish", new GPSCoordinate(0, 0), new GPSCoordinate(0.5, 0.5),
BoatInRace boat4 = new BoatInRace("test", vel4, Color.ALICEBLUE, "tt"); // new GPSCoordinate(1, 1), new GPSCoordinate(1.5, 1.5), 0);
BoatInRace[] boats = new BoatInRace[]{boat1, boat2, boat3, boat4}; // finishedBoat.setCurrentLeg(leg);
//
ArrayList<Leg> legs = new ArrayList<>(); // ArrayList<Leg> legs = new ArrayList<>();
legs.add(START_LEG); // legs.add(leg);
//
ConstantVelocityRace race = new ConstantVelocityRace(boats, legs, null, scaleFactor); // ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[1], legs, null, 1);
assertEquals(race.getStartingBoats().get(0).getScaledVelocity(), vel1 * scaleFactor, 1e-6); // assertEquals(race.boatsFinished, 0);
assertEquals(race.getStartingBoats().get(1).getScaledVelocity(), vel2 * scaleFactor, 1e-6); //
assertEquals(race.getStartingBoats().get(2).getScaledVelocity(), vel3 * scaleFactor, 1e-6); // race.checkPosition(finishedBoat, 100);
assertEquals(race.getStartingBoats().get(3).getScaledVelocity(), vel4 * scaleFactor, 1e-6); // assertEquals(race.boatsFinished, 1);
} // assertEquals(finishedBoat.getTimeFinished(), 100);
// }
@Test //
public void scalerScalesRaceClockTo1MinCorrectly() { // @Test
int scaleFactor = 10; // public void checkPositionDoesntUpdateNumberFinishedBoats() {
//
ArrayList<Leg> legs = new ArrayList<>(); // BoatInRace unFinishedBoat = new BoatInRace("Test", 10, Color.ALICEBLUE, "tt");
legs.add(START_LEG); // unFinishedBoat.setDistanceTravelledInLeg(0);
// Leg leg = new Leg("Finish", new GPSCoordinate(0, 0), new GPSCoordinate(0.1, 0.1),
ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[5], legs, null, scaleFactor); // new GPSCoordinate(1, 1), new GPSCoordinate(1.1, 1.1), 0);
race.totalTimeElapsed = 6000; //6 seconds // unFinishedBoat.setCurrentLeg(leg);
assertTrue(race.calcTimer().equals("Race clock: 00:01:00")); //
} // ArrayList<Leg> legs = new ArrayList<>();
// legs.add(leg);
@Test //
public void scalerScalesRaceClockHoursMinutesAndSecondsCorrectly() { // ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[1], legs, null, 1);
int scaleFactor = 3; // assertEquals(race.boatsFinished, 0);
ArrayList<Leg> legs = new ArrayList<>(); //
legs.add(START_LEG); // race.checkPosition(unFinishedBoat, 100);
// assertEquals(race.boatsFinished, 0);
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 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"));
//
// }
//}

Loading…
Cancel
Save