Added shared.enums.XMLFileType, which is used to specify if a string contains a file path or file contents. Updated the XML readers to use it. Testing: Moved the networking tests and resources into racevisionGame module. Moved the remaining tests from visualiser into racevisionGame, and added a few empty tests to implement later.main
parent
10e80bca05
commit
4bcfc01ceb
@ -0,0 +1,24 @@
|
||||
package shared.enums;
|
||||
|
||||
/**
|
||||
* Represents the various ways in which we want to open/read an xml file - e.g., a string may contain the file contents, or the file path.
|
||||
*/
|
||||
public enum XMLFileType {
|
||||
|
||||
/**
|
||||
* This means that a provided string contains the contents of an XML file.
|
||||
*/
|
||||
Contents,
|
||||
|
||||
/**
|
||||
* This means that a provided string contains the path to an XML file.
|
||||
*/
|
||||
FilePath,
|
||||
|
||||
/**
|
||||
* This means that a provided string contains the path, to be loaded as a resource, of an XML file.
|
||||
*/
|
||||
ResourcePath;
|
||||
|
||||
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
package seng302.Networking;
|
||||
package network;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
package seng302.Networking;
|
||||
package network;
|
||||
|
||||
import org.junit.Test;
|
||||
import seng302.Networking.Utils.ByteConverter;
|
||||
@ -1,9 +1,9 @@
|
||||
package seng302.Networking.MessageDecoders;
|
||||
package network.MessageDecoders;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import seng302.Networking.Messages.BoatLocation;
|
||||
import seng302.Networking.MessageEncoders.RaceVisionByteEncoder;
|
||||
import seng302.Networking.Messages.BoatLocation;
|
||||
|
||||
|
||||
/**
|
||||
@ -1,9 +1,9 @@
|
||||
package seng302.Networking.MessageDecoders;
|
||||
package network.MessageDecoders;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import seng302.Networking.Messages.CourseWind;
|
||||
import seng302.Networking.MessageEncoders.RaceVisionByteEncoder;
|
||||
import seng302.Networking.Messages.CourseWind;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
package seng302.Networking.MessageDecoders;
|
||||
package network.MessageDecoders;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
@ -1,4 +1,4 @@
|
||||
package seng302.Networking.MessageDecoders;
|
||||
package network.MessageDecoders;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
@ -1,4 +1,4 @@
|
||||
package seng302.Networking.MessageDecoders;
|
||||
package network.MessageDecoders;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
@ -1,10 +1,12 @@
|
||||
package seng302.Networking;
|
||||
package network;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import seng302.Networking.MessageEncoders.XMLMessageEncoder;
|
||||
|
||||
import java.io.*;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
/**
|
||||
* Created by hba56 on 19/04/17.
|
||||
@ -0,0 +1,5 @@
|
||||
package shared.dataInput;
|
||||
|
||||
public class RaceXMLReaderTest {
|
||||
//TODO
|
||||
}
|
||||
@ -0,0 +1,5 @@
|
||||
package shared.dataInput;
|
||||
|
||||
public class XMLReaderTest {
|
||||
//TODO
|
||||
}
|
||||
@ -0,0 +1,5 @@
|
||||
package visualiser.model;
|
||||
|
||||
public class GraphCoordinateTest {
|
||||
//TODO
|
||||
}
|
||||
@ -0,0 +1,5 @@
|
||||
package visualiser.model;
|
||||
|
||||
public class RaceMapTest {
|
||||
//TODO
|
||||
}
|
||||
@ -0,0 +1,5 @@
|
||||
package visualiser.model;
|
||||
|
||||
public class TrackPointTest {
|
||||
//TODO
|
||||
}
|
||||
@ -0,0 +1,5 @@
|
||||
package visualiser.model;
|
||||
|
||||
public class VisualiserBoatTest {
|
||||
//TODO
|
||||
}
|
||||
@ -0,0 +1,100 @@
|
||||
//package visualiser.model;
|
||||
//
|
||||
//
|
||||
//import org.junit.Before;
|
||||
//import org.junit.Test;
|
||||
//import shared.dataInput.RaceXMLReader;
|
||||
//import shared.dataInput.XMLReader;
|
||||
//import shared.exceptions.InvalidRaceDataException;
|
||||
//import shared.model.GPSCoordinate;
|
||||
//
|
||||
//import java.nio.charset.StandardCharsets;
|
||||
//import java.util.List;
|
||||
//
|
||||
//import static org.junit.Assert.assertEquals;
|
||||
//import static org.junit.Assert.fail;
|
||||
//
|
||||
///**
|
||||
// * Tests only work on the current version of mockXML/raceXML/raceTest.xml
|
||||
// */
|
||||
//public class VisualiserRaceTest {
|
||||
// private RaceXMLReader streamedCourseXMLReader;
|
||||
// private List<GPSCoordinate> boundary;
|
||||
//
|
||||
// @Before
|
||||
// public void setup() {
|
||||
// try {
|
||||
// streamedCourseXMLReader = new RaceXMLReader(XMLReader.readXMLFileToString("mockXML/raceXML/raceTest.xml", StandardCharsets.UTF_8));
|
||||
// boundary = streamedCourseXMLReader.getBoundary();
|
||||
// } catch (InvalidRaceDataException e) {
|
||||
// e.printStackTrace();
|
||||
// fail("Cannot find mockXML/raceXML/raceTest.xml in the resources folder");
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void testAllBoundaryPointsRead() {
|
||||
// assertEquals(boundary.size(), 10);
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void testBoundaryPointData() {
|
||||
// // First point
|
||||
// assertEquals(boundary.get(0).getLatitude(), -36.8325, 1e-6);
|
||||
// assertEquals(boundary.get(0).getLongitude(), 174.8325, 1e-6);
|
||||
//
|
||||
// // Last point
|
||||
// assertEquals(boundary.get(boundary.size() - 1).getLatitude(), -36.83417, 1e-6);
|
||||
// assertEquals(boundary.get(boundary.size() - 1).getLongitude(), 174.84767, 1e-6);
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void testMapEdges() {
|
||||
// double maxLatitude = streamedCourseXMLReader.getMapBottomRight().getLatitude() - streamedCourseXMLReader.getPadding();
|
||||
// double maxLongitude = streamedCourseXMLReader.getMapBottomRight().getLongitude() - streamedCourseXMLReader.getPadding();
|
||||
// double minLatitude = streamedCourseXMLReader.getMapTopLeft().getLatitude() - streamedCourseXMLReader.getPadding();
|
||||
// double minLongitude = streamedCourseXMLReader.getMapTopLeft().getLongitude() - streamedCourseXMLReader.getPadding();
|
||||
//
|
||||
// assertEquals(maxLatitude, -36.81033, 1e-6);
|
||||
// assertEquals(maxLongitude, 174.88217, 1e-6);
|
||||
// assertEquals(minLatitude, -36.83417, 1e-6);
|
||||
// assertEquals(minLongitude, 174.81983, 1e-6);
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void testRaceSettings() {
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void correctLegSequence() {
|
||||
// List<Leg> legs = streamedCourseXMLReader.getLegs();
|
||||
// String[] expectedNames = {
|
||||
// "StartLine",
|
||||
// "M1",
|
||||
// "M2",
|
||||
// "Gate"
|
||||
// };
|
||||
// for(int i = 0; i < legs.size(); i++) {
|
||||
// assertEquals(expectedNames[i], legs.get(i).getName());
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * raceTest.xml is not compliant with this test. Markers are positioned far out of bounds.
|
||||
// */
|
||||
// @Test
|
||||
// @Ignore
|
||||
// public void markersWithinRaceBoundaries() {
|
||||
// GPSCoordinate topLeft = streamedCourseXMLReader.getMapTopLeft();
|
||||
// GPSCoordinate bottomRight = streamedCourseXMLReader.getMapBottomRight();
|
||||
//
|
||||
// for(Marker compoundMark : streamedCourseXMLReader.getMarkers()) {
|
||||
// GPSCoordinate centre = compoundMark.getAverageGPSCoordinate();
|
||||
// assertTrue(centre.getLatitude() < bottomRight.getLatitude());
|
||||
// assertTrue(centre.getLatitude() > topLeft.getLatitude());
|
||||
// assertTrue(centre.getLongitude() > bottomRight.getLongitude());
|
||||
// assertTrue(centre.getLongitude() < topLeft.getLongitude());
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
@ -1,98 +0,0 @@
|
||||
package seng302.Mock;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import seng302.GPSCoordinate;
|
||||
import seng302.Model.Leg;
|
||||
import seng302.Model.Marker;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Tests only work on the current version of mockXML/raceXML/raceTest.xml
|
||||
*/
|
||||
public class StreamedRaceTest {
|
||||
private StreamedCourseXMLReader streamedCourseXMLReader;
|
||||
private List<GPSCoordinate> boundary;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
try {
|
||||
streamedCourseXMLReader = new StreamedCourseXMLReader("mockXML/raceXML/raceTest.xml", true);
|
||||
boundary = streamedCourseXMLReader.getBoundary();
|
||||
} catch (Exception | StreamedCourseXMLException e) {
|
||||
e.printStackTrace();
|
||||
//fail("Cannot find mockXML/raceXML/raceTest.xml in the resources folder");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAllBoundaryPointsRead() {
|
||||
assertEquals(boundary.size(), 10);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBoundaryPointData() {
|
||||
// First point
|
||||
assertEquals(boundary.get(0).getLatitude(), -36.8325, 1e-6);
|
||||
assertEquals(boundary.get(0).getLongitude(), 174.8325, 1e-6);
|
||||
|
||||
// Last point
|
||||
assertEquals(boundary.get(boundary.size() - 1).getLatitude(), -36.83417, 1e-6);
|
||||
assertEquals(boundary.get(boundary.size() - 1).getLongitude(), 174.84767, 1e-6);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapEdges() {
|
||||
double maxLatitude = streamedCourseXMLReader.getMapBottomRight().getLatitude() - streamedCourseXMLReader.getPadding();
|
||||
double maxLongitude = streamedCourseXMLReader.getMapBottomRight().getLongitude() - streamedCourseXMLReader.getPadding();
|
||||
double minLatitude = streamedCourseXMLReader.getMapTopLeft().getLatitude() - streamedCourseXMLReader.getPadding();
|
||||
double minLongitude = streamedCourseXMLReader.getMapTopLeft().getLongitude() - streamedCourseXMLReader.getPadding();
|
||||
|
||||
assertEquals(maxLatitude, -36.81033, 1e-6);
|
||||
assertEquals(maxLongitude, 174.88217, 1e-6);
|
||||
assertEquals(minLatitude, -36.83417, 1e-6);
|
||||
assertEquals(minLongitude, 174.81983, 1e-6);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRaceSettings() {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void correctLegSequence() {
|
||||
List<Leg> legs = streamedCourseXMLReader.getLegs();
|
||||
String[] expectedNames = {
|
||||
"StartLine",
|
||||
"M1",
|
||||
"M2",
|
||||
"Gate"
|
||||
};
|
||||
for(int i = 0; i < legs.size(); i++) {
|
||||
assertEquals(expectedNames[i], legs.get(i).getName());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* raceTest.xml is not compliant with this test. Markers are positioned far out of bounds.
|
||||
*/
|
||||
@Test
|
||||
@Ignore
|
||||
public void markersWithinRaceBoundaries() {
|
||||
GPSCoordinate topLeft = streamedCourseXMLReader.getMapTopLeft();
|
||||
GPSCoordinate bottomRight = streamedCourseXMLReader.getMapBottomRight();
|
||||
|
||||
for(Marker compoundMark : streamedCourseXMLReader.getMarkers()) {
|
||||
GPSCoordinate centre = compoundMark.getAverageGPSCoordinate();
|
||||
assertTrue(centre.getLatitude() < bottomRight.getLatitude());
|
||||
assertTrue(centre.getLatitude() > topLeft.getLatitude());
|
||||
assertTrue(centre.getLongitude() > bottomRight.getLongitude());
|
||||
assertTrue(centre.getLongitude() < topLeft.getLongitude());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,149 +0,0 @@
|
||||
package seng302.Model;
|
||||
|
||||
/**
|
||||
* Tests various aspects of a boat in race perform correctly.
|
||||
*/
|
||||
public class BoatInRaceTest {
|
||||
// TODO change this test to use Boat and not BoatInRace ??
|
||||
// TODO delete BoatInRace class
|
||||
|
||||
// private final GPSCoordinate ORIGIN_COORDS = new GPSCoordinate(0, 0);
|
||||
// private final BoatInRace TEST_BOAT = new BoatInRace("Test", 1, Color.ALICEBLUE, "tt");
|
||||
//
|
||||
//
|
||||
// @Test
|
||||
// public void calculateDueNorthAzimuthReturns0() {
|
||||
//
|
||||
// Marker startMarker = new Marker(ORIGIN_COORDS);
|
||||
// Marker endMarker = new Marker(new GPSCoordinate(50, 0));
|
||||
// Leg start = new Leg("Start", startMarker, endMarker, 0);
|
||||
// TEST_BOAT.setCurrentLeg(start);
|
||||
// assertEquals(TEST_BOAT.calculateAzimuth(), 0, 1e-8);
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void calculateDueSouthAzimuthReturns180() {
|
||||
// Marker startMarker = new Marker(ORIGIN_COORDS);
|
||||
// Marker endMarker = new Marker(new GPSCoordinate(-50, 0));
|
||||
// Leg start = new Leg("Start", startMarker, endMarker, 0);
|
||||
// TEST_BOAT.setCurrentLeg(start);
|
||||
// assertEquals(TEST_BOAT.calculateAzimuth(), 180, 1e-8);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// @Test
|
||||
// public void calculateDueEastAzimuthReturns90() {
|
||||
//
|
||||
// Marker startMarker = new Marker(ORIGIN_COORDS);
|
||||
// Marker endMarker = new Marker(new GPSCoordinate(0, 50));
|
||||
// Leg start = new Leg("Start", startMarker, endMarker, 0);
|
||||
// TEST_BOAT.setCurrentLeg(start);
|
||||
// assertEquals(TEST_BOAT.calculateAzimuth(), 90, 1e-8);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// @Test
|
||||
// public void calculateDueWestAzimuthReturnsNegative90() {
|
||||
// Marker startMarker = new Marker(ORIGIN_COORDS);
|
||||
// Marker endMarker = new Marker(new GPSCoordinate(0, -50));
|
||||
// Leg start = new Leg("Start", startMarker, endMarker, 0);
|
||||
// TEST_BOAT.setCurrentLeg(start);
|
||||
// assertEquals(TEST_BOAT.calculateAzimuth(), -90, 1e-8);
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void calculateDueNorthHeadingReturns0() {
|
||||
//
|
||||
// Marker startMarker = new Marker(ORIGIN_COORDS);
|
||||
// Marker endMarker = new Marker(new GPSCoordinate(50, 0));
|
||||
// Leg start = new Leg("Start", startMarker, endMarker, 0);
|
||||
// TEST_BOAT.setCurrentLeg(start);
|
||||
// assertEquals(TEST_BOAT.calculateHeading(), 0, 1e-8);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// @Test
|
||||
// public void calculateDueEastHeadingReturns90() {
|
||||
// Marker startMarker = new Marker(ORIGIN_COORDS);
|
||||
// Marker endMarker = new Marker(new GPSCoordinate(0, 50));
|
||||
// Leg start = new Leg("Start", startMarker, endMarker, 0);
|
||||
// TEST_BOAT.setCurrentLeg(start);
|
||||
// assertEquals(TEST_BOAT.calculateHeading(), 90, 1e-8);
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void calculateDueSouthHeadingReturns180() {
|
||||
// Marker startMarker = new Marker(ORIGIN_COORDS);
|
||||
// Marker endMarker = new Marker(new GPSCoordinate(-50, 0));
|
||||
// Leg start = new Leg("Start", startMarker, endMarker, 0);
|
||||
// TEST_BOAT.setCurrentLeg(start);
|
||||
// assertEquals(TEST_BOAT.calculateHeading(), 180, 1e-8);
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void calculateDueWestHeadingReturns270() {
|
||||
// Marker startMarker = new Marker(ORIGIN_COORDS);
|
||||
// Marker endMarker = new Marker(new GPSCoordinate(0, -50));
|
||||
// Leg start = new Leg("Start", startMarker, endMarker, 0);
|
||||
// TEST_BOAT.setCurrentLeg(start);
|
||||
// assertEquals(TEST_BOAT.calculateHeading(), 270, 1e-8);
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void createNewBoatCratesInstanceOfSuperClass() {
|
||||
//
|
||||
// BoatInRace testBoat = new BoatInRace("Boat", 20, Color.ALICEBLUE, "tt");
|
||||
// testBoat.setName("Name can change");
|
||||
// assertTrue(testBoat instanceof Boat);
|
||||
// assertTrue(testBoat.getCurrentLeg() == null);
|
||||
// assertTrue(testBoat.getCurrentPosition() == null);
|
||||
// assertTrue(testBoat.toString().contains("Name can change"));
|
||||
// assertEquals(testBoat.getVelocity(), 20.0);
|
||||
// assertTrue(testBoat.getVelocityProp().toString().contains("20"));
|
||||
// assertTrue(testBoat.getAbbrev().equals("tt"));
|
||||
// assertTrue(testBoat.getColour().equals(Color.ALICEBLUE));
|
||||
// assertFalse(testBoat.isFinished());
|
||||
// }
|
||||
//
|
||||
//
|
||||
// @Test
|
||||
// public void getWakeAtProperHeading() throws Exception {
|
||||
// BoatInRace boat = new BoatInRace("Test", 1, Color.ALICEBLUE, "tt");
|
||||
//
|
||||
// // Construct leg of 0 degrees
|
||||
// Marker startMarker = new Marker(ORIGIN_COORDS);
|
||||
// Marker endMarker = new Marker(new GPSCoordinate(50, 0));
|
||||
// Leg leg0deg = new Leg("Start", startMarker, endMarker, 0);
|
||||
// boat.setCurrentLeg(leg0deg);
|
||||
// boat.setCurrentPosition(new GPSCoordinate(0, 0));
|
||||
//
|
||||
// assertEquals(0, boat.calculateHeading(), 1e-8);
|
||||
//
|
||||
// // Construct leg from wake - heading should be 180 degrees
|
||||
// Leg leg180deg = new Leg("Start", startMarker, new Marker(boat.getWake()), 0);
|
||||
// boat.setCurrentLeg(leg180deg);
|
||||
//
|
||||
// assertEquals(180, boat.calculateHeading(), 1e-8);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// @Test
|
||||
// public void getWakeProportionalToVelocity() throws Exception {
|
||||
// BoatInRace boat = new BoatInRace("Test", 10, Color.ALICEBLUE, "tt");
|
||||
//
|
||||
// // Construct leg of 0 degrees at 0 N
|
||||
// Marker startMarker = new Marker(ORIGIN_COORDS);
|
||||
// Marker endMarker = new Marker(new GPSCoordinate(50, 0));
|
||||
// Leg leg0deg = new Leg("Start", startMarker, endMarker, 0);
|
||||
// boat.setCurrentLeg(leg0deg);
|
||||
// boat.setCurrentPosition(new GPSCoordinate(0, 0));
|
||||
//
|
||||
// // Get latitude of endpoint of wake at 10 kn (longitude is 0)
|
||||
// double endpointAt10Kn = boat.getWake().getLatitude();
|
||||
//
|
||||
// // Latitude of endpoint at 20 kn should be twice endpoint at 10 kn
|
||||
// boat.setVelocity(20);
|
||||
// assertEquals(2 * endpointAt10Kn, boat.getWake().getLatitude(), 1e-8);
|
||||
// }
|
||||
}
|
||||
@ -1,140 +0,0 @@
|
||||
//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 {
|
||||
//
|
||||
// CompoundMark START_MARKER = new CompoundMark(new GPSCoordinate(0, 0));
|
||||
// CompoundMark END_MARKER = new CompoundMark(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);
|
||||
// }
|
||||
//
|
||||
//}
|
||||
@ -1,78 +0,0 @@
|
||||
package seng302.Model;
|
||||
|
||||
import org.geotools.referencing.GeodeticCalculator;
|
||||
import org.junit.Test;
|
||||
import seng302.GPSCoordinate;
|
||||
|
||||
import java.awt.geom.Point2D;
|
||||
|
||||
import static junit.framework.TestCase.assertEquals;
|
||||
import static seng302.Model.Leg.NM_TO_METERS;
|
||||
|
||||
/**
|
||||
* Tests that using a start and end mark initialises the correct leg between
|
||||
* the markers.
|
||||
*/
|
||||
public class LegTest {
|
||||
|
||||
private final 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 * NM_TO_METERS);
|
||||
|
||||
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 * NM_TO_METERS);
|
||||
|
||||
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 * NM_TO_METERS);
|
||||
|
||||
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 * NM_TO_METERS);
|
||||
|
||||
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);
|
||||
|
||||
}
|
||||
}
|
||||
@ -1,57 +0,0 @@
|
||||
package seng302.Model;
|
||||
|
||||
import org.junit.Test;
|
||||
import seng302.GPSCoordinate;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Created by esa46 on 29/03/17.
|
||||
*/
|
||||
public class MarkerTest {
|
||||
|
||||
private final GPSCoordinate ORIGIN_COORD = new GPSCoordinate(0, 0);
|
||||
|
||||
@Test
|
||||
public void averageOfSingleMarkAtOriginIsSingleMark() {
|
||||
|
||||
Marker testMark = new Marker(ORIGIN_COORD);
|
||||
assertTrue(testMark.getAverageGPSCoordinate().equals(ORIGIN_COORD));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void averageOfSingleMarkIsSingleMark() {
|
||||
|
||||
GPSCoordinate testCoord = new GPSCoordinate(20, 25);
|
||||
Marker testMark = new Marker(testCoord);
|
||||
assertTrue(testMark.getAverageGPSCoordinate().equals(testCoord));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void averageLatOfTwoMarksIsAccurate() {
|
||||
|
||||
GPSCoordinate testCoord = new GPSCoordinate(10, 0);
|
||||
Marker testMark = new Marker(ORIGIN_COORD, testCoord);
|
||||
assertTrue(testMark.getAverageGPSCoordinate().equals(new GPSCoordinate(5, 0)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void averageLongOfTwoMarksIsAccurate() {
|
||||
|
||||
GPSCoordinate testCoord = new GPSCoordinate(0, 10);
|
||||
Marker testMark = new Marker(ORIGIN_COORD, testCoord);
|
||||
assertTrue(testMark.getAverageGPSCoordinate().equals(new GPSCoordinate(0, 5)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void averageLatAndLongOfTwoMarksIsAccurate() {
|
||||
|
||||
GPSCoordinate testCoord1 = new GPSCoordinate(10, 30);
|
||||
GPSCoordinate testCoord2 = new GPSCoordinate(30, 60);
|
||||
Marker testMark = new Marker(testCoord1, testCoord2);
|
||||
assertTrue(testMark.getAverageGPSCoordinate().equals(new GPSCoordinate(020.644102, 44.014817)));
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,8 +0,0 @@
|
||||
package seng302.Model;
|
||||
|
||||
/**
|
||||
* Created by esa46 on 15/03/17.
|
||||
*/
|
||||
public class RaceTest {
|
||||
|
||||
}
|
||||
Loading…
Reference in new issue