Moved mock.app.App#readFile(...) to shared.dataInput.XMLReader#readXMLFileToString(...).
Did the bare minimum to get the mock.model, mock.dataInput, shared.model tests working - many of them need to be tidied/refactored/moved as they don't take into account most of the refactorings.
This commit is contained in:
@@ -1,36 +1,74 @@
|
||||
package mock.dataInput;
|
||||
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
import seng302.Exceptions.InvalidPolarFileException;
|
||||
import seng302.Model.Polars;
|
||||
import mock.exceptions.InvalidPolarFileException;
|
||||
import mock.model.Polars;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.testng.Assert.assertTrue;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
/**
|
||||
* Created by f123 on 10-May-17.
|
||||
* Tests the polar parser.
|
||||
*/
|
||||
public class PolarParserTest {
|
||||
|
||||
@Test
|
||||
/*
|
||||
Tests if we can parse a polar data file (stored in a string), and create a polar table.
|
||||
|
||||
/**
|
||||
* Tests if we can parse a valid polar data file (stored in a string), and create a polar table.
|
||||
*/
|
||||
public void testParse() throws Exception {
|
||||
@Test
|
||||
public void testParseValidFile() {
|
||||
|
||||
try {
|
||||
//Parse data file.
|
||||
Polars polars = PolarParser.parse("polars/acc_polars.csv");
|
||||
Polars polars = PolarParser.parse("mock/polars/acc_polars.csv");
|
||||
|
||||
//If the parse function didn't through, it worked.
|
||||
} catch (InvalidPolarFileException e) {
|
||||
fail("Couldn't parse polar file.");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests if we can parse an invalid polar data file - it is expected that parsing will fail.
|
||||
*/
|
||||
@Test
|
||||
public void testParseInvalidFile() {
|
||||
|
||||
try {
|
||||
//Parse data file.
|
||||
Polars polars = PolarParser.parse("mock/polars/invalid_polars.csv");
|
||||
|
||||
//As the file is invalid, we shouldn't reach here.
|
||||
fail("exception should have been thrown, but wasn't.");
|
||||
|
||||
} catch (InvalidPolarFileException e) {
|
||||
assertTrue(true);
|
||||
}
|
||||
catch (InvalidPolarFileException e) {
|
||||
assertTrue(false);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests if we can parse an non-existent polar data file - it is expected that parsing will fail.
|
||||
*/
|
||||
@Test
|
||||
public void testParseNonExistentFile() {
|
||||
|
||||
try {
|
||||
//Parse data file.
|
||||
Polars polars = PolarParser.parse("mock/polars/this_does_not_exist.csv");
|
||||
|
||||
//As the file doesn't exist, we shouldn't reach here.
|
||||
fail("exception should have been thrown, but wasn't.");
|
||||
|
||||
} catch (InvalidPolarFileException e) {
|
||||
assertTrue(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,101 +0,0 @@
|
||||
package mock.model;
|
||||
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Created by esa46 on 22/03/17.
|
||||
*/
|
||||
public class BoatTest {
|
||||
|
||||
|
||||
private GPSCoordinate ORIGIN_COORDS;
|
||||
private Boat TEST_BOAT;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
ORIGIN_COORDS = new GPSCoordinate(0, 0);
|
||||
TEST_BOAT = new Boat(1, "Test", "tt", new Polars());
|
||||
TEST_BOAT.setCurrentPosition(ORIGIN_COORDS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void calculateDueNorthAzimuthReturns0() {
|
||||
|
||||
CompoundMark startMarker = new CompoundMark(new Mark(1, "test origin 1", ORIGIN_COORDS));
|
||||
CompoundMark endMarker = new CompoundMark(new Mark(2, "test mark 2", new GPSCoordinate(50, 0)));
|
||||
Leg start = new Leg("Start", startMarker, endMarker, 0);
|
||||
TEST_BOAT.setCurrentLeg(start);
|
||||
assertEquals(GPSCoordinate.calculateAzimuth(startMarker.getAverageGPSCoordinate(), endMarker.getAverageGPSCoordinate()).degrees(), 0, 1e-8);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void calculateDueSouthAzimuthReturns180() {
|
||||
CompoundMark startMarker = new CompoundMark(new Mark(1, "test origin 1", ORIGIN_COORDS));
|
||||
CompoundMark endMarker = new CompoundMark(new Mark(2, "test mark 2", new GPSCoordinate(-50, 0)));
|
||||
Leg start = new Leg("Start", startMarker, endMarker, 0);
|
||||
TEST_BOAT.setCurrentLeg(start);
|
||||
assertEquals(GPSCoordinate.calculateAzimuth(startMarker.getAverageGPSCoordinate(), endMarker.getAverageGPSCoordinate()).degrees(), -180, 1e-8);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void calculateDueEastAzimuthReturns90() {
|
||||
|
||||
CompoundMark startMarker = new CompoundMark(new Mark(1, "test origin 1", ORIGIN_COORDS));
|
||||
CompoundMark endMarker = new CompoundMark(new Mark(2, "test mark 2", new GPSCoordinate(0, 50)));
|
||||
Leg start = new Leg("Start", startMarker, endMarker, 0);
|
||||
TEST_BOAT.setCurrentLeg(start);
|
||||
assertEquals(GPSCoordinate.calculateAzimuth(startMarker.getAverageGPSCoordinate(), endMarker.getAverageGPSCoordinate()).degrees(), 90, 1e-8);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void calculateDueWestAzimuthReturnsNegative90() {
|
||||
CompoundMark startMarker = new CompoundMark(new Mark(1, "test origin 1", ORIGIN_COORDS));
|
||||
CompoundMark endMarker = new CompoundMark(new Mark(2, "test mark 2", new GPSCoordinate(0, -50)));
|
||||
Leg start = new Leg("Start", startMarker, endMarker, 0);
|
||||
TEST_BOAT.setCurrentLeg(start);
|
||||
assertEquals(GPSCoordinate.calculateAzimuth(startMarker.getAverageGPSCoordinate(), endMarker.getAverageGPSCoordinate()).degrees(), -90, 1e-8);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void calculateDueNorthHeadingReturns0() {
|
||||
|
||||
CompoundMark startMarker = new CompoundMark(new Mark(1, "test origin 1", ORIGIN_COORDS));
|
||||
CompoundMark endMarker = new CompoundMark(new Mark(2, "test mark 2", new GPSCoordinate(50, 0)));
|
||||
Leg start = new Leg("Start", startMarker, endMarker, 0);
|
||||
TEST_BOAT.setCurrentLeg(start);
|
||||
assertEquals(TEST_BOAT.calculateBearingToNextMarker().degrees(), 0, 1e-8);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void calculateDueEastHeadingReturns90() {
|
||||
CompoundMark startMarker = new CompoundMark(new Mark(1, "test origin 1", ORIGIN_COORDS));
|
||||
CompoundMark endMarker = new CompoundMark(new Mark(2, "test mark 2", new GPSCoordinate(0, 50)));
|
||||
Leg start = new Leg("Start", startMarker, endMarker, 0);
|
||||
TEST_BOAT.setCurrentLeg(start);
|
||||
assertEquals(TEST_BOAT.calculateBearingToNextMarker().degrees(), 90, 1e-8);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void calculateDueSouthHeadingReturns180() {
|
||||
CompoundMark startMarker = new CompoundMark(new Mark(1, "test origin 1", ORIGIN_COORDS));
|
||||
CompoundMark endMarker = new CompoundMark(new Mark(2, "test mark 2", new GPSCoordinate(-50, 0)));
|
||||
Leg start = new Leg("Start", startMarker, endMarker, 0);
|
||||
TEST_BOAT.setCurrentLeg(start);
|
||||
assertEquals(TEST_BOAT.calculateBearingToNextMarker().degrees(), 180, 1e-8);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void calculateDueWestHeadingReturns270() {
|
||||
CompoundMark startMarker = new CompoundMark(new Mark(1, "test origin 1", ORIGIN_COORDS));
|
||||
CompoundMark endMarker = new CompoundMark(new Mark(2, "test mark 2", new GPSCoordinate(0, -50)));
|
||||
Leg start = new Leg("Start", startMarker, endMarker, 0);
|
||||
TEST_BOAT.setCurrentLeg(start);
|
||||
assertEquals(TEST_BOAT.calculateBearingToNextMarker().degrees(), 270, 1e-8);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package mock.model;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class MockBoatTest {
|
||||
//TODO
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package mock.model;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class MockRaceTest {
|
||||
//TODO
|
||||
}
|
||||
@@ -1,20 +1,34 @@
|
||||
package mock.model;
|
||||
|
||||
import mock.dataInput.PolarParser;
|
||||
import mock.exceptions.InvalidPolarFileException;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import seng302.DataInput.PolarParser;
|
||||
import seng302.Exceptions.InvalidPolarFileException;
|
||||
import shared.model.Bearing;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Created by f123 on 10-May-17.
|
||||
* Tests the polars class, to see if various VMGs can be calculated.
|
||||
*/
|
||||
public class PolarsTest {
|
||||
|
||||
/**
|
||||
* The polars table used in each test.
|
||||
*/
|
||||
private Polars polars = null;
|
||||
|
||||
/**
|
||||
* The epsilon, in degrees, for computed bearing angles.
|
||||
*/
|
||||
private double angleEpsilon = 2;
|
||||
|
||||
/**
|
||||
* The epsilon, in knots, for computed speeds.
|
||||
*/
|
||||
private double speedEpsilon = 0.5;
|
||||
|
||||
|
||||
@@ -26,10 +40,10 @@ public class PolarsTest {
|
||||
//Read data.
|
||||
try {
|
||||
//Parse data file.
|
||||
polars = PolarParser.parse("polars/acc_polars.csv");
|
||||
polars = PolarParser.parse("mock/polars/acc_polars.csv");
|
||||
}
|
||||
catch (InvalidPolarFileException e) {
|
||||
assertTrue(false);
|
||||
fail("Couldn't parse polar file.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,314 +0,0 @@
|
||||
package mock.model;
|
||||
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
import org.xml.sax.SAXException;
|
||||
import seng302.DataInput.BoatDataSource;
|
||||
import seng302.DataInput.BoatXMLReader;
|
||||
import seng302.DataInput.RaceDataSource;
|
||||
import seng302.DataInput.RaceXMLReader;
|
||||
import seng302.Exceptions.StreamedCourseXMLException;
|
||||
import seng302.MockOutput;
|
||||
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import java.io.IOException;
|
||||
import java.text.ParseException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
/**
|
||||
* Created by esa46 on 15/03/17.
|
||||
*/
|
||||
public class RaceTest{
|
||||
|
||||
|
||||
public static final CompoundMark ORIGIN = new CompoundMark(new Mark(1, "test origin 1", new GPSCoordinate(0, 0)));
|
||||
public static final CompoundMark THREE_NM_FROM_ORIGIN = new CompoundMark(new Mark(2, "test mark 2", new GPSCoordinate(0.050246769, 0)));
|
||||
public static final CompoundMark FIFTEEN_NM_FROM_ORIGIN = new CompoundMark(new Mark(3, "test mark 3", new GPSCoordinate(0.251233845, 0)));
|
||||
public static ArrayList<Leg> TEST_LEGS = new ArrayList<>();
|
||||
public static final int START_LEG_DISTANCE = 3;
|
||||
public static final int MIDDLE_LEG_DISTANCE = 12;
|
||||
public static final Leg START_LEG = new Leg("Start", ORIGIN, THREE_NM_FROM_ORIGIN, 0);
|
||||
public static final Leg MIDDLE_LEG = new Leg("Middle", THREE_NM_FROM_ORIGIN, FIFTEEN_NM_FROM_ORIGIN, 1);
|
||||
public static final Leg FINISH_LEG = new Leg("Finish", FIFTEEN_NM_FROM_ORIGIN, FIFTEEN_NM_FROM_ORIGIN, 2);
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
TEST_LEGS.add(START_LEG);
|
||||
TEST_LEGS.add(MIDDLE_LEG);
|
||||
TEST_LEGS.add(FINISH_LEG);
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void countdownTimerSendsBoatLocations() {
|
||||
|
||||
try {
|
||||
MockOutput mockOutput = Mockito.mock(MockOutput.class);
|
||||
BoatDataSource boatDataSource = new BoatXMLReader("mockXML/boatTest.xml", new Polars());
|
||||
RaceDataSource raceDataSource = new RaceXMLReader("mockXML/raceTest.xml", boatDataSource);
|
||||
Race testRace = new Race(raceDataSource, mockOutput);
|
||||
testRace.initialiseBoats();
|
||||
testRace.countdownTimer.handle(1);
|
||||
verify(mockOutput, atLeast(boatDataSource.getBoats().size())).parseBoatLocation(anyInt(), anyDouble(), anyDouble(), anyDouble(), anyDouble(), anyLong());
|
||||
|
||||
} catch (ParserConfigurationException | IOException | SAXException | ParseException | StreamedCourseXMLException e) {
|
||||
e.printStackTrace();
|
||||
fail();
|
||||
}
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void countdownTimerSendsRaceStatusMessages() {
|
||||
|
||||
try {
|
||||
MockOutput mockOutput = Mockito.mock(MockOutput.class);
|
||||
RaceDataSource dataSource = new RaceXMLReader("mockXML/raceTest.xml", new BoatXMLReader("mockXML/boatTest.xml", new Polars()));
|
||||
Race testRace = new Race(dataSource, mockOutput);
|
||||
testRace.initialiseBoats();
|
||||
testRace.countdownTimer.handle(1);
|
||||
verify(mockOutput, atLeast(1)).parseRaceStatus(any());
|
||||
|
||||
} catch (ParserConfigurationException | IOException | SAXException | ParseException | StreamedCourseXMLException e) {
|
||||
e.printStackTrace();
|
||||
fail();
|
||||
}
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void checkPositionFinishedUpdatesNumberFinishedBoats() {
|
||||
|
||||
try {
|
||||
MockOutput mockOutput = Mockito.mock(MockOutput.class);
|
||||
RaceDataSource dataSource = new RaceXMLReader("mockXML/raceTest.xml", new BoatXMLReader("mockXML/boatTest.xml", new Polars()));
|
||||
Race testRace = new Race(dataSource, mockOutput);
|
||||
testRace.initialiseBoats();
|
||||
Boat testBoat = testRace.getBoats().get(0);
|
||||
testBoat.setCurrentLeg(FINISH_LEG);
|
||||
testBoat.setDistanceTravelledInLeg(1);
|
||||
testRace.checkPosition(testBoat, 1);
|
||||
|
||||
assertEquals(testRace.getNumberOfActiveBoats(), 0);
|
||||
|
||||
} catch (ParserConfigurationException | IOException | SAXException | ParseException | StreamedCourseXMLException e) {
|
||||
e.printStackTrace();
|
||||
fail();
|
||||
}
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void checkPositionSetFinishedBoatVelocityTo0() {
|
||||
|
||||
try {
|
||||
MockOutput mockOutput = Mockito.mock(MockOutput.class);
|
||||
RaceDataSource dataSource = new RaceXMLReader("mockXML/raceTest.xml", new BoatXMLReader("mockXML/boatTest.xml", new Polars()));
|
||||
Race testRace = new Race(dataSource, mockOutput);
|
||||
testRace.initialiseBoats();
|
||||
Boat testBoat = testRace.getBoats().get(0);
|
||||
testBoat.setCurrentLeg(FINISH_LEG);
|
||||
testBoat.setDistanceTravelledInLeg(1);
|
||||
testRace.checkPosition(testBoat, 1);
|
||||
|
||||
assertEquals(testBoat.getCurrentSpeed(), 0, 1e-8);
|
||||
|
||||
} catch (ParserConfigurationException | IOException | SAXException | ParseException | StreamedCourseXMLException e) {
|
||||
e.printStackTrace();
|
||||
fail();
|
||||
}
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void checkPositionSetsFinishTime() {
|
||||
|
||||
try {
|
||||
MockOutput mockOutput = Mockito.mock(MockOutput.class);
|
||||
RaceDataSource dataSource = new RaceXMLReader("mockXML/raceTest.xml", new BoatXMLReader("mockXML/boatTest.xml", new Polars()));
|
||||
Race testRace = new Race(dataSource, mockOutput);
|
||||
testRace.initialiseBoats();
|
||||
Boat testBoat = testRace.getBoats().get(0);
|
||||
testBoat.setCurrentLeg(FINISH_LEG);
|
||||
testBoat.setDistanceTravelledInLeg(1);
|
||||
testRace.checkPosition(testBoat, 1);
|
||||
|
||||
assertEquals(testBoat.getTimeFinished(), 1, 1e-8);
|
||||
|
||||
} catch (ParserConfigurationException | IOException | SAXException | ParseException | StreamedCourseXMLException e) {
|
||||
e.printStackTrace();
|
||||
fail();
|
||||
}
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void checkPositionUnfinishedDoesntUpdateNumberFinishedBoats() {
|
||||
|
||||
try {
|
||||
MockOutput mockOutput = Mockito.mock(MockOutput.class);
|
||||
RaceDataSource dataSource = new RaceXMLReader("mockXML/raceTest.xml", new BoatXMLReader("mockXML/boatTest.xml", new Polars()));
|
||||
Race testRace = new Race(dataSource, mockOutput);
|
||||
testRace.initialiseBoats();
|
||||
Boat testBoat = testRace.getBoats().get(0);
|
||||
testBoat.setCurrentLeg(START_LEG);
|
||||
testBoat.setDistanceTravelledInLeg(START_LEG_DISTANCE);
|
||||
testRace.checkPosition(testBoat, 1);
|
||||
|
||||
assertEquals(testRace.getNumberOfActiveBoats(), 1);
|
||||
|
||||
} catch (ParserConfigurationException | IOException | SAXException | ParseException | StreamedCourseXMLException e) {
|
||||
e.printStackTrace();
|
||||
fail();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void distanceTravelledBeforeUpdatingLegIsRetained() {
|
||||
|
||||
try {
|
||||
MockOutput mockOutput = Mockito.mock(MockOutput.class);
|
||||
RaceDataSource dataSource = new RaceXMLReader("mockXML/raceTest.xml", new BoatXMLReader("mockXML/boatTest.xml", new Polars()));
|
||||
Race testRace = new Race(dataSource, mockOutput);
|
||||
testRace.initialiseBoats();
|
||||
Boat testBoat = testRace.getBoats().get(0);
|
||||
testBoat.setCurrentLeg(START_LEG);
|
||||
testBoat.setDistanceTravelledInLeg(START_LEG_DISTANCE + 1);
|
||||
testRace.checkPosition(testBoat, 0);
|
||||
|
||||
assertEquals(testBoat.getDistanceTravelledInLeg(), 1, 1e-7);
|
||||
|
||||
} catch (ParserConfigurationException | IOException | SAXException | ParseException | StreamedCourseXMLException e) {
|
||||
e.printStackTrace();
|
||||
fail();
|
||||
}
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void doNotFinishAnswersYesIf100PercentChance() {
|
||||
|
||||
try {
|
||||
MockOutput mockOutput = Mockito.mock(MockOutput.class);
|
||||
BoatDataSource boatDataSource = new BoatXMLReader("mockXML/boatTest.xml", new Polars());
|
||||
RaceDataSource raceDataSource = new RaceXMLReader("mockXML/raceTest.xml", boatDataSource);
|
||||
Race testRace = new Race(raceDataSource, mockOutput);
|
||||
|
||||
testRace.setDnfChance(100);
|
||||
assertTrue(testRace.doNotFinish());
|
||||
|
||||
} catch (ParserConfigurationException | IOException | SAXException | ParseException | StreamedCourseXMLException e) {
|
||||
e.printStackTrace();
|
||||
fail();
|
||||
}
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void doNotFinishAnswersNoIf0PercentChance() {
|
||||
|
||||
try {
|
||||
MockOutput mockOutput = Mockito.mock(MockOutput.class);
|
||||
BoatDataSource boatDataSource = new BoatXMLReader("mockXML/boatTest.xml", new Polars());
|
||||
RaceDataSource raceDataSource = new RaceXMLReader("mockXML/raceTest.xml", boatDataSource);
|
||||
Race testRace = new Race(raceDataSource, mockOutput);
|
||||
testRace.setDnfChance(0);
|
||||
assertFalse(testRace.doNotFinish());
|
||||
|
||||
} catch (ParserConfigurationException | IOException | SAXException | ParseException | StreamedCourseXMLException e) {
|
||||
e.printStackTrace();
|
||||
fail();
|
||||
}
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void boatsAreSetToDNF() {
|
||||
try {
|
||||
MockOutput mockOutput = Mockito.mock(MockOutput.class);
|
||||
BoatDataSource boatDataSource = new BoatXMLReader("mockXML/boatTest.xml", new Polars());
|
||||
RaceDataSource raceDataSource = new RaceXMLReader("mockXML/raceTest.xml", boatDataSource);
|
||||
Race testRace = new Race(raceDataSource, mockOutput);
|
||||
testRace.setDnfChance(100);
|
||||
Boat testBoat = testRace.getBoats().get(0);
|
||||
testBoat.setCurrentLeg(START_LEG);
|
||||
testBoat.setDistanceTravelledInLeg(START_LEG_DISTANCE + 1);
|
||||
testRace.checkPosition(testBoat, 1);
|
||||
assertEquals(testBoat.getCurrentLeg().getName(), "DNF");
|
||||
|
||||
} catch (ParserConfigurationException | IOException | SAXException | ParseException | StreamedCourseXMLException e) {
|
||||
e.printStackTrace();
|
||||
fail();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void updatePositionIgnoresFinishedBoats() {
|
||||
try {
|
||||
MockOutput mockOutput = Mockito.mock(MockOutput.class);
|
||||
BoatDataSource boatDataSource = new BoatXMLReader("mockXML/boatTest.xml", new Polars());
|
||||
RaceDataSource raceDataSource = new RaceXMLReader("mockXML/raceTest.xml", boatDataSource);
|
||||
Race testRace = new Race(raceDataSource, mockOutput);
|
||||
Boat testBoat = testRace.getBoats().get(0);
|
||||
testBoat.setCurrentLeg(FINISH_LEG);
|
||||
testBoat.setCurrentPosition(ORIGIN.getAverageGPSCoordinate());
|
||||
testRace.updatePosition(testBoat, 1, 1);
|
||||
assertEquals(testBoat.getCurrentPosition(), ORIGIN.getAverageGPSCoordinate());
|
||||
|
||||
} catch (ParserConfigurationException | IOException | SAXException | ParseException | StreamedCourseXMLException e) {
|
||||
e.printStackTrace();
|
||||
fail();
|
||||
}
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void updatePositionChangesBoatPosition() {
|
||||
try {
|
||||
MockOutput mockOutput = Mockito.mock(MockOutput.class);
|
||||
BoatDataSource boatDataSource = new BoatXMLReader("mockXML/boatTest.xml", new Polars());
|
||||
RaceDataSource raceDataSource = new RaceXMLReader("mockXML/raceTest.xml", boatDataSource);
|
||||
Race testRace = new Race(raceDataSource, mockOutput);
|
||||
testRace.initialiseBoats();
|
||||
Boat testBoat = testRace.getBoats().get(0);
|
||||
testBoat.setCurrentLeg(START_LEG);
|
||||
testBoat.setDistanceTravelledInLeg(START_LEG_DISTANCE - 1);
|
||||
testBoat.setCurrentPosition(ORIGIN.getAverageGPSCoordinate());
|
||||
testRace.updatePosition(testBoat, 100, 100);
|
||||
assertFalse(testBoat.getCurrentPosition() == ORIGIN.getAverageGPSCoordinate());
|
||||
} catch (ParserConfigurationException | IOException | SAXException | ParseException | StreamedCourseXMLException e) {
|
||||
e.printStackTrace();
|
||||
fail();
|
||||
}
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void windDirectionCorrectValues(){
|
||||
// try {
|
||||
// MockOutput mockOutput = Mockito.mock(MockOutput.class);
|
||||
// BoatDataSource boatDataSource = new BoatXMLReader("mockXML/boatTest.xml");
|
||||
// RaceDataSource raceDataSource = new RaceXMLReader("mockXML/raceTest.xml", boatDataSource);
|
||||
// Race testRace = new Race(raceDataSource, mockOutput);
|
||||
// testRace.setChangeWind(1);
|
||||
// testRace.setWindDir(65535);
|
||||
// testRace.changeWindDir();
|
||||
// assertEquals(100, testRace.getWind());
|
||||
// } catch (ParserConfigurationException | IOException | SAXException | ParseException | StreamedCourseXMLException e) {
|
||||
// e.printStackTrace();
|
||||
// fail();
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package mock.model;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import shared.model.Bearing;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class VMGTest {
|
||||
|
||||
/**
|
||||
* VMG object to test.
|
||||
*/
|
||||
private VMG vmg;
|
||||
|
||||
/**
|
||||
* Speed of the VMG, in knots.
|
||||
*/
|
||||
private double speed;
|
||||
|
||||
private double speedEpsilon = 0.001;
|
||||
|
||||
/**
|
||||
* Bearing of the vmg.
|
||||
*/
|
||||
private Bearing bearing;
|
||||
|
||||
private double bearingDegreeEpsilon = 0.001;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Constructs a VMG object.
|
||||
*/
|
||||
@Before
|
||||
public void setUp() {
|
||||
|
||||
speed = 14.98;
|
||||
|
||||
bearing = Bearing.fromDegrees(78.5);
|
||||
|
||||
|
||||
vmg = new VMG(speed, bearing);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testVMGSpeed() {
|
||||
|
||||
assertEquals(speed, vmg.getSpeed(), speedEpsilon);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVMGBearing() {
|
||||
|
||||
assertEquals(bearing.degrees(), vmg.getBearing().degrees(), bearingDegreeEpsilon);
|
||||
}
|
||||
}
|
||||
+37
-14
@@ -1,38 +1,59 @@
|
||||
package mock.dataInput;
|
||||
package shared.dataInput;
|
||||
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.xml.sax.SAXException;
|
||||
import seng302.Model.Boat;
|
||||
import seng302.Model.Mark;
|
||||
import seng302.Model.Polars;
|
||||
import shared.exceptions.InvalidBoatDataException;
|
||||
import shared.exceptions.XMLReaderException;
|
||||
import shared.model.Boat;
|
||||
import shared.model.Mark;
|
||||
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import javax.xml.transform.TransformerException;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
//import static org.testng.Assert.*;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
/**
|
||||
* Created by cbt24 on 10/05/17.
|
||||
*/
|
||||
public class BoatXMLReaderTest {
|
||||
BoatDataSource boatData;
|
||||
List<Boat> boats;
|
||||
List<Mark> marks;
|
||||
|
||||
private BoatDataSource boatData;
|
||||
private List<Boat> boats;
|
||||
private List<Mark> marks;
|
||||
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
|
||||
String boatXMLString = null;
|
||||
|
||||
try {
|
||||
boatData = new BoatXMLReader("mockXML/boatTest.xml", new Polars());
|
||||
boatXMLString = XMLReader.readXMLFileToString("mock/mockXML/boatTest.xml", StandardCharsets.UTF_8);
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
fail("could not read boat xml file into a string");
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
|
||||
boatData = new BoatXMLReader(boatXMLString);
|
||||
|
||||
boats = new ArrayList<>(boatData.getBoats().values());
|
||||
marks = new ArrayList<>(boatData.getMarkerBoats().values());
|
||||
} catch (ParserConfigurationException e) {
|
||||
e.printStackTrace();
|
||||
} catch (SAXException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
|
||||
} catch (XMLReaderException | InvalidBoatDataException e) {
|
||||
e.printStackTrace();
|
||||
assertTrue(false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,4 +76,6 @@ public class BoatXMLReaderTest {
|
||||
assertEquals(names[i], marks.get(i).getName());
|
||||
}
|
||||
}
|
||||
|
||||
//TODO should add more tests for various BoatXMLReader functions.
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package shared.model;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class AngleTest {
|
||||
//TODO
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package shared.model;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class AzimuthTest {
|
||||
//TODO
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package shared.model;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class BearingTest {
|
||||
//TODO
|
||||
}
|
||||
@@ -0,0 +1,173 @@
|
||||
package shared.model;
|
||||
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* Created by esa46 on 22/03/17.
|
||||
*/
|
||||
public class BoatTest {
|
||||
|
||||
|
||||
private GPSCoordinate ORIGIN_COORDS;
|
||||
private Boat TEST_BOAT;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
ORIGIN_COORDS = new GPSCoordinate(0, 0);
|
||||
TEST_BOAT = new Boat(1, "Test", "tt");
|
||||
TEST_BOAT.setCurrentPosition(ORIGIN_COORDS);
|
||||
}
|
||||
|
||||
//TODO these bearing tests could be tidied up to reduce code repetition.
|
||||
//TODO also, most of these tests may be more appropriate in GPSCoordinateTest
|
||||
|
||||
@Test
|
||||
public void calculateDueNorthAzimuthReturns0() {
|
||||
|
||||
CompoundMark startMarker = new CompoundMark(
|
||||
1,
|
||||
"start",
|
||||
new Mark(1, "test origin 1", ORIGIN_COORDS) );
|
||||
|
||||
CompoundMark endMarker = new CompoundMark(
|
||||
2,
|
||||
"end",
|
||||
new Mark(2, "test mark 2", new GPSCoordinate(50, 0)) );
|
||||
|
||||
Leg start = new Leg("Start", startMarker, endMarker, 0);
|
||||
TEST_BOAT.setCurrentLeg(start);
|
||||
assertEquals(GPSCoordinate.calculateAzimuth(startMarker.getAverageGPSCoordinate(), endMarker.getAverageGPSCoordinate()).degrees(), 0, 1e-8);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void calculateDueSouthAzimuthReturns180() {
|
||||
CompoundMark startMarker = new CompoundMark(
|
||||
1,
|
||||
"start",
|
||||
new Mark(1, "test origin 1", ORIGIN_COORDS) );
|
||||
|
||||
CompoundMark endMarker = new CompoundMark(
|
||||
2,
|
||||
"end",
|
||||
new Mark(2, "test mark 2", new GPSCoordinate(-50, 0)) );
|
||||
|
||||
Leg start = new Leg("Start", startMarker, endMarker, 0);
|
||||
TEST_BOAT.setCurrentLeg(start);
|
||||
assertEquals(GPSCoordinate.calculateAzimuth(startMarker.getAverageGPSCoordinate(), endMarker.getAverageGPSCoordinate()).degrees(), -180, 1e-8);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void calculateDueEastAzimuthReturns90() {
|
||||
|
||||
CompoundMark startMarker = new CompoundMark(
|
||||
1,
|
||||
"start",
|
||||
new Mark(1, "test origin 1", ORIGIN_COORDS) );
|
||||
|
||||
CompoundMark endMarker = new CompoundMark(
|
||||
2,
|
||||
"end",
|
||||
new Mark(2, "test mark 2", new GPSCoordinate(0, 50)) );
|
||||
|
||||
Leg start = new Leg("Start", startMarker, endMarker, 0);
|
||||
TEST_BOAT.setCurrentLeg(start);
|
||||
assertEquals(GPSCoordinate.calculateAzimuth(startMarker.getAverageGPSCoordinate(), endMarker.getAverageGPSCoordinate()).degrees(), 90, 1e-8);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void calculateDueWestAzimuthReturnsNegative90() {
|
||||
CompoundMark startMarker = new CompoundMark(
|
||||
1,
|
||||
"start",
|
||||
new Mark(1, "test origin 1", ORIGIN_COORDS) );
|
||||
|
||||
CompoundMark endMarker = new CompoundMark(
|
||||
2,
|
||||
"end",
|
||||
new Mark(2, "test mark 2", new GPSCoordinate(0, -50)) );
|
||||
|
||||
Leg start = new Leg("Start", startMarker, endMarker, 0);
|
||||
TEST_BOAT.setCurrentLeg(start);
|
||||
assertEquals(GPSCoordinate.calculateAzimuth(startMarker.getAverageGPSCoordinate(), endMarker.getAverageGPSCoordinate()).degrees(), -90, 1e-8);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void calculateDueNorthHeadingReturns0() {
|
||||
|
||||
CompoundMark startMarker = new CompoundMark(
|
||||
1,
|
||||
"start",
|
||||
new Mark(1, "test origin 1", ORIGIN_COORDS) );
|
||||
|
||||
CompoundMark endMarker = new CompoundMark(
|
||||
2,
|
||||
"end",
|
||||
new Mark(2, "test mark 2", new GPSCoordinate(50, 0)) );
|
||||
|
||||
Leg start = new Leg("Start", startMarker, endMarker, 0);
|
||||
TEST_BOAT.setCurrentLeg(start);
|
||||
assertEquals(GPSCoordinate.calculateAzimuth(TEST_BOAT.getCurrentPosition(), endMarker.getAverageGPSCoordinate()).degrees(), 0, 1e-8);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void calculateDueEastHeadingReturns90() {
|
||||
CompoundMark startMarker = new CompoundMark(
|
||||
1,
|
||||
"start",
|
||||
new Mark(1, "test origin 1", ORIGIN_COORDS) );
|
||||
|
||||
CompoundMark endMarker = new CompoundMark(
|
||||
2,
|
||||
"end",
|
||||
new Mark(2, "test mark 2", new GPSCoordinate(0, 50)) );
|
||||
|
||||
Leg start = new Leg("Start", startMarker, endMarker, 0);
|
||||
TEST_BOAT.setCurrentLeg(start);
|
||||
assertEquals(GPSCoordinate.calculateAzimuth(TEST_BOAT.getCurrentPosition(), endMarker.getAverageGPSCoordinate()).degrees(), 90, 1e-8);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void calculateDueSouthHeadingReturns180() {
|
||||
CompoundMark startMarker = new CompoundMark(
|
||||
1,
|
||||
"start",
|
||||
new Mark(1, "test origin 1", ORIGIN_COORDS) );
|
||||
|
||||
CompoundMark endMarker = new CompoundMark(
|
||||
2,
|
||||
"end",
|
||||
new Mark(2, "test mark 2", new GPSCoordinate(-50, 0)) );
|
||||
|
||||
Leg start = new Leg("Start", startMarker, endMarker, 0);
|
||||
TEST_BOAT.setCurrentLeg(start);
|
||||
assertEquals(GPSCoordinate.calculateAzimuth(TEST_BOAT.getCurrentPosition(), endMarker.getAverageGPSCoordinate()).degrees(), -180, 1e-8);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void calculateDueWestHeadingReturns270() {
|
||||
CompoundMark startMarker = new CompoundMark(
|
||||
1,
|
||||
"start",
|
||||
new Mark(1, "test origin 1", ORIGIN_COORDS) );
|
||||
|
||||
CompoundMark endMarker = new CompoundMark(
|
||||
2,
|
||||
"end",
|
||||
new Mark(2, "test mark 2", new GPSCoordinate(0, -50)) );
|
||||
|
||||
Leg start = new Leg("Start", startMarker, endMarker, 0);
|
||||
TEST_BOAT.setCurrentLeg(start);
|
||||
assertEquals(GPSCoordinate.calculateBearing(TEST_BOAT.getCurrentPosition(), endMarker.getAverageGPSCoordinate()).degrees(), 270, 1e-8);
|
||||
}
|
||||
|
||||
|
||||
//TODO test Boat#setCurrentLeg and it's effects.
|
||||
}
|
||||
+39
-10
@@ -1,23 +1,34 @@
|
||||
package mock.model;
|
||||
package shared.model;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
//import static org.testng.AssertJUnit.assertEquals;
|
||||
|
||||
/**
|
||||
* Created by esa46 on 29/03/17.
|
||||
*/
|
||||
public class CompoundMarkTest {
|
||||
|
||||
GPSCoordinate ORIGIN_COORD = new GPSCoordinate(0, 0);
|
||||
private GPSCoordinate ORIGIN_COORD;
|
||||
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
ORIGIN_COORD = new GPSCoordinate(0, 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void averageOfSingleMarkAtOriginIsSingleMark() {
|
||||
|
||||
CompoundMark testMark = new CompoundMark(new Mark(1, "test origin 1", ORIGIN_COORD));
|
||||
assertTrue(testMark.getAverageGPSCoordinate().equals(ORIGIN_COORD));
|
||||
CompoundMark testMark = new CompoundMark(
|
||||
1,
|
||||
"test",
|
||||
new Mark(1, "test origin 1", ORIGIN_COORD) );
|
||||
|
||||
assertTrue(testMark.getAverageGPSCoordinate().equals(ORIGIN_COORD) );
|
||||
|
||||
}
|
||||
|
||||
@@ -25,7 +36,11 @@ public class CompoundMarkTest {
|
||||
public void averageOfSingleMarkIsSingleMark() {
|
||||
|
||||
GPSCoordinate testCoord = new GPSCoordinate(20, 25);
|
||||
CompoundMark testMark = new CompoundMark(new Mark(1, "test origin 1", testCoord));
|
||||
CompoundMark testMark = new CompoundMark(
|
||||
1,
|
||||
"test",
|
||||
new Mark(1, "test origin 1", testCoord));
|
||||
|
||||
assertTrue(testMark.getAverageGPSCoordinate().equals(testCoord));
|
||||
|
||||
}
|
||||
@@ -34,7 +49,12 @@ public class CompoundMarkTest {
|
||||
public void averageLatOfTwoMarksIsAccurate() {
|
||||
|
||||
GPSCoordinate testCoord = new GPSCoordinate(0.001, 0);
|
||||
CompoundMark testMark = new CompoundMark(new Mark(1, "test origin 1", ORIGIN_COORD), new Mark(2, "test origin 2", testCoord));
|
||||
CompoundMark testMark = new CompoundMark(
|
||||
1,
|
||||
"test",
|
||||
new Mark(1, "test origin 1", ORIGIN_COORD),
|
||||
new Mark(2, "test origin 2", testCoord) );
|
||||
|
||||
assertEquals(testMark.getAverageGPSCoordinate(), new GPSCoordinate(0.0005, 0));
|
||||
|
||||
}
|
||||
@@ -43,18 +63,27 @@ public class CompoundMarkTest {
|
||||
public void averageLongOfTwoMarksIsAccurate() {
|
||||
|
||||
GPSCoordinate testCoord = new GPSCoordinate(0, 10);
|
||||
CompoundMark testMark = new CompoundMark(new Mark(1, "test origin 1", ORIGIN_COORD), new Mark(2, "test origin 2", testCoord));
|
||||
CompoundMark testMark = new CompoundMark(
|
||||
1,
|
||||
"test",
|
||||
new Mark(1, "test origin 1", ORIGIN_COORD),
|
||||
new Mark(2, "test origin 2", testCoord) );
|
||||
|
||||
assertTrue(testMark.getAverageGPSCoordinate().equals(new GPSCoordinate(0, 5)));
|
||||
}
|
||||
|
||||
@Ignore
|
||||
|
||||
@Test
|
||||
public void averageLatAndLongOfTwoMarksIsAccurate() {
|
||||
|
||||
GPSCoordinate testCoord1 = new GPSCoordinate(0.0, 30);
|
||||
GPSCoordinate testCoord2 = new GPSCoordinate(0.001, 60);
|
||||
|
||||
CompoundMark testMark = new CompoundMark(new Mark(1, "test origin 1", testCoord1), new Mark(2, "test origin 2", testCoord2));
|
||||
CompoundMark testMark = new CompoundMark(
|
||||
1,
|
||||
"test",
|
||||
new Mark(1, "test origin 1", testCoord1),
|
||||
new Mark(2, "test origin 2", testCoord2) );
|
||||
|
||||
assertEquals(testMark.getAverageGPSCoordinate().getLatitude(), 0.00051776, 1e-8);
|
||||
assertEquals(testMark.getAverageGPSCoordinate().getLongitude(), 45.000000, 1e-8);
|
||||
+4
-3
@@ -1,4 +1,4 @@
|
||||
package mock.model;
|
||||
package shared.model;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -6,8 +6,9 @@ import org.junit.Test;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static junit.framework.TestCase.assertFalse;
|
||||
import static junit.framework.TestCase.assertTrue;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
|
||||
/**
|
||||
* Created by jjg64 on 11/05/17.
|
||||
+20
-5
@@ -1,17 +1,29 @@
|
||||
package mock.model;
|
||||
package shared.model;
|
||||
|
||||
import org.geotools.referencing.GeodeticCalculator;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import seng302.Constants;
|
||||
|
||||
import java.awt.geom.Point2D;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* Created by esa46 on 22/03/17.
|
||||
*
|
||||
*/
|
||||
public class LegTest {
|
||||
|
||||
private CompoundMark ORIGIN_COMPOUND_MARKER = new CompoundMark(new Mark(1, "test mark1", new GPSCoordinate(0, 0)));
|
||||
private CompoundMark ORIGIN_COMPOUND_MARKER;
|
||||
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
ORIGIN_COMPOUND_MARKER = new CompoundMark(
|
||||
1,
|
||||
"origin",
|
||||
new Mark(1, "test mark1", new GPSCoordinate(0, 0)) );
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void calculateDistanceHandles5nmNorth() {
|
||||
@@ -68,7 +80,10 @@ public class LegTest {
|
||||
|
||||
GPSCoordinate coords = new GPSCoordinate(point.getY(), point.getX());
|
||||
|
||||
return new CompoundMark(new Mark(3, "test mark3", coords));
|
||||
return new CompoundMark(
|
||||
1,
|
||||
"test compound 3",
|
||||
new Mark(3, "test mark3", coords) );
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package shared.model;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class MarkTest {
|
||||
//TODO
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package shared.model;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class RaceClockTest {
|
||||
//TODO
|
||||
}
|
||||
@@ -0,0 +1,345 @@
|
||||
//package shared.model;
|
||||
//
|
||||
//
|
||||
//import mock.model.Polars;
|
||||
//import org.junit.Before;
|
||||
//import org.junit.Ignore;
|
||||
//import org.junit.Test;
|
||||
//import org.mockito.Mockito;
|
||||
//import org.xml.sax.SAXException;
|
||||
//
|
||||
//import javax.xml.parsers.ParserConfigurationException;
|
||||
//import java.io.IOException;
|
||||
//import java.text.ParseException;
|
||||
//import java.util.ArrayList;
|
||||
//
|
||||
//import static org.junit.Assert.*;
|
||||
//import static org.mockito.Mockito.*;
|
||||
//
|
||||
///**
|
||||
// * Created by esa46 on 15/03/17.
|
||||
// */
|
||||
//public class RaceTest{
|
||||
//
|
||||
//
|
||||
// private CompoundMark ORIGIN;
|
||||
//
|
||||
// private CompoundMark THREE_NM_FROM_ORIGIN;
|
||||
//
|
||||
// private CompoundMark FIFTEEN_NM_FROM_ORIGIN;
|
||||
//
|
||||
// private ArrayList<Leg> TEST_LEGS = new ArrayList<>();
|
||||
//
|
||||
// private int START_LEG_DISTANCE = 3;
|
||||
// private int MIDDLE_LEG_DISTANCE = 12;
|
||||
//
|
||||
// private Leg START_LEG;
|
||||
//
|
||||
// private Leg MIDDLE_LEG;
|
||||
//
|
||||
// private Leg FINISH_LEG;
|
||||
//
|
||||
//
|
||||
// @Before
|
||||
// public void setUp() {
|
||||
//
|
||||
// ORIGIN = new CompoundMark(
|
||||
// 1,
|
||||
// "origin compound",
|
||||
// new Mark(1, "test origin 1", new GPSCoordinate(0, 0)) );
|
||||
//
|
||||
//
|
||||
// THREE_NM_FROM_ORIGIN = new CompoundMark(
|
||||
// 2,
|
||||
// "3 NM from origin compound",
|
||||
// new Mark(2, "test mark 2", new GPSCoordinate(0.050246769, 0)) );
|
||||
//
|
||||
//
|
||||
// FIFTEEN_NM_FROM_ORIGIN = new CompoundMark(
|
||||
// 3,
|
||||
// "15 NM from origin compound",
|
||||
// new Mark(3, "test mark 3", new GPSCoordinate(0.251233845, 0)) );
|
||||
//
|
||||
//
|
||||
// START_LEG = new Leg("Start", ORIGIN, THREE_NM_FROM_ORIGIN, 0);
|
||||
//
|
||||
//
|
||||
// MIDDLE_LEG = new Leg("Middle", THREE_NM_FROM_ORIGIN, FIFTEEN_NM_FROM_ORIGIN, 1);
|
||||
//
|
||||
//
|
||||
// FINISH_LEG = new Leg("Finish", FIFTEEN_NM_FROM_ORIGIN, FIFTEEN_NM_FROM_ORIGIN, 2);
|
||||
//
|
||||
//
|
||||
// TEST_LEGS.add(START_LEG);
|
||||
// TEST_LEGS.add(MIDDLE_LEG);
|
||||
// TEST_LEGS.add(FINISH_LEG);
|
||||
// }
|
||||
//
|
||||
// @Ignore
|
||||
// @Test
|
||||
// public void countdownTimerSendsBoatLocations() {
|
||||
//
|
||||
// try {
|
||||
// MockOutput mockOutput = Mockito.mock(MockOutput.class);
|
||||
// BoatDataSource boatDataSource = new BoatXMLReader("mockXML/boatTest.xml", new Polars());
|
||||
// RaceDataSource raceDataSource = new RaceXMLReader("mockXML/raceTest.xml", boatDataSource);
|
||||
// Race testRace = new Race(raceDataSource, mockOutput);
|
||||
// testRace.initialiseBoats();
|
||||
// testRace.countdownTimer.handle(1);
|
||||
// verify(mockOutput, atLeast(boatDataSource.getBoats().size())).parseBoatLocation(anyInt(), anyDouble(), anyDouble(), anyDouble(), anyDouble(), anyLong());
|
||||
//
|
||||
// } catch (ParserConfigurationException | IOException | SAXException | ParseException | StreamedCourseXMLException e) {
|
||||
// e.printStackTrace();
|
||||
// fail();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Ignore
|
||||
// @Test
|
||||
// public void countdownTimerSendsRaceStatusMessages() {
|
||||
//
|
||||
// try {
|
||||
// MockOutput mockOutput = Mockito.mock(MockOutput.class);
|
||||
// RaceDataSource dataSource = new RaceXMLReader("mockXML/raceTest.xml", new BoatXMLReader("mockXML/boatTest.xml", new Polars()));
|
||||
// Race testRace = new Race(dataSource, mockOutput);
|
||||
// testRace.initialiseBoats();
|
||||
// testRace.countdownTimer.handle(1);
|
||||
// verify(mockOutput, atLeast(1)).parseRaceStatus(any());
|
||||
//
|
||||
// } catch (ParserConfigurationException | IOException | SAXException | ParseException | StreamedCourseXMLException e) {
|
||||
// e.printStackTrace();
|
||||
// fail();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Ignore
|
||||
// @Test
|
||||
// public void checkPositionFinishedUpdatesNumberFinishedBoats() {
|
||||
//
|
||||
// try {
|
||||
// MockOutput mockOutput = Mockito.mock(MockOutput.class);
|
||||
// RaceDataSource dataSource = new RaceXMLReader("mockXML/raceTest.xml", new BoatXMLReader("mockXML/boatTest.xml", new Polars()));
|
||||
// Race testRace = new Race(dataSource, mockOutput);
|
||||
// testRace.initialiseBoats();
|
||||
// Boat testBoat = testRace.getBoats().get(0);
|
||||
// testBoat.setCurrentLeg(FINISH_LEG);
|
||||
// testBoat.setDistanceTravelledInLeg(1);
|
||||
// testRace.checkPosition(testBoat, 1);
|
||||
//
|
||||
// assertEquals(testRace.getNumberOfActiveBoats(), 0);
|
||||
//
|
||||
// } catch (ParserConfigurationException | IOException | SAXException | ParseException | StreamedCourseXMLException e) {
|
||||
// e.printStackTrace();
|
||||
// fail();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Ignore
|
||||
// @Test
|
||||
// public void checkPositionSetFinishedBoatVelocityTo0() {
|
||||
//
|
||||
// try {
|
||||
// MockOutput mockOutput = Mockito.mock(MockOutput.class);
|
||||
// RaceDataSource dataSource = new RaceXMLReader("mockXML/raceTest.xml", new BoatXMLReader("mockXML/boatTest.xml", new Polars()));
|
||||
// Race testRace = new Race(dataSource, mockOutput);
|
||||
// testRace.initialiseBoats();
|
||||
// Boat testBoat = testRace.getBoats().get(0);
|
||||
// testBoat.setCurrentLeg(FINISH_LEG);
|
||||
// testBoat.setDistanceTravelledInLeg(1);
|
||||
// testRace.checkPosition(testBoat, 1);
|
||||
//
|
||||
// assertEquals(testBoat.getCurrentSpeed(), 0, 1e-8);
|
||||
//
|
||||
// } catch (ParserConfigurationException | IOException | SAXException | ParseException | StreamedCourseXMLException e) {
|
||||
// e.printStackTrace();
|
||||
// fail();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Ignore
|
||||
// @Test
|
||||
// public void checkPositionSetsFinishTime() {
|
||||
//
|
||||
// try {
|
||||
// MockOutput mockOutput = Mockito.mock(MockOutput.class);
|
||||
// RaceDataSource dataSource = new RaceXMLReader("mockXML/raceTest.xml", new BoatXMLReader("mockXML/boatTest.xml", new Polars()));
|
||||
// Race testRace = new Race(dataSource, mockOutput);
|
||||
// testRace.initialiseBoats();
|
||||
// Boat testBoat = testRace.getBoats().get(0);
|
||||
// testBoat.setCurrentLeg(FINISH_LEG);
|
||||
// testBoat.setDistanceTravelledInLeg(1);
|
||||
// testRace.checkPosition(testBoat, 1);
|
||||
//
|
||||
// assertEquals(testBoat.getTimeFinished(), 1, 1e-8);
|
||||
//
|
||||
// } catch (ParserConfigurationException | IOException | SAXException | ParseException | StreamedCourseXMLException e) {
|
||||
// e.printStackTrace();
|
||||
// fail();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Ignore
|
||||
// @Test
|
||||
// public void checkPositionUnfinishedDoesntUpdateNumberFinishedBoats() {
|
||||
//
|
||||
// try {
|
||||
// MockOutput mockOutput = Mockito.mock(MockOutput.class);
|
||||
// RaceDataSource dataSource = new RaceXMLReader("mockXML/raceTest.xml", new BoatXMLReader("mockXML/boatTest.xml", new Polars()));
|
||||
// Race testRace = new Race(dataSource, mockOutput);
|
||||
// testRace.initialiseBoats();
|
||||
// Boat testBoat = testRace.getBoats().get(0);
|
||||
// testBoat.setCurrentLeg(START_LEG);
|
||||
// testBoat.setDistanceTravelledInLeg(START_LEG_DISTANCE);
|
||||
// testRace.checkPosition(testBoat, 1);
|
||||
//
|
||||
// assertEquals(testRace.getNumberOfActiveBoats(), 1);
|
||||
//
|
||||
// } catch (ParserConfigurationException | IOException | SAXException | ParseException | StreamedCourseXMLException e) {
|
||||
// e.printStackTrace();
|
||||
// fail();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//
|
||||
// @Ignore
|
||||
// @Test
|
||||
// public void distanceTravelledBeforeUpdatingLegIsRetained() {
|
||||
//
|
||||
// try {
|
||||
// MockOutput mockOutput = Mockito.mock(MockOutput.class);
|
||||
// RaceDataSource dataSource = new RaceXMLReader("mockXML/raceTest.xml", new BoatXMLReader("mockXML/boatTest.xml", new Polars()));
|
||||
// Race testRace = new Race(dataSource, mockOutput);
|
||||
// testRace.initialiseBoats();
|
||||
// Boat testBoat = testRace.getBoats().get(0);
|
||||
// testBoat.setCurrentLeg(START_LEG);
|
||||
// testBoat.setDistanceTravelledInLeg(START_LEG_DISTANCE + 1);
|
||||
// testRace.checkPosition(testBoat, 0);
|
||||
//
|
||||
// assertEquals(testBoat.getDistanceTravelledInLeg(), 1, 1e-7);
|
||||
//
|
||||
// } catch (ParserConfigurationException | IOException | SAXException | ParseException | StreamedCourseXMLException e) {
|
||||
// e.printStackTrace();
|
||||
// fail();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Ignore
|
||||
// @Test
|
||||
// public void doNotFinishAnswersYesIf100PercentChance() {
|
||||
//
|
||||
// try {
|
||||
// MockOutput mockOutput = Mockito.mock(MockOutput.class);
|
||||
// BoatDataSource boatDataSource = new BoatXMLReader("mockXML/boatTest.xml", new Polars());
|
||||
// RaceDataSource raceDataSource = new RaceXMLReader("mockXML/raceTest.xml", boatDataSource);
|
||||
// Race testRace = new Race(raceDataSource, mockOutput);
|
||||
//
|
||||
// testRace.setDnfChance(100);
|
||||
// assertTrue(testRace.doNotFinish());
|
||||
//
|
||||
// } catch (ParserConfigurationException | IOException | SAXException | ParseException | StreamedCourseXMLException e) {
|
||||
// e.printStackTrace();
|
||||
// fail();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Ignore
|
||||
// @Test
|
||||
// public void doNotFinishAnswersNoIf0PercentChance() {
|
||||
//
|
||||
// try {
|
||||
// MockOutput mockOutput = Mockito.mock(MockOutput.class);
|
||||
// BoatDataSource boatDataSource = new BoatXMLReader("mockXML/boatTest.xml", new Polars());
|
||||
// RaceDataSource raceDataSource = new RaceXMLReader("mockXML/raceTest.xml", boatDataSource);
|
||||
// Race testRace = new Race(raceDataSource, mockOutput);
|
||||
// testRace.setDnfChance(0);
|
||||
// assertFalse(testRace.doNotFinish());
|
||||
//
|
||||
// } catch (ParserConfigurationException | IOException | SAXException | ParseException | StreamedCourseXMLException e) {
|
||||
// e.printStackTrace();
|
||||
// fail();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Ignore
|
||||
// @Test
|
||||
// public void boatsAreSetToDNF() {
|
||||
// try {
|
||||
// MockOutput mockOutput = Mockito.mock(MockOutput.class);
|
||||
// BoatDataSource boatDataSource = new BoatXMLReader("mockXML/boatTest.xml", new Polars());
|
||||
// RaceDataSource raceDataSource = new RaceXMLReader("mockXML/raceTest.xml", boatDataSource);
|
||||
// Race testRace = new Race(raceDataSource, mockOutput);
|
||||
// testRace.setDnfChance(100);
|
||||
// Boat testBoat = testRace.getBoats().get(0);
|
||||
// testBoat.setCurrentLeg(START_LEG);
|
||||
// testBoat.setDistanceTravelledInLeg(START_LEG_DISTANCE + 1);
|
||||
// testRace.checkPosition(testBoat, 1);
|
||||
// assertEquals(testBoat.getCurrentLeg().getName(), "DNF");
|
||||
//
|
||||
// } catch (ParserConfigurationException | IOException | SAXException | ParseException | StreamedCourseXMLException e) {
|
||||
// e.printStackTrace();
|
||||
// fail();
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @Ignore
|
||||
// @Test
|
||||
// public void updatePositionIgnoresFinishedBoats() {
|
||||
// try {
|
||||
// MockOutput mockOutput = Mockito.mock(MockOutput.class);
|
||||
// BoatDataSource boatDataSource = new BoatXMLReader("mockXML/boatTest.xml", new Polars());
|
||||
// RaceDataSource raceDataSource = new RaceXMLReader("mockXML/raceTest.xml", boatDataSource);
|
||||
// Race testRace = new Race(raceDataSource, mockOutput);
|
||||
// Boat testBoat = testRace.getBoats().get(0);
|
||||
// testBoat.setCurrentLeg(FINISH_LEG);
|
||||
// testBoat.setCurrentPosition(ORIGIN.getAverageGPSCoordinate());
|
||||
// testRace.updatePosition(testBoat, 1, 1);
|
||||
// assertEquals(testBoat.getCurrentPosition(), ORIGIN.getAverageGPSCoordinate());
|
||||
//
|
||||
// } catch (ParserConfigurationException | IOException | SAXException | ParseException | StreamedCourseXMLException e) {
|
||||
// e.printStackTrace();
|
||||
// fail();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Ignore
|
||||
// @Test
|
||||
// public void updatePositionChangesBoatPosition() {
|
||||
// try {
|
||||
// MockOutput mockOutput = Mockito.mock(MockOutput.class);
|
||||
// BoatDataSource boatDataSource = new BoatXMLReader("mockXML/boatTest.xml", new Polars());
|
||||
// RaceDataSource raceDataSource = new RaceXMLReader("mockXML/raceTest.xml", boatDataSource);
|
||||
// Race testRace = new Race(raceDataSource, mockOutput);
|
||||
// testRace.initialiseBoats();
|
||||
// Boat testBoat = testRace.getBoats().get(0);
|
||||
// testBoat.setCurrentLeg(START_LEG);
|
||||
// testBoat.setDistanceTravelledInLeg(START_LEG_DISTANCE - 1);
|
||||
// testBoat.setCurrentPosition(ORIGIN.getAverageGPSCoordinate());
|
||||
// testRace.updatePosition(testBoat, 100, 100);
|
||||
// assertFalse(testBoat.getCurrentPosition() == ORIGIN.getAverageGPSCoordinate());
|
||||
// } catch (ParserConfigurationException | IOException | SAXException | ParseException | StreamedCourseXMLException e) {
|
||||
// e.printStackTrace();
|
||||
// fail();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Ignore
|
||||
// @Test
|
||||
// public void windDirectionCorrectValues(){
|
||||
//// try {
|
||||
//// MockOutput mockOutput = Mockito.mock(MockOutput.class);
|
||||
//// BoatDataSource boatDataSource = new BoatXMLReader("mockXML/boatTest.xml");
|
||||
//// RaceDataSource raceDataSource = new RaceXMLReader("mockXML/raceTest.xml", boatDataSource);
|
||||
//// Race testRace = new Race(raceDataSource, mockOutput);
|
||||
//// testRace.setChangeWind(1);
|
||||
//// testRace.setWindDir(65535);
|
||||
//// testRace.changeWindDir();
|
||||
//// assertEquals(100, testRace.getWind());
|
||||
//// } catch (ParserConfigurationException | IOException | SAXException | ParseException | StreamedCourseXMLException e) {
|
||||
//// e.printStackTrace();
|
||||
//// fail();
|
||||
//// }
|
||||
// }
|
||||
//
|
||||
//
|
||||
//}
|
||||
@@ -0,0 +1,8 @@
|
||||
Tws,Twa0,Bsp0,Twa1,Bsp1,UpTwa,UpBsp,Twa2,Bsp2,Twa3,Bsp3,Twa4,Bsp4,Twa5,Bsp5,Twa6,Bsp6,DnTwa,DnBsp,Twa7,Bsp7,Twa4
|
||||
4,0,0,30,4,45,8,60,9,75,10,90www,10,115,10,145,10,155,10,175,4,179
|
||||
8,0,0,30,7,43,10,60,11,75,11,90,11,115,12,145,12,153,12,175,10,179
|
||||
12,0,0,30,11,43,14.4,60,16,75,20,90,23,115,24,145,23,153,21.6,175,14,179
|
||||
16,0,0,30,12,42,19.2,60,25,75,27,90,31,115,32,145,30,153,28.8,175,20,179
|
||||
20,0,0,30,13,41,24,60,29,75,37,90,39,115,40,145,38,153,36,175,24,179
|
||||
25,0,0,30,15,40,30,60,38,75,44,90,49,115,50,145,49,151,47,175,30,179
|
||||
30,0,0,30,15,42,30,60,37,75,42,90,48,115,49,145,48,150,46,175,32,179
|
||||
|
Reference in New Issue
Block a user