Changed it so Boat can be used as a superclass for StreamedBoat and BoatInRace properly and removed ConstantVelocityRace. Everything that used to use BoatInRace or StreamedBoat now uses it superclass (boat). #pair[jjg64, cbt24] #refactor #story[782]
This commit is contained in:
@@ -1,140 +1,140 @@
|
||||
package seng302.Model;
|
||||
|
||||
|
||||
import javafx.scene.paint.Color;
|
||||
import org.geotools.referencing.GeodeticCalculator;
|
||||
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 {
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
//package seng302.Model;
|
||||
//
|
||||
//
|
||||
//import javafx.scene.paint.Color;
|
||||
//import org.geotools.referencing.GeodeticCalculator;
|
||||
//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 {
|
||||
//
|
||||
// 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);
|
||||
// }
|
||||
//
|
||||
//}
|
||||
|
||||
@@ -30,7 +30,7 @@ public class RaceXMLTest {
|
||||
try {
|
||||
RaceXMLReader raceXMLReader = new RaceXMLReader("raceXML/bermuda_AC35.xml", false);
|
||||
raceXMLReader.readBoats();
|
||||
List<BoatInRace> boats = raceXMLReader.getBoats();
|
||||
List<Boat> boats = raceXMLReader.getBoats();
|
||||
assertTrue(boats.size() == 6);
|
||||
//test boat 1
|
||||
assertEquals(boats.get(0).getName().getValue(), "ORACLE TEAM USA");
|
||||
|
||||
Reference in New Issue
Block a user