Merge branch 'story30_XMLs' into splitIntoTwoModules
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
package seng302.Mock;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import java.io.IOException;
|
||||
import java.text.ParseException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Created by jjg64 on 21/04/17.
|
||||
*/
|
||||
public class BoatsXMLTest {
|
||||
BoatXMLReader boatXMLReader;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
try {
|
||||
boatXMLReader = new BoatXMLReader("mockXML/boatXML/boatTest.xml", false);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
//fail("Cannot find mockXML/raceXML/raceTest.xml in the resources folder");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvalidParticipant() {
|
||||
Map<Integer, StreamedBoat> inputParticipants = new HashMap<>();
|
||||
inputParticipants.put(420, new StreamedBoat(420));
|
||||
boatXMLReader.setParticipants(inputParticipants);
|
||||
boatXMLReader.read();
|
||||
assertEquals(boatXMLReader.getStreamedBoatMap().size(), 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidParticipant() {
|
||||
Map<Integer, StreamedBoat> inputParticipants = new HashMap<>();
|
||||
inputParticipants.put(101, new StreamedBoat(101));
|
||||
boatXMLReader.setParticipants(inputParticipants);
|
||||
boatXMLReader.read();
|
||||
assertTrue(boatXMLReader.getStreamedBoatMap().containsKey(101));
|
||||
}
|
||||
}
|
||||
@@ -16,7 +16,7 @@ public class RegattaXMLTest {
|
||||
@Before
|
||||
public void findFile(){
|
||||
try {
|
||||
regattaXMLReader = new RegattaXMLReader("mockXML/regattaXML/regattaTest.xml", false);
|
||||
regattaXMLReader = new RegattaXMLReader("mockXML/regattaXML/regattaTest.xml");
|
||||
} catch (Exception e) {
|
||||
fail("Cannot find mockXML/regattaXML/regattaTest.xml in the resources folder");
|
||||
}
|
||||
@@ -24,29 +24,19 @@ public class RegattaXMLTest {
|
||||
|
||||
@Test
|
||||
public void makeRegattaTest() {
|
||||
try {
|
||||
regattaXMLReader = new RegattaXMLReader("mockXML/regattaXML/regattaTest.xml");
|
||||
assertNotEquals(regattaXMLReader.getRegatta(), null);
|
||||
} catch (Exception e) {
|
||||
fail("Did not make a Regatta object");
|
||||
}
|
||||
assertNotEquals(regattaXMLReader.getRegatta(), null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void correctValuesTest() {
|
||||
try {
|
||||
regattaXMLReader = new RegattaXMLReader("mockXML/regattaXML/regattaTest.xml");
|
||||
Regatta regatta = regattaXMLReader.getRegatta();
|
||||
assertEquals(regatta.getRegattaID(), 3);
|
||||
assertEquals(regatta.getRegattaName(), "New Zealand Test");
|
||||
assertEquals(regatta.getCourseName(), "North Head");
|
||||
assertEquals(regatta.getCentralLatitude(), -36.82791529, 0.00000001);
|
||||
assertEquals(regatta.getCentralLongitude(), 174.81218919, 0.00000001);
|
||||
assertEquals(regatta.getCentralAltitude(), 0.00, 0.00000001);
|
||||
assertEquals(regatta.getUtcOffset(), 12.0, 0.001);
|
||||
assertEquals(regatta.getMagneticVariation(), 14.1, 0.001);
|
||||
} catch (Exception e) {
|
||||
fail("Did not have the correct values");
|
||||
}
|
||||
Regatta regatta = regattaXMLReader.getRegatta();
|
||||
assertEquals(regatta.getRegattaID(), 3);
|
||||
assertEquals(regatta.getRegattaName(), "New Zealand Test");
|
||||
assertEquals(regatta.getCourseName(), "North Head");
|
||||
assertEquals(regatta.getCentralLatitude(), -36.82791529, 0.00000001);
|
||||
assertEquals(regatta.getCentralLongitude(), 174.81218919, 0.00000001);
|
||||
assertEquals(regatta.getCentralAltitude(), 0.00, 0.00000001);
|
||||
assertEquals(regatta.getUtcOffset(), 12.0, 0.001);
|
||||
assertEquals(regatta.getMagneticVariation(), 14.1, 0.001);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
package seng302.Mock;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import seng302.GPSCoordinate;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
/**
|
||||
* Tests only work on the current version of mockXML/raceXML/raceTest.xml
|
||||
*/
|
||||
public class StreamedRaceTest {
|
||||
StreamedCourseXMLReader streamedCourseXMLReader;
|
||||
List<GPSCoordinate> boundary;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
try {
|
||||
streamedCourseXMLReader = new StreamedCourseXMLReader("mockXML/raceXML/raceTest.xml", true);
|
||||
boundary = streamedCourseXMLReader.getBoundary();
|
||||
} catch (Exception 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 testParticipants() {
|
||||
Map<Integer, StreamedBoat> participants = streamedCourseXMLReader.getParticipants();
|
||||
assertTrue(participants.containsKey(107));
|
||||
assertTrue(participants.containsKey(108));
|
||||
}
|
||||
}
|
||||
@@ -1,173 +1,18 @@
|
||||
package seng302.Model;
|
||||
|
||||
import javafx.scene.paint.Color;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import seng302.GPSCoordinate;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import org.mockito.Mock;
|
||||
import seng302.RaceDataSource;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
/**
|
||||
* Created by esa46 on 15/03/17.
|
||||
*/
|
||||
public class RaceTest {
|
||||
|
||||
Leg START_LEG = new Leg("Start", new Marker(new GPSCoordinate(0, 0)), new Marker(new GPSCoordinate(1, 1)), 0);
|
||||
Leg FINISH_LEG = new Leg("Finish", new Marker(new GPSCoordinate(1, 1)), new Marker(new GPSCoordinate(2, 2)), 0);
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void timerCanBeDisabled() {
|
||||
BoatInRace boat1 = new BoatInRace("Test 1", 10000, Color.ALICEBLUE, "t1");
|
||||
BoatInRace boat2 = new BoatInRace("Test 2", 10000, Color.BURLYWOOD, "t2");
|
||||
BoatInRace[] boats = new BoatInRace[]{boat1, boat2};
|
||||
|
||||
ArrayList<Leg> legs = new ArrayList<>();
|
||||
legs.add(START_LEG); legs.add(FINISH_LEG);
|
||||
|
||||
ConstantVelocityRace race = new ConstantVelocityRace(boats, legs, null, 5);
|
||||
race.disableTimer();
|
||||
race.setDnfChance(0);
|
||||
long timeStarted = System.currentTimeMillis();
|
||||
race.run();
|
||||
|
||||
assertTrue(System.currentTimeMillis() - timeStarted < 4000);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkPositionUpdatesNumberFinishedBoats() {
|
||||
|
||||
BoatInRace finishedBoat = new BoatInRace("Test", 1000, Color.ALICEBLUE, "tt");
|
||||
finishedBoat.setDistanceTravelledInLeg(500);
|
||||
|
||||
finishedBoat.setCurrentLeg(FINISH_LEG);
|
||||
|
||||
ArrayList<Leg> legs = new ArrayList<>();
|
||||
legs.add(FINISH_LEG);
|
||||
|
||||
ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[1], legs, null, 1);
|
||||
race.setDnfChance(0);
|
||||
assertEquals(race.boatsFinished, 0);
|
||||
|
||||
|
||||
race.checkPosition(finishedBoat, 100000);
|
||||
assertEquals(race.boatsFinished, 1);
|
||||
assertEquals(finishedBoat.getTimeFinished(), 100000);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkPositionDoesntUpdateNumberFinishedBoats() {
|
||||
|
||||
BoatInRace unFinishedBoat = new BoatInRace("Test", 10, Color.ALICEBLUE, "tt");
|
||||
unFinishedBoat.setDistanceTravelledInLeg(0);
|
||||
|
||||
unFinishedBoat.setCurrentLeg(FINISH_LEG);
|
||||
|
||||
ArrayList<Leg> legs = new ArrayList<>();
|
||||
legs.add(FINISH_LEG);
|
||||
|
||||
ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[1], legs, null, 1);
|
||||
race.setDnfChance(0);
|
||||
assertEquals(race.boatsFinished, 0);
|
||||
|
||||
race.checkPosition(unFinishedBoat, 100);
|
||||
assertEquals(race.boatsFinished, 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void distanceTravelledBeforeUpdatingLegIsRetained() {
|
||||
|
||||
ArrayList<Leg> legs = new ArrayList<>();
|
||||
|
||||
|
||||
legs.add(START_LEG);
|
||||
legs.add(FINISH_LEG);
|
||||
|
||||
ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[1], legs, null, 1);
|
||||
race.setDnfChance(0);
|
||||
|
||||
BoatInRace unFinishedBoat = new BoatInRace("Test", 10, Color.ALICEBLUE, "tt");
|
||||
unFinishedBoat.setDistanceTravelledInLeg(100);
|
||||
unFinishedBoat.setCurrentLeg(START_LEG);
|
||||
|
||||
race.checkPosition(unFinishedBoat, 100);
|
||||
assertEquals(unFinishedBoat.getCurrentLeg().getName(), "Finish");
|
||||
assertTrue(unFinishedBoat.getDistanceTravelledInLeg() > 0);
|
||||
assertTrue(unFinishedBoat.getDistanceTravelledInLeg() < 100);
|
||||
|
||||
}
|
||||
|
||||
/*@Test
|
||||
|
||||
//Test temporarily removed as countdown timer now uses animation timer
|
||||
|
||||
public void timerDelaysByHalfSecond() {
|
||||
|
||||
ArrayList<Leg> legs = new ArrayList<>();
|
||||
legs.add(START_LEG);
|
||||
|
||||
ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[1], legs, null, 1);
|
||||
race.PRERACE_TIME = 500;
|
||||
|
||||
long timeStarted = System.currentTimeMillis();
|
||||
race.countdownTimer();
|
||||
|
||||
//assertTrue(System.currentTimeMillis() - timeStarted > 500);
|
||||
System.out.println(System.currentTimeMillis() - timeStarted);
|
||||
|
||||
}*/
|
||||
|
||||
@Test
|
||||
public void scalerScalesVelocityCorrectly() {
|
||||
|
||||
int scaleFactor = 3;
|
||||
float vel1 = 0;
|
||||
float vel2 = (float) 1.999;
|
||||
float vel3 = (float) 32.5;
|
||||
float vel4 = 500;
|
||||
BoatInRace boat1 = new BoatInRace("test", vel1, Color.ALICEBLUE, "tt");
|
||||
BoatInRace boat2 = new BoatInRace("test", vel2, Color.ALICEBLUE, "tt");
|
||||
BoatInRace boat3 = new BoatInRace("test", vel3, Color.ALICEBLUE, "tt");
|
||||
BoatInRace boat4 = new BoatInRace("test", vel4, Color.ALICEBLUE, "tt");
|
||||
BoatInRace[] boats = new BoatInRace[]{boat1, boat2, boat3, boat4};
|
||||
|
||||
ArrayList<Leg> legs = new ArrayList<>();
|
||||
legs.add(START_LEG);
|
||||
|
||||
ConstantVelocityRace race = new ConstantVelocityRace(boats, legs, null, scaleFactor);
|
||||
race.setDnfChance(0);
|
||||
|
||||
assertEquals(race.getStartingBoats().get(0).getScaledVelocity(), vel1 * scaleFactor, 1e-6);
|
||||
assertEquals(race.getStartingBoats().get(1).getScaledVelocity(), vel2 * scaleFactor, 1e-6);
|
||||
assertEquals(race.getStartingBoats().get(2).getScaledVelocity(), vel3 * scaleFactor, 1e-6);
|
||||
assertEquals(race.getStartingBoats().get(3).getScaledVelocity(), vel4 * scaleFactor, 1e-6);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void scalerScalesRaceClockTo1MinCorrectly() {
|
||||
int scaleFactor = 10;
|
||||
|
||||
ArrayList<Leg> legs = new ArrayList<>();
|
||||
legs.add(START_LEG);
|
||||
|
||||
ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[5], legs, null, scaleFactor);
|
||||
race.totalTimeElapsed = 6000; //6 seconds
|
||||
assertTrue(race.calcTimer().equals("Race clock: 00:01:00"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void scalerScalesRaceClockHoursMinutesAndSecondsCorrectly() {
|
||||
int scaleFactor = 3;
|
||||
ArrayList<Leg> legs = new ArrayList<>();
|
||||
legs.add(START_LEG);
|
||||
|
||||
ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[5], legs, null, scaleFactor);
|
||||
race.totalTimeElapsed = 3213000;
|
||||
assertTrue(race.calcTimer().equals("Race clock: 02:40:39"));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,7 +86,6 @@ public class RaceXMLTest {
|
||||
assertTrue(raceXMLReader.getLeewardPt2() != null);
|
||||
assertTrue(raceXMLReader.getWindwardPt1() != null);
|
||||
assertTrue(raceXMLReader.getWindwardPt2() != null);
|
||||
assertTrue(raceXMLReader.getMark() != null);
|
||||
assertTrue(raceXMLReader.getBoundary().size() == 11);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
||||
Reference in New Issue
Block a user