shared.dataInput:
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.
This commit is contained in:
@@ -8,6 +8,7 @@ import network.Messages.LatestMessages;
|
|||||||
import network.Messages.XMLMessage;
|
import network.Messages.XMLMessage;
|
||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXException;
|
||||||
import shared.dataInput.*;
|
import shared.dataInput.*;
|
||||||
|
import shared.enums.XMLFileType;
|
||||||
import shared.exceptions.InvalidBoatDataException;
|
import shared.exceptions.InvalidBoatDataException;
|
||||||
import shared.exceptions.InvalidRaceDataException;
|
import shared.exceptions.InvalidRaceDataException;
|
||||||
import shared.exceptions.InvalidRegattaDataException;
|
import shared.exceptions.InvalidRegattaDataException;
|
||||||
@@ -61,9 +62,9 @@ public class Event {
|
|||||||
sendXMLs();
|
sendXMLs();
|
||||||
|
|
||||||
//Parse the XML files into data sources.
|
//Parse the XML files into data sources.
|
||||||
RaceDataSource raceDataSource = new RaceXMLReader(this.raceXML);
|
RaceDataSource raceDataSource = new RaceXMLReader(this.raceXML, XMLFileType.ResourcePath);
|
||||||
BoatDataSource boatDataSource = new BoatXMLReader(this.boatXML);
|
BoatDataSource boatDataSource = new BoatXMLReader(this.boatXML, XMLFileType.ResourcePath);
|
||||||
RegattaDataSource regattaDataSource = new RegattaXMLReader(this.regattaXML);
|
RegattaDataSource regattaDataSource = new RegattaXMLReader(this.regattaXML, XMLFileType.ResourcePath);
|
||||||
|
|
||||||
//Create and start race.
|
//Create and start race.
|
||||||
MockRace newRace = new MockRace(boatDataSource, raceDataSource, regattaDataSource, this.latestMessages, this.boatPolars, Constants.RaceTimeScale);
|
MockRace newRace = new MockRace(boatDataSource, raceDataSource, regattaDataSource, this.latestMessages, this.boatPolars, Constants.RaceTimeScale);
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package shared.dataInput;
|
|||||||
|
|
||||||
import org.w3c.dom.Element;
|
import org.w3c.dom.Element;
|
||||||
import org.w3c.dom.Node;
|
import org.w3c.dom.Node;
|
||||||
|
import shared.enums.XMLFileType;
|
||||||
import shared.exceptions.InvalidBoatDataException;
|
import shared.exceptions.InvalidBoatDataException;
|
||||||
import shared.exceptions.XMLReaderException;
|
import shared.exceptions.XMLReaderException;
|
||||||
import shared.model.Boat;
|
import shared.model.Boat;
|
||||||
@@ -32,11 +33,12 @@ public class BoatXMLReader extends XMLReader implements BoatDataSource {
|
|||||||
* Constructor for Boat XML using a file read as a resource.
|
* Constructor for Boat XML using a file read as a resource.
|
||||||
*
|
*
|
||||||
* @param fileContents Contents of xml file.
|
* @param fileContents Contents of xml file.
|
||||||
|
* @param type How to read the file - e.g., load as resource.
|
||||||
* @throws XMLReaderException Thrown if the file cannot be parsed.
|
* @throws XMLReaderException Thrown if the file cannot be parsed.
|
||||||
* @throws InvalidBoatDataException Thrown if the file cannot be parsed correctly.
|
* @throws InvalidBoatDataException Thrown if the file cannot be parsed correctly.
|
||||||
*/
|
*/
|
||||||
public BoatXMLReader(String fileContents) throws XMLReaderException, InvalidBoatDataException {
|
public BoatXMLReader(String fileContents, XMLFileType type) throws XMLReaderException, InvalidBoatDataException {
|
||||||
super(fileContents);
|
super(fileContents, type);
|
||||||
|
|
||||||
//Attempt to read boat xml file.
|
//Attempt to read boat xml file.
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import org.w3c.dom.Element;
|
|||||||
import org.w3c.dom.NamedNodeMap;
|
import org.w3c.dom.NamedNodeMap;
|
||||||
import org.w3c.dom.Node;
|
import org.w3c.dom.Node;
|
||||||
import org.w3c.dom.NodeList;
|
import org.w3c.dom.NodeList;
|
||||||
|
import shared.enums.XMLFileType;
|
||||||
import shared.exceptions.InvalidRaceDataException;
|
import shared.exceptions.InvalidRaceDataException;
|
||||||
import shared.exceptions.XMLReaderException;
|
import shared.exceptions.XMLReaderException;
|
||||||
import shared.model.*;
|
import shared.model.*;
|
||||||
@@ -83,12 +84,13 @@ public class RaceXMLReader extends XMLReader implements RaceDataSource {
|
|||||||
/**
|
/**
|
||||||
* Constructor for Streamed Race XML
|
* Constructor for Streamed Race XML
|
||||||
* @param fileContents Contents of xml file.
|
* @param fileContents Contents of xml file.
|
||||||
|
* @param type How to read the file - e.g., load as resource.
|
||||||
* @throws XMLReaderException Thrown if an XML reader cannot be constructed for the given file.
|
* @throws XMLReaderException Thrown if an XML reader cannot be constructed for the given file.
|
||||||
* @throws InvalidRaceDataException Thrown if the XML file is invalid in some way.
|
* @throws InvalidRaceDataException Thrown if the XML file is invalid in some way.
|
||||||
*/
|
*/
|
||||||
public RaceXMLReader(String fileContents) throws XMLReaderException, InvalidRaceDataException {
|
public RaceXMLReader(String fileContents, XMLFileType type) throws XMLReaderException, InvalidRaceDataException {
|
||||||
|
|
||||||
super(fileContents);
|
super(fileContents, type);
|
||||||
|
|
||||||
|
|
||||||
//Attempt to read race xml file.
|
//Attempt to read race xml file.
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import org.w3c.dom.Element;
|
|||||||
import org.w3c.dom.NodeList;
|
import org.w3c.dom.NodeList;
|
||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXException;
|
||||||
import shared.dataInput.XMLReader;
|
import shared.dataInput.XMLReader;
|
||||||
|
import shared.enums.XMLFileType;
|
||||||
import shared.exceptions.InvalidRegattaDataException;
|
import shared.exceptions.InvalidRegattaDataException;
|
||||||
import shared.exceptions.XMLReaderException;
|
import shared.exceptions.XMLReaderException;
|
||||||
import shared.model.GPSCoordinate;
|
import shared.model.GPSCoordinate;
|
||||||
@@ -67,11 +68,12 @@ public class RegattaXMLReader extends XMLReader implements RegattaDataSource {
|
|||||||
* Constructor for Regatta XML using a file read as a resource.
|
* Constructor for Regatta XML using a file read as a resource.
|
||||||
*
|
*
|
||||||
* @param fileContents Contents of xml file.
|
* @param fileContents Contents of xml file.
|
||||||
|
* @param type How to read the file - e.g., load as resource.
|
||||||
* @throws XMLReaderException Thrown if the file cannot be parsed.
|
* @throws XMLReaderException Thrown if the file cannot be parsed.
|
||||||
* @throws InvalidRegattaDataException Thrown if the file cannot be parsed correctly.
|
* @throws InvalidRegattaDataException Thrown if the file cannot be parsed correctly.
|
||||||
*/
|
*/
|
||||||
public RegattaXMLReader(String fileContents) throws XMLReaderException, InvalidRegattaDataException {
|
public RegattaXMLReader(String fileContents, XMLFileType type) throws XMLReaderException, InvalidRegattaDataException {
|
||||||
super(fileContents);
|
super(fileContents, type);
|
||||||
|
|
||||||
//Attempt to read boat xml file.
|
//Attempt to read boat xml file.
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import org.w3c.dom.Element;
|
|||||||
import org.w3c.dom.Node;
|
import org.w3c.dom.Node;
|
||||||
import org.xml.sax.InputSource;
|
import org.xml.sax.InputSource;
|
||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXException;
|
||||||
|
import shared.enums.XMLFileType;
|
||||||
import shared.exceptions.XMLReaderException;
|
import shared.exceptions.XMLReaderException;
|
||||||
|
|
||||||
import javax.xml.parsers.DocumentBuilder;
|
import javax.xml.parsers.DocumentBuilder;
|
||||||
@@ -27,20 +28,43 @@ public abstract class XMLReader {
|
|||||||
|
|
||||||
protected Document doc;
|
protected Document doc;
|
||||||
|
|
||||||
/**
|
|
||||||
* Read an XML file.
|
|
||||||
* @param fileContents Contents of the xml file.
|
|
||||||
* @throws XMLReaderException Thrown if the file cannot be parsed.
|
|
||||||
*/
|
|
||||||
public XMLReader(String fileContents) throws XMLReaderException {
|
|
||||||
|
|
||||||
//Wrap file contents in input stream.
|
/**
|
||||||
InputStream xmlInputStream = new ByteArrayInputStream(fileContents.getBytes(StandardCharsets.UTF_8));
|
* Reads an XML file.
|
||||||
|
* @param file The file to read.
|
||||||
|
* @param type How to read the file - e.g., load as resource.
|
||||||
|
* @throws XMLReaderException Throw if the file cannot be parsed.
|
||||||
|
*/
|
||||||
|
public XMLReader(String file, XMLFileType type) throws XMLReaderException {
|
||||||
|
|
||||||
|
|
||||||
|
InputStream xmlInputStream = null;
|
||||||
|
|
||||||
|
//Create an input stream. Method depends on type parameter.
|
||||||
|
|
||||||
|
if (type == XMLFileType.Contents) {
|
||||||
|
//Wrap file contents in input stream.
|
||||||
|
xmlInputStream = new ByteArrayInputStream(file.getBytes(StandardCharsets.UTF_8));
|
||||||
|
|
||||||
|
} else if (type == XMLFileType.ResourcePath) {
|
||||||
|
xmlInputStream = XMLReader.class.getClassLoader().getResourceAsStream(file);
|
||||||
|
|
||||||
|
} else if (type == XMLFileType.FilePath) {
|
||||||
|
try {
|
||||||
|
xmlInputStream = new FileInputStream(file);
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
throw new XMLReaderException("Could not open file " + file, e);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
this.doc = parseInputStream(xmlInputStream);
|
this.doc = parseInputStream(xmlInputStream);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads an XML file from an input stream.
|
* Reads an XML file from an input stream.
|
||||||
* @param xmlInputStream The input stream to parse.
|
* @param xmlInputStream The input stream to parse.
|
||||||
@@ -58,7 +82,7 @@ public abstract class XMLReader {
|
|||||||
* @return The parsed document.
|
* @return The parsed document.
|
||||||
* @throws XMLReaderException Thrown when a document builder cannot be constructed, or the stream cannot be parsed.
|
* @throws XMLReaderException Thrown when a document builder cannot be constructed, or the stream cannot be parsed.
|
||||||
*/
|
*/
|
||||||
private Document parseInputStream(InputStream inputStream) throws XMLReaderException {
|
private static Document parseInputStream(InputStream inputStream) throws XMLReaderException {
|
||||||
|
|
||||||
//Create document builder.
|
//Create document builder.
|
||||||
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
|
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
|
||||||
@@ -142,18 +166,15 @@ public abstract class XMLReader {
|
|||||||
* @param path path of the XML
|
* @param path path of the XML
|
||||||
* @param encoding encoding of the xml
|
* @param encoding encoding of the xml
|
||||||
* @return A string containing the contents of the specified file.
|
* @return A string containing the contents of the specified file.
|
||||||
* @throws IOException No file etc
|
|
||||||
* @throws ParserConfigurationException Issue with the XML formatting
|
|
||||||
* @throws SAXException Issue with XML formatting
|
|
||||||
* @throws TransformerException Issue with the XML format
|
* @throws TransformerException Issue with the XML format
|
||||||
|
* @throws XMLReaderException Thrown if file cannot be read for some reason.
|
||||||
*/
|
*/
|
||||||
public static String readXMLFileToString(String path, Charset encoding) throws IOException, ParserConfigurationException, SAXException, TransformerException {
|
public static String readXMLFileToString(String path, Charset encoding) throws TransformerException, XMLReaderException {
|
||||||
|
|
||||||
InputSource fileSource = new InputSource(XMLReader.class.getClassLoader().getResourceAsStream(path));
|
InputStream fileStream = XMLReader.class.getClassLoader().getResourceAsStream(path);
|
||||||
|
|
||||||
|
Document doc = XMLReader.parseInputStream(fileStream);
|
||||||
|
|
||||||
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
|
|
||||||
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
|
|
||||||
Document doc = dBuilder.parse(fileSource);
|
|
||||||
doc.getDocumentElement().normalize();
|
doc.getDocumentElement().normalize();
|
||||||
|
|
||||||
return XMLReader.getContents(doc);
|
return XMLReader.getContents(doc);
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -13,6 +13,7 @@ import javafx.scene.paint.Color;
|
|||||||
import network.Messages.Enums.RaceStatusEnum;
|
import network.Messages.Enums.RaceStatusEnum;
|
||||||
import network.Messages.LatestMessages;
|
import network.Messages.LatestMessages;
|
||||||
import shared.dataInput.*;
|
import shared.dataInput.*;
|
||||||
|
import shared.enums.XMLFileType;
|
||||||
import shared.exceptions.InvalidBoatDataException;
|
import shared.exceptions.InvalidBoatDataException;
|
||||||
import shared.exceptions.InvalidRaceDataException;
|
import shared.exceptions.InvalidRaceDataException;
|
||||||
import shared.exceptions.InvalidRegattaDataException;
|
import shared.exceptions.InvalidRegattaDataException;
|
||||||
@@ -115,9 +116,9 @@ public class StartController extends Controller implements Observer {
|
|||||||
private void startRace(LatestMessages latestMessages) throws XMLReaderException, InvalidRaceDataException, InvalidBoatDataException, InvalidRegattaDataException {
|
private void startRace(LatestMessages latestMessages) throws XMLReaderException, InvalidRaceDataException, InvalidBoatDataException, InvalidRegattaDataException {
|
||||||
|
|
||||||
//Create data sources from latest messages for the race.
|
//Create data sources from latest messages for the race.
|
||||||
RaceDataSource raceDataSource = new RaceXMLReader(latestMessages.getRaceXMLMessage().getXmlMessage());
|
RaceDataSource raceDataSource = new RaceXMLReader(latestMessages.getRaceXMLMessage().getXmlMessage(), XMLFileType.ResourcePath);
|
||||||
BoatDataSource boatDataSource = new BoatXMLReader(latestMessages.getBoatXMLMessage().getXmlMessage());
|
BoatDataSource boatDataSource = new BoatXMLReader(latestMessages.getBoatXMLMessage().getXmlMessage(), XMLFileType.ResourcePath);
|
||||||
RegattaDataSource regattaDataSource = new RegattaXMLReader(latestMessages.getRegattaXMLMessage().getXmlMessage());
|
RegattaDataSource regattaDataSource = new RegattaXMLReader(latestMessages.getRegattaXMLMessage().getXmlMessage(), XMLFileType.ResourcePath);
|
||||||
|
|
||||||
//Create race.
|
//Create race.
|
||||||
this.visualiserRace = new VisualiserRace(boatDataSource, raceDataSource, regattaDataSource, latestMessages, this.colors);
|
this.visualiserRace = new VisualiserRace(boatDataSource, raceDataSource, regattaDataSource, latestMessages, this.colors);
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package seng302.Networking;
|
package network;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
+4
-2
@@ -1,4 +1,4 @@
|
|||||||
package seng302.Networking;
|
package network;
|
||||||
|
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@@ -9,7 +9,9 @@ import seng302.Networking.Messages.AC35Data;
|
|||||||
import seng302.Networking.Messages.Enums.MessageType;
|
import seng302.Networking.Messages.Enums.MessageType;
|
||||||
import seng302.Networking.Messages.XMLMessage;
|
import seng302.Networking.Messages.XMLMessage;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.BufferedReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by hba56 on 21/04/17.
|
* Created by hba56 on 21/04/17.
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package seng302.Networking;
|
package network;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import seng302.Networking.Utils.ByteConverter;
|
import seng302.Networking.Utils.ByteConverter;
|
||||||
+2
-2
@@ -1,9 +1,9 @@
|
|||||||
package seng302.Networking.MessageDecoders;
|
package network.MessageDecoders;
|
||||||
|
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import seng302.Networking.Messages.BoatLocation;
|
|
||||||
import seng302.Networking.MessageEncoders.RaceVisionByteEncoder;
|
import seng302.Networking.MessageEncoders.RaceVisionByteEncoder;
|
||||||
|
import seng302.Networking.Messages.BoatLocation;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
+2
-2
@@ -1,9 +1,9 @@
|
|||||||
package seng302.Networking.MessageDecoders;
|
package network.MessageDecoders;
|
||||||
|
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import seng302.Networking.Messages.CourseWind;
|
|
||||||
import seng302.Networking.MessageEncoders.RaceVisionByteEncoder;
|
import seng302.Networking.MessageEncoders.RaceVisionByteEncoder;
|
||||||
|
import seng302.Networking.Messages.CourseWind;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package seng302.Networking.MessageDecoders;
|
package network.MessageDecoders;
|
||||||
|
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package seng302.Networking.MessageDecoders;
|
package network.MessageDecoders;
|
||||||
|
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package seng302.Networking.MessageDecoders;
|
package network.MessageDecoders;
|
||||||
|
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
+4
-2
@@ -1,10 +1,12 @@
|
|||||||
package seng302.Networking;
|
package network;
|
||||||
|
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import seng302.Networking.MessageEncoders.XMLMessageEncoder;
|
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.
|
* Created by hba56 on 19/04/17.
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package shared.dataInput;
|
||||||
|
|
||||||
|
public class RaceXMLReaderTest {
|
||||||
|
//TODO
|
||||||
|
}
|
||||||
+2
-2
@@ -1,4 +1,4 @@
|
|||||||
package seng302.Mock;
|
package shared.dataInput;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@@ -10,7 +10,7 @@ import static org.junit.Assert.fail;
|
|||||||
* Created by jjg64 on 19/04/17.
|
* Created by jjg64 on 19/04/17.
|
||||||
* Tests RegattaXMLReader
|
* Tests RegattaXMLReader
|
||||||
*/
|
*/
|
||||||
public class RegattaXMLTest {
|
public class RegattaXMLReaderTest {
|
||||||
private RegattaXMLReader regatta;
|
private RegattaXMLReader regatta;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package shared.dataInput;
|
||||||
|
|
||||||
|
public class XMLReaderTest {
|
||||||
|
//TODO
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package visualiser.model;
|
||||||
|
|
||||||
|
public class GraphCoordinateTest {
|
||||||
|
//TODO
|
||||||
|
}
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package seng302;
|
package visualiser.model;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
@@ -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 {
|
|
||||||
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user