Create XML object of boat data.
-XML object currently displaying out in terminal. -Reads in data from RaceDataSource. -TODO: Add sourceID to boats. #story[778]
This commit is contained in:
@@ -4,8 +4,7 @@ package seng302;
|
|||||||
import javafx.application.Application;
|
import javafx.application.Application;
|
||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXException;
|
||||||
import seng302.Model.ConstantVelocityRace;
|
import seng302.Model.Event;
|
||||||
import seng302.Model.Race;
|
|
||||||
|
|
||||||
import javax.xml.parsers.ParserConfigurationException;
|
import javax.xml.parsers.ParserConfigurationException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -25,9 +24,8 @@ public class App extends Application {
|
|||||||
public void start(Stage primaryStage) {
|
public void start(Stage primaryStage) {
|
||||||
try {
|
try {
|
||||||
RaceDataSource raceData = new RaceXMLReader("raceXML/bermuda_AC35.xml");
|
RaceDataSource raceData = new RaceXMLReader("raceXML/bermuda_AC35.xml");
|
||||||
Race newRace = new Race(raceData, 15);
|
Event raceEvent = new Event(raceData);
|
||||||
System.out.println(newRace.getStartingBoats());
|
raceEvent.start();
|
||||||
new Thread((newRace)).start();
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} catch (SAXException e) {
|
} catch (SAXException e) {
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package seng302.Data;
|
||||||
|
|
||||||
|
import seng302.Model.Boat;
|
||||||
|
import seng302.Model.Marker;
|
||||||
|
|
||||||
|
import java.time.OffsetDateTime;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by esa46 on 21/04/17.
|
||||||
|
*/
|
||||||
|
public class RaceData {
|
||||||
|
|
||||||
|
private String raceID;
|
||||||
|
private String raceType;
|
||||||
|
private OffsetDateTime creationTimeDate;
|
||||||
|
private OffsetDateTime raceStartTime;
|
||||||
|
private List<Boat> participants;
|
||||||
|
// private List<Marker>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -29,12 +29,6 @@ public class BoatInRace extends Boat {
|
|||||||
private StringProperty position;
|
private StringProperty position;
|
||||||
private double heading;
|
private double heading;
|
||||||
|
|
||||||
private Queue<TrackPoint> track = new ConcurrentLinkedQueue<>();
|
|
||||||
private long nextValidTime = 0;
|
|
||||||
|
|
||||||
private static final float BASE_TRACK_POINT_TIME_INTERVAL = 5000;
|
|
||||||
private static float trackPointTimeInterval = 5000; // every 1 seconds
|
|
||||||
private final int TRACK_POINT_LIMIT = 10;
|
|
||||||
private boolean trackVisible = true;
|
private boolean trackVisible = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -269,44 +263,4 @@ public class BoatInRace extends Boat {
|
|||||||
this.position.set(position);
|
this.position.set(position);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the boat's sampled track between start of race and current time.
|
|
||||||
* @return queue of track points
|
|
||||||
* @see seng302.Model.TrackPoint
|
|
||||||
*/
|
|
||||||
public Queue<TrackPoint> getTrack() {
|
|
||||||
return track;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns whether track is visible
|
|
||||||
* @return true if visible
|
|
||||||
*/
|
|
||||||
public boolean isTrackVisible() {
|
|
||||||
return trackVisible;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets track visibility.
|
|
||||||
* @param trackVisible visible if true.
|
|
||||||
*/
|
|
||||||
public void setTrackVisible(boolean trackVisible) {
|
|
||||||
this.trackVisible = trackVisible;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get base track point time interval
|
|
||||||
* @return base track point time interval
|
|
||||||
*/
|
|
||||||
public static float getBaseTrackPointTimeInterval() {
|
|
||||||
return BASE_TRACK_POINT_TIME_INTERVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set track point time interval
|
|
||||||
* @param value track point time interval value
|
|
||||||
*/
|
|
||||||
public static void setTrackPointTimeInterval(float value) {
|
|
||||||
trackPointTimeInterval = value;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,23 +0,0 @@
|
|||||||
package seng302.Model;
|
|
||||||
|
|
||||||
import org.geotools.referencing.GeodeticCalculator;
|
|
||||||
import seng302.Constants;
|
|
||||||
import seng302.GPSCoordinate;
|
|
||||||
import seng302.RaceDataSource;
|
|
||||||
|
|
||||||
import java.awt.geom.Point2D;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by cbt24 on 6/03/17.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class ConstantVelocityRace{
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
package seng302.Model;
|
||||||
|
|
||||||
|
import seng302.Data.RaceData;
|
||||||
|
import seng302.Model.Race;
|
||||||
|
import seng302.RaceDataSource;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by esa46 on 21/04/17.
|
||||||
|
*/
|
||||||
|
public class Event {
|
||||||
|
|
||||||
|
RaceDataSource raceData;
|
||||||
|
|
||||||
|
public Event(RaceDataSource raceData) {
|
||||||
|
this.raceData = raceData;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void start() {
|
||||||
|
sendRegattaData();
|
||||||
|
sendRaceData();
|
||||||
|
sendBoatData();
|
||||||
|
|
||||||
|
Race newRace = new Race(raceData, 15);
|
||||||
|
new Thread((newRace)).start();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendRegattaData() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendRaceData() {
|
||||||
|
RaceData raceData = new RaceData();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendBoatData() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -57,10 +57,6 @@ public class Race implements Runnable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Race(BoatInRace[] startingBoats, List<Leg> legs, int scaleFactor) {
|
|
||||||
this(Arrays.asList(startingBoats), legs, scaleFactor);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Race(RaceDataSource raceData, int scaleFactor) {
|
public Race(RaceDataSource raceData, int scaleFactor) {
|
||||||
this(raceData.getBoats(), raceData.getLegs(), scaleFactor);
|
this(raceData.getBoats(), raceData.getLegs(), scaleFactor);
|
||||||
}
|
}
|
||||||
@@ -182,9 +178,7 @@ public class Race implements Runnable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}.start();
|
}.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -204,15 +198,11 @@ public class Race implements Runnable {
|
|||||||
System.out.println("=====");
|
System.out.println("=====");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void initialiseBoats() {
|
public void initialiseBoats() {
|
||||||
Leg officialStart = legs.get(0);
|
Leg officialStart = legs.get(0);
|
||||||
String name = officialStart.getName();
|
String name = officialStart.getName();
|
||||||
Marker endMarker = officialStart.getEndMarker();
|
Marker endMarker = officialStart.getEndMarker();
|
||||||
|
|
||||||
BoatInRace.setTrackPointTimeInterval(BoatInRace.getBaseTrackPointTimeInterval() / scaleFactor);
|
|
||||||
|
|
||||||
ArrayList<Marker> startMarkers = getSpreadStartingPositions();
|
ArrayList<Marker> startMarkers = getSpreadStartingPositions();
|
||||||
for (int i = 0; i < startingBoats.size(); i++) {
|
for (int i = 0; i < startingBoats.size(); i++) {
|
||||||
BoatInRace boat = startingBoats.get(i);
|
BoatInRace boat = startingBoats.get(i);
|
||||||
@@ -354,7 +344,6 @@ public class Race implements Runnable {
|
|||||||
return new GPSCoordinate(endPoint.getY(), endPoint.getX());
|
return new GPSCoordinate(endPoint.getY(), endPoint.getX());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the boats that have started the race.
|
* Returns the boats that have started the race.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1,50 +0,0 @@
|
|||||||
package seng302.Model;
|
|
||||||
|
|
||||||
import seng302.GPSCoordinate;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by cbt24 on 7/04/17.
|
|
||||||
*/
|
|
||||||
public class TrackPoint {
|
|
||||||
private GPSCoordinate coordinate;
|
|
||||||
private long timeAdded;
|
|
||||||
private long expiry;
|
|
||||||
private double minAlpha;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new track point with fixed GPS coordinates and time, to reach minimum opacity on expiry.
|
|
||||||
* @param coordinate position of point on physical race map
|
|
||||||
* @param timeAdded system clock at time of addition
|
|
||||||
* @param expiry time to minimum opacity after added
|
|
||||||
*/
|
|
||||||
public TrackPoint(GPSCoordinate coordinate, long timeAdded, long expiry) {
|
|
||||||
this.coordinate = coordinate;
|
|
||||||
this.timeAdded = timeAdded;
|
|
||||||
this.expiry = expiry;
|
|
||||||
this.minAlpha = 0.1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the position of the point on physical race map.
|
|
||||||
* @return GPS coordinate of point
|
|
||||||
*/
|
|
||||||
public GPSCoordinate getCoordinate() {
|
|
||||||
return coordinate;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets opacity of point scaled by age in proportion to expiry, between 1 and minimum opacity inclusive.
|
|
||||||
* @return greater of minimum opacity and scaled opacity
|
|
||||||
*/
|
|
||||||
public double getAlpha() {
|
|
||||||
return Double.max(minAlpha,1.0 - (double)(System.currentTimeMillis() - timeAdded) / expiry);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets time point was added to track.
|
|
||||||
* @return system clock at time of addition
|
|
||||||
*/
|
|
||||||
public long getTimeAdded() {
|
|
||||||
return timeAdded;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -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 {
|
|
||||||
/*
|
|
||||||
Marker START_MARKER = new Marker(new GPSCoordinate(0, 0));
|
|
||||||
Marker END_MARKER = new Marker(new GPSCoordinate(10, 10));
|
|
||||||
Leg START_LEG = new Leg("Start", START_MARKER, END_MARKER, 0);
|
|
||||||
|
|
||||||
int ONE_HOUR = 3600000; //1 hour in milliseconds
|
|
||||||
|
|
||||||
|
|
||||||
private ArrayList<Leg> generateLegsArray() {
|
|
||||||
ArrayList<Leg> legs = new ArrayList<>();
|
|
||||||
legs.add(START_LEG);
|
|
||||||
return legs;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void updatePositionChangesDistanceTravelled() {
|
|
||||||
ArrayList<Leg> legs = generateLegsArray();
|
|
||||||
BoatInRace boat = new BoatInRace("Test", 1, Color.ALICEBLUE, "tt");
|
|
||||||
boat.setCurrentLeg(legs.get(0));
|
|
||||||
boat.setDistanceTravelledInLeg(0);
|
|
||||||
BoatInRace[] boats = new BoatInRace[]{boat};
|
|
||||||
|
|
||||||
ConstantVelocityRace race = new ConstantVelocityRace(boats, legs, null, 1);
|
|
||||||
|
|
||||||
race.updatePosition(boat, ONE_HOUR);
|
|
||||||
assertEquals(boat.getDistanceTravelledInLeg(), boat.getVelocity(), 1e-8);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void updatePositionHandlesNoChangeToDistanceTravelled() {
|
|
||||||
|
|
||||||
ArrayList<Leg> legs = generateLegsArray();
|
|
||||||
BoatInRace boat = new BoatInRace("Test", 0, Color.ALICEBLUE, "tt");
|
|
||||||
boat.setCurrentLeg(legs.get(0));
|
|
||||||
boat.setDistanceTravelledInLeg(0);
|
|
||||||
BoatInRace[] boats = new BoatInRace[]{boat};
|
|
||||||
|
|
||||||
ConstantVelocityRace race = new ConstantVelocityRace(boats, legs, null, 1);
|
|
||||||
|
|
||||||
race.updatePosition(boat, ONE_HOUR);
|
|
||||||
assertEquals(boat.getDistanceTravelledInLeg(), 0, 1e-8);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void changesToDistanceTravelledAreAdditive() {
|
|
||||||
|
|
||||||
ArrayList<Leg> legs = generateLegsArray();
|
|
||||||
BoatInRace boat = new BoatInRace("Test", 5, Color.ALICEBLUE, "tt");
|
|
||||||
boat.setCurrentLeg(legs.get(0));
|
|
||||||
boat.setDistanceTravelledInLeg(50);
|
|
||||||
BoatInRace[] boats = new BoatInRace[]{boat};
|
|
||||||
|
|
||||||
ConstantVelocityRace race = new ConstantVelocityRace(boats, legs, null, 1);
|
|
||||||
|
|
||||||
race.updatePosition(boat, ONE_HOUR);
|
|
||||||
assertEquals(boat.getDistanceTravelledInLeg(), boat.getVelocity() + 50, 1e-8);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void travelling10nmNorthGivesCorrectNewCoordinates() {
|
|
||||||
GPSCoordinate oldPos = new GPSCoordinate(0, 0);
|
|
||||||
GPSCoordinate newPos = ConstantVelocityRace.calculatePosition(oldPos, 10, 0);
|
|
||||||
|
|
||||||
GeodeticCalculator calc = new GeodeticCalculator();
|
|
||||||
calc.setStartingGeographicPoint(0, 0);
|
|
||||||
calc.setDirection(0, 10 * Constants.NMToMetersConversion);
|
|
||||||
|
|
||||||
assertEquals(newPos.getLongitude(), 0, 1e-8);
|
|
||||||
assertEquals(newPos.getLatitude(), calc.getDestinationGeographicPoint().getY(), 1e-8);
|
|
||||||
assertEquals(newPos.getLongitude(), calc.getDestinationGeographicPoint().getX(), 1e-8);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void travelling10nmEastGivesCorrectNewCoordinates() {
|
|
||||||
GPSCoordinate oldPos = new GPSCoordinate(0, 0);
|
|
||||||
GPSCoordinate newPos = ConstantVelocityRace.calculatePosition(oldPos, 10, 90);
|
|
||||||
|
|
||||||
GeodeticCalculator calc = new GeodeticCalculator();
|
|
||||||
calc.setStartingGeographicPoint(0, 0);
|
|
||||||
calc.setDirection(90, 10 * Constants.NMToMetersConversion);
|
|
||||||
|
|
||||||
|
|
||||||
assertEquals(newPos.getLatitude(), 0, 1e-8);
|
|
||||||
assertEquals(newPos.getLatitude(), calc.getDestinationGeographicPoint().getY(), 1e-8);
|
|
||||||
assertEquals(newPos.getLongitude(), calc.getDestinationGeographicPoint().getX(), 1e-8);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void travelling10nmWestGivesCorrectNewCoordinates() {
|
|
||||||
GPSCoordinate oldPos = new GPSCoordinate(0, 0);
|
|
||||||
GPSCoordinate newPos = ConstantVelocityRace.calculatePosition(oldPos, 10, -90);
|
|
||||||
|
|
||||||
GeodeticCalculator calc = new GeodeticCalculator();
|
|
||||||
calc.setStartingGeographicPoint(0, 0);
|
|
||||||
calc.setDirection(-90, 10 * Constants.NMToMetersConversion);
|
|
||||||
|
|
||||||
|
|
||||||
assertEquals(newPos.getLatitude(), 0, 1e-8);
|
|
||||||
assertEquals(newPos.getLatitude(), calc.getDestinationGeographicPoint().getY(), 1e-8);
|
|
||||||
assertEquals(newPos.getLongitude(), calc.getDestinationGeographicPoint().getX(), 1e-8);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void travelling10nmSouthGivesCorrectNewCoordinates() {
|
|
||||||
GPSCoordinate oldPos = new GPSCoordinate(0, 0);
|
|
||||||
GPSCoordinate newPos = ConstantVelocityRace.calculatePosition(oldPos, 10, 180);
|
|
||||||
|
|
||||||
GeodeticCalculator calc = new GeodeticCalculator();
|
|
||||||
calc.setStartingGeographicPoint(0, 0);
|
|
||||||
calc.setDirection(180, 10 * Constants.NMToMetersConversion);
|
|
||||||
|
|
||||||
|
|
||||||
assertEquals(newPos.getLongitude(), 0, 1e-8);
|
|
||||||
assertEquals(newPos.getLatitude(), calc.getDestinationGeographicPoint().getY(), 1e-8);
|
|
||||||
assertEquals(newPos.getLongitude(), calc.getDestinationGeographicPoint().getX(), 1e-8);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -15,160 +15,159 @@ import static org.junit.Assert.assertTrue;
|
|||||||
* Created by esa46 on 15/03/17.
|
* Created by esa46 on 15/03/17.
|
||||||
*/
|
*/
|
||||||
public class RaceTest {
|
public class RaceTest {
|
||||||
/*
|
|
||||||
Leg START_LEG = new Leg("Start", new Marker(new GPSCoordinate(0, 0)), new Marker(new GPSCoordinate(1, 1)), 0);
|
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);
|
Leg FINISH_LEG = new Leg("Finish", new Marker(new GPSCoordinate(1, 1)), new Marker(new GPSCoordinate(2, 2)), 0);
|
||||||
|
//
|
||||||
@Ignore
|
// @Ignore
|
||||||
@Test
|
// @Test
|
||||||
public void timerCanBeDisabled() {
|
// public void timerCanBeDisabled() {
|
||||||
BoatInRace boat1 = new BoatInRace("Test 1", 10000, Color.ALICEBLUE, "t1");
|
// BoatInRace boat1 = new BoatInRace("Test 1", 10000, Color.ALICEBLUE, "t1");
|
||||||
BoatInRace boat2 = new BoatInRace("Test 2", 10000, Color.BURLYWOOD, "t2");
|
// BoatInRace boat2 = new BoatInRace("Test 2", 10000, Color.BURLYWOOD, "t2");
|
||||||
BoatInRace[] boats = new BoatInRace[]{boat1, boat2};
|
// BoatInRace[] boats = new BoatInRace[]{boat1, boat2};
|
||||||
|
//
|
||||||
ArrayList<Leg> legs = new ArrayList<>();
|
// ArrayList<Leg> legs = new ArrayList<>();
|
||||||
legs.add(START_LEG); legs.add(FINISH_LEG);
|
// legs.add(START_LEG); legs.add(FINISH_LEG);
|
||||||
|
//
|
||||||
ConstantVelocityRace race = new ConstantVelocityRace(boats, legs, null, 5);
|
// ConstantVelocityRace race = new ConstantVelocityRace(boats, legs, null, 5);
|
||||||
race.disableTimer();
|
// race.disableTimer();
|
||||||
race.setDnfChance(0);
|
// race.setDnfChance(0);
|
||||||
long timeStarted = System.currentTimeMillis();
|
// long timeStarted = System.currentTimeMillis();
|
||||||
race.run();
|
// race.run();
|
||||||
|
//
|
||||||
assertTrue(System.currentTimeMillis() - timeStarted < 4000);
|
// assertTrue(System.currentTimeMillis() - timeStarted < 4000);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@Test
|
// @Test
|
||||||
public void checkPositionUpdatesNumberFinishedBoats() {
|
// public void checkPositionUpdatesNumberFinishedBoats() {
|
||||||
|
//
|
||||||
BoatInRace finishedBoat = new BoatInRace("Test", 1000, Color.ALICEBLUE, "tt");
|
// BoatInRace finishedBoat = new BoatInRace("Test", 1000, Color.ALICEBLUE, "tt");
|
||||||
finishedBoat.setDistanceTravelledInLeg(500);
|
// finishedBoat.setDistanceTravelledInLeg(500);
|
||||||
|
//
|
||||||
finishedBoat.setCurrentLeg(FINISH_LEG);
|
// finishedBoat.setCurrentLeg(FINISH_LEG);
|
||||||
|
//
|
||||||
ArrayList<Leg> legs = new ArrayList<>();
|
// ArrayList<Leg> legs = new ArrayList<>();
|
||||||
legs.add(FINISH_LEG);
|
// legs.add(FINISH_LEG);
|
||||||
|
//
|
||||||
ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[1], legs, null, 1);
|
// ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[1], legs, null, 1);
|
||||||
race.setDnfChance(0);
|
// race.setDnfChance(0);
|
||||||
assertEquals(race.boatsFinished, 0);
|
// assertEquals(race.boatsFinished, 0);
|
||||||
|
//
|
||||||
|
//
|
||||||
race.checkPosition(finishedBoat, 100000);
|
// race.checkPosition(finishedBoat, 100000);
|
||||||
assertEquals(race.boatsFinished, 1);
|
// assertEquals(race.boatsFinished, 1);
|
||||||
assertEquals(finishedBoat.getTimeFinished(), 100000);
|
// assertEquals(finishedBoat.getTimeFinished(), 100000);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@Test
|
// @Test
|
||||||
public void checkPositionDoesntUpdateNumberFinishedBoats() {
|
// public void checkPositionDoesntUpdateNumberFinishedBoats() {
|
||||||
|
//
|
||||||
BoatInRace unFinishedBoat = new BoatInRace("Test", 10, Color.ALICEBLUE, "tt");
|
// BoatInRace unFinishedBoat = new BoatInRace("Test", 10, Color.ALICEBLUE, "tt");
|
||||||
unFinishedBoat.setDistanceTravelledInLeg(0);
|
// unFinishedBoat.setDistanceTravelledInLeg(0);
|
||||||
|
//
|
||||||
unFinishedBoat.setCurrentLeg(FINISH_LEG);
|
// unFinishedBoat.setCurrentLeg(FINISH_LEG);
|
||||||
|
//
|
||||||
ArrayList<Leg> legs = new ArrayList<>();
|
// ArrayList<Leg> legs = new ArrayList<>();
|
||||||
legs.add(FINISH_LEG);
|
// legs.add(FINISH_LEG);
|
||||||
|
//
|
||||||
ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[1], legs, null, 1);
|
// ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[1], legs, null, 1);
|
||||||
race.setDnfChance(0);
|
// race.setDnfChance(0);
|
||||||
assertEquals(race.boatsFinished, 0);
|
// assertEquals(race.boatsFinished, 0);
|
||||||
|
//
|
||||||
race.checkPosition(unFinishedBoat, 100);
|
// race.checkPosition(unFinishedBoat, 100);
|
||||||
assertEquals(race.boatsFinished, 0);
|
// assertEquals(race.boatsFinished, 0);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@Test
|
// @Test
|
||||||
public void distanceTravelledBeforeUpdatingLegIsRetained() {
|
// public void distanceTravelledBeforeUpdatingLegIsRetained() {
|
||||||
|
//
|
||||||
ArrayList<Leg> legs = new ArrayList<>();
|
// ArrayList<Leg> legs = new ArrayList<>();
|
||||||
|
//
|
||||||
|
//
|
||||||
legs.add(START_LEG);
|
// legs.add(START_LEG);
|
||||||
legs.add(FINISH_LEG);
|
// legs.add(FINISH_LEG);
|
||||||
|
//
|
||||||
ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[1], legs, null, 1);
|
// ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[1], legs, null, 1);
|
||||||
race.setDnfChance(0);
|
// race.setDnfChance(0);
|
||||||
|
//
|
||||||
BoatInRace unFinishedBoat = new BoatInRace("Test", 10, Color.ALICEBLUE, "tt");
|
// BoatInRace unFinishedBoat = new BoatInRace("Test", 10, Color.ALICEBLUE, "tt");
|
||||||
unFinishedBoat.setDistanceTravelledInLeg(100);
|
// unFinishedBoat.setDistanceTravelledInLeg(100);
|
||||||
unFinishedBoat.setCurrentLeg(START_LEG);
|
// unFinishedBoat.setCurrentLeg(START_LEG);
|
||||||
|
//
|
||||||
race.checkPosition(unFinishedBoat, 100);
|
// race.checkPosition(unFinishedBoat, 100);
|
||||||
assertEquals(unFinishedBoat.getCurrentLeg().getName(), "Finish");
|
// assertEquals(unFinishedBoat.getCurrentLeg().getName(), "Finish");
|
||||||
assertTrue(unFinishedBoat.getDistanceTravelledInLeg() > 0);
|
// assertTrue(unFinishedBoat.getDistanceTravelledInLeg() > 0);
|
||||||
assertTrue(unFinishedBoat.getDistanceTravelledInLeg() < 100);
|
// assertTrue(unFinishedBoat.getDistanceTravelledInLeg() < 100);
|
||||||
|
//
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
/*@Test
|
// /*@Test
|
||||||
|
//
|
||||||
//Test temporarily removed as countdown timer now uses animation timer
|
// //Test temporarily removed as countdown timer now uses animation timer
|
||||||
|
//
|
||||||
public void timerDelaysByHalfSecond() {
|
// public void timerDelaysByHalfSecond() {
|
||||||
|
//
|
||||||
ArrayList<Leg> legs = new ArrayList<>();
|
// ArrayList<Leg> legs = new ArrayList<>();
|
||||||
legs.add(START_LEG);
|
// legs.add(START_LEG);
|
||||||
|
//
|
||||||
ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[1], legs, null, 1);
|
// ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[1], legs, null, 1);
|
||||||
race.PRERACE_TIME = 500;
|
// race.PRERACE_TIME = 500;
|
||||||
|
//
|
||||||
long timeStarted = System.currentTimeMillis();
|
// long timeStarted = System.currentTimeMillis();
|
||||||
race.countdownTimer();
|
// race.countdownTimer();
|
||||||
|
//
|
||||||
//assertTrue(System.currentTimeMillis() - timeStarted > 500);
|
// //assertTrue(System.currentTimeMillis() - timeStarted > 500);
|
||||||
System.out.println(System.currentTimeMillis() - timeStarted);
|
// System.out.println(System.currentTimeMillis() - timeStarted);
|
||||||
|
//
|
||||||
}
|
// }*/
|
||||||
|
//
|
||||||
@Test
|
// @Test
|
||||||
public void scalerScalesVelocityCorrectly() {
|
// public void scalerScalesVelocityCorrectly() {
|
||||||
|
//
|
||||||
int scaleFactor = 3;
|
// int scaleFactor = 3;
|
||||||
float vel1 = 0;
|
// float vel1 = 0;
|
||||||
float vel2 = (float) 1.999;
|
// float vel2 = (float) 1.999;
|
||||||
float vel3 = (float) 32.5;
|
// float vel3 = (float) 32.5;
|
||||||
float vel4 = 500;
|
// float vel4 = 500;
|
||||||
BoatInRace boat1 = new BoatInRace("test", vel1, Color.ALICEBLUE, "tt");
|
// BoatInRace boat1 = new BoatInRace("test", vel1, Color.ALICEBLUE, "tt");
|
||||||
BoatInRace boat2 = new BoatInRace("test", vel2, Color.ALICEBLUE, "tt");
|
// BoatInRace boat2 = new BoatInRace("test", vel2, Color.ALICEBLUE, "tt");
|
||||||
BoatInRace boat3 = new BoatInRace("test", vel3, Color.ALICEBLUE, "tt");
|
// BoatInRace boat3 = new BoatInRace("test", vel3, Color.ALICEBLUE, "tt");
|
||||||
BoatInRace boat4 = new BoatInRace("test", vel4, Color.ALICEBLUE, "tt");
|
// BoatInRace boat4 = new BoatInRace("test", vel4, Color.ALICEBLUE, "tt");
|
||||||
BoatInRace[] boats = new BoatInRace[]{boat1, boat2, boat3, boat4};
|
// BoatInRace[] boats = new BoatInRace[]{boat1, boat2, boat3, boat4};
|
||||||
|
//
|
||||||
ArrayList<Leg> legs = new ArrayList<>();
|
// ArrayList<Leg> legs = new ArrayList<>();
|
||||||
legs.add(START_LEG);
|
// legs.add(START_LEG);
|
||||||
|
//
|
||||||
ConstantVelocityRace race = new ConstantVelocityRace(boats, legs, null, scaleFactor);
|
// ConstantVelocityRace race = new ConstantVelocityRace(boats, legs, null, scaleFactor);
|
||||||
race.setDnfChance(0);
|
// race.setDnfChance(0);
|
||||||
|
//
|
||||||
assertEquals(race.getStartingBoats().get(0).getScaledVelocity(), vel1 * scaleFactor, 1e-6);
|
// assertEquals(race.getStartingBoats().get(0).getScaledVelocity(), vel1 * scaleFactor, 1e-6);
|
||||||
assertEquals(race.getStartingBoats().get(1).getScaledVelocity(), vel2 * 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(2).getScaledVelocity(), vel3 * scaleFactor, 1e-6);
|
||||||
assertEquals(race.getStartingBoats().get(3).getScaledVelocity(), vel4 * scaleFactor, 1e-6);
|
// assertEquals(race.getStartingBoats().get(3).getScaledVelocity(), vel4 * scaleFactor, 1e-6);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@Test
|
// @Test
|
||||||
public void scalerScalesRaceClockTo1MinCorrectly() {
|
// public void scalerScalesRaceClockTo1MinCorrectly() {
|
||||||
int scaleFactor = 10;
|
// int scaleFactor = 10;
|
||||||
|
//
|
||||||
ArrayList<Leg> legs = new ArrayList<>();
|
// ArrayList<Leg> legs = new ArrayList<>();
|
||||||
legs.add(START_LEG);
|
// legs.add(START_LEG);
|
||||||
|
//
|
||||||
ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[5], legs, null, scaleFactor);
|
// ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[5], legs, null, scaleFactor);
|
||||||
race.totalTimeElapsed = 6000; //6 seconds
|
// race.totalTimeElapsed = 6000; //6 seconds
|
||||||
assertTrue(race.calcTimer().equals("Race clock: 00:01:00"));
|
// assertTrue(race.calcTimer().equals("Race clock: 00:01:00"));
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@Test
|
// @Test
|
||||||
public void scalerScalesRaceClockHoursMinutesAndSecondsCorrectly() {
|
// public void scalerScalesRaceClockHoursMinutesAndSecondsCorrectly() {
|
||||||
int scaleFactor = 3;
|
// int scaleFactor = 3;
|
||||||
ArrayList<Leg> legs = new ArrayList<>();
|
// ArrayList<Leg> legs = new ArrayList<>();
|
||||||
legs.add(START_LEG);
|
// legs.add(START_LEG);
|
||||||
|
//
|
||||||
ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[5], legs, null, scaleFactor);
|
// ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[5], legs, null, scaleFactor);
|
||||||
race.totalTimeElapsed = 3213000;
|
// race.totalTimeElapsed = 3213000;
|
||||||
assertTrue(race.calcTimer().equals("Race clock: 02:40:39"));
|
// assertTrue(race.calcTimer().equals("Race clock: 02:40:39"));
|
||||||
|
//
|
||||||
}
|
// }
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user