Adding end coords to get test running gain
#story[20]
This commit is contained in:
@@ -30,6 +30,8 @@ public class Leg {
|
|||||||
this.startGPSCoordinate = start;
|
this.startGPSCoordinate = start;
|
||||||
this.endGPSCoordinate = end;
|
this.endGPSCoordinate = end;
|
||||||
this.legNumber = number;
|
this.legNumber = number;
|
||||||
|
calculateStart();
|
||||||
|
calculateEnd();
|
||||||
this.distance = calculateDistance();
|
this.distance = calculateDistance();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -153,12 +155,18 @@ public class Leg {
|
|||||||
|
|
||||||
private void calculateStart() {
|
private void calculateStart() {
|
||||||
//TO DO: Make this function set the start node as halfway between the two markers
|
//TO DO: Make this function set the start node as halfway between the two markers
|
||||||
|
if (startMarker1 != null) {
|
||||||
this.startGPSCoordinate = startMarker1;
|
this.startGPSCoordinate = startMarker1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private void calculateEnd() {
|
private void calculateEnd() {
|
||||||
//TO DO: Make this function set the end node as halfway between the two markers
|
//TO DO: Make this function set the end node as halfway between the two markers
|
||||||
|
if (endMarker1 != null) {
|
||||||
this.endGPSCoordinate = endMarker1;
|
this.endGPSCoordinate = endMarker1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ public abstract class Race implements Runnable {
|
|||||||
protected int boatsFinished = 0;
|
protected int boatsFinished = 0;
|
||||||
protected long totalTimeElapsed;
|
protected long totalTimeElapsed;
|
||||||
|
|
||||||
|
|
||||||
protected int scaleFactor;
|
protected int scaleFactor;
|
||||||
|
|
||||||
private int SLEEP_TIME = 100; //time in milliseconds to pause in a paced loop
|
private int SLEEP_TIME = 100; //time in milliseconds to pause in a paced loop
|
||||||
@@ -70,6 +71,7 @@ public abstract class Race implements Runnable {
|
|||||||
|
|
||||||
protected void initialiseBoats() {
|
protected void initialiseBoats() {
|
||||||
System.out.println("boat initialisation");
|
System.out.println("boat initialisation");
|
||||||
|
|
||||||
Leg startLeg = legs.get(0);
|
Leg startLeg = legs.get(0);
|
||||||
Leg copyLeg = startLeg.createCopy();
|
Leg copyLeg = startLeg.createCopy();
|
||||||
ArrayList<GPSCoordinate> startPositions = getSpreadStartingPositions();
|
ArrayList<GPSCoordinate> startPositions = getSpreadStartingPositions();
|
||||||
|
|||||||
@@ -16,7 +16,9 @@ import static org.junit.Assert.assertEquals;
|
|||||||
*/
|
*/
|
||||||
public class ConstantVelocityRaceTest {
|
public class ConstantVelocityRaceTest {
|
||||||
|
|
||||||
Leg START_LEG = new Leg("Start", new GPSCoordinate(0, 0), new GPSCoordinate(50, 50), 0);
|
Leg START_LEG = new Leg("Start", new GPSCoordinate(0, 0), new GPSCoordinate(1, 1),
|
||||||
|
new GPSCoordinate(50, 50), new GPSCoordinate(51, 51), 0);
|
||||||
|
|
||||||
int ONE_HOUR = 3600000; //1 hour in milliseconds
|
int ONE_HOUR = 3600000; //1 hour in milliseconds
|
||||||
|
|
||||||
|
|
||||||
@@ -28,7 +30,10 @@ public class ConstantVelocityRaceTest {
|
|||||||
boat.setDistanceTravelledInLeg(0);
|
boat.setDistanceTravelledInLeg(0);
|
||||||
BoatInRace[] boats = new BoatInRace[]{boat};
|
BoatInRace[] boats = new BoatInRace[]{boat};
|
||||||
|
|
||||||
ConstantVelocityRace race = new ConstantVelocityRace(boats, new ArrayList<Leg>(), null, 1);
|
ArrayList<Leg> legs = new ArrayList<>();
|
||||||
|
legs.add(START_LEG);
|
||||||
|
|
||||||
|
ConstantVelocityRace race = new ConstantVelocityRace(boats, legs, null, 1);
|
||||||
|
|
||||||
race.updatePosition(boat, ONE_HOUR);
|
race.updatePosition(boat, ONE_HOUR);
|
||||||
assertEquals(boat.getDistanceTravelledInLeg(), boat.getVelocity(), 1e-8);
|
assertEquals(boat.getDistanceTravelledInLeg(), boat.getVelocity(), 1e-8);
|
||||||
@@ -42,7 +47,10 @@ public class ConstantVelocityRaceTest {
|
|||||||
boat.setDistanceTravelledInLeg(0);
|
boat.setDistanceTravelledInLeg(0);
|
||||||
BoatInRace[] boats = new BoatInRace[]{boat};
|
BoatInRace[] boats = new BoatInRace[]{boat};
|
||||||
|
|
||||||
ConstantVelocityRace race = new ConstantVelocityRace(boats, new ArrayList<Leg>(), null, 1);
|
ArrayList<Leg> legs = new ArrayList<>();
|
||||||
|
legs.add(START_LEG);
|
||||||
|
|
||||||
|
ConstantVelocityRace race = new ConstantVelocityRace(boats, legs, null, 1);
|
||||||
|
|
||||||
race.updatePosition(boat, ONE_HOUR);
|
race.updatePosition(boat, ONE_HOUR);
|
||||||
assertEquals(boat.getDistanceTravelledInLeg(), 0, 1e-8);
|
assertEquals(boat.getDistanceTravelledInLeg(), 0, 1e-8);
|
||||||
@@ -54,8 +62,10 @@ public class ConstantVelocityRaceTest {
|
|||||||
boat.setCurrentLeg(START_LEG);
|
boat.setCurrentLeg(START_LEG);
|
||||||
boat.setDistanceTravelledInLeg(50);
|
boat.setDistanceTravelledInLeg(50);
|
||||||
BoatInRace[] boats = new BoatInRace[]{boat};
|
BoatInRace[] boats = new BoatInRace[]{boat};
|
||||||
|
ArrayList<Leg> legs = new ArrayList<>();
|
||||||
|
legs.add(START_LEG);
|
||||||
|
|
||||||
ConstantVelocityRace race = new ConstantVelocityRace(boats, new ArrayList<Leg>(), null, 1);
|
ConstantVelocityRace race = new ConstantVelocityRace(boats, legs, null, 1);
|
||||||
|
|
||||||
race.updatePosition(boat, ONE_HOUR);
|
race.updatePosition(boat, ONE_HOUR);
|
||||||
assertEquals(boat.getDistanceTravelledInLeg(), boat.getVelocity() + 50, 1e-8);
|
assertEquals(boat.getDistanceTravelledInLeg(), boat.getVelocity() + 50, 1e-8);
|
||||||
|
|||||||
@@ -16,6 +16,9 @@ import static org.junit.Assert.assertTrue;
|
|||||||
public class RaceTest {
|
public class RaceTest {
|
||||||
|
|
||||||
|
|
||||||
|
Leg START_LEG = new Leg("Start", new GPSCoordinate(0, 0), new GPSCoordinate(1, 1),
|
||||||
|
new GPSCoordinate(50, 50), new GPSCoordinate(51, 51), 0);
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void finishOrderDeterminedByVelocity() {
|
public void finishOrderDeterminedByVelocity() {
|
||||||
BoatInRace[] boats = {
|
BoatInRace[] boats = {
|
||||||
@@ -23,7 +26,9 @@ public class RaceTest {
|
|||||||
new BoatInRace("AU", 2800, Color.BEIGE, "AU")
|
new BoatInRace("AU", 2800, Color.BEIGE, "AU")
|
||||||
};
|
};
|
||||||
ArrayList<Leg> legs = new ArrayList<>();
|
ArrayList<Leg> legs = new ArrayList<>();
|
||||||
legs.add(new Leg("Start", new GPSCoordinate(32.296577, -64.854304), new GPSCoordinate(32.293039, -64.843983), 0));
|
GPSCoordinate startCoord = new GPSCoordinate(32.296577, -64.854304);
|
||||||
|
GPSCoordinate endCoord = new GPSCoordinate(32.293039, -64.843983);
|
||||||
|
legs.add(new Leg("Start", startCoord, startCoord, endCoord, endCoord, 0));
|
||||||
legs.add(new Leg("Start", new GPSCoordinate(32.293039, -64.843983), new GPSCoordinate(32.284680, -64.850045), 1));
|
legs.add(new Leg("Start", new GPSCoordinate(32.293039, -64.843983), new GPSCoordinate(32.284680, -64.850045), 1));
|
||||||
Race race = new ConstantVelocityRace(boats, legs, null, 1);
|
Race race = new ConstantVelocityRace(boats, legs, null, 1);
|
||||||
race.disableTimer();
|
race.disableTimer();
|
||||||
@@ -42,10 +47,14 @@ public class RaceTest {
|
|||||||
|
|
||||||
BoatInRace finishedBoat = new BoatInRace("Test", 1000, Color.ALICEBLUE, "tt");
|
BoatInRace finishedBoat = new BoatInRace("Test", 1000, Color.ALICEBLUE, "tt");
|
||||||
finishedBoat.setDistanceTravelledInLeg(500);
|
finishedBoat.setDistanceTravelledInLeg(500);
|
||||||
Leg leg = new Leg("Finish", new GPSCoordinate(0, 0), new GPSCoordinate(1, 1), 0);
|
Leg leg = new Leg("Finish", new GPSCoordinate(0, 0), new GPSCoordinate(0.5, 0.5),
|
||||||
|
new GPSCoordinate(1, 1), new GPSCoordinate(1.5, 1.5), 0);
|
||||||
finishedBoat.setCurrentLeg(leg);
|
finishedBoat.setCurrentLeg(leg);
|
||||||
|
|
||||||
ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[1], new ArrayList<Leg>(), null, 1);
|
ArrayList<Leg> legs = new ArrayList<>();
|
||||||
|
legs.add(leg);
|
||||||
|
|
||||||
|
ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[1], legs, null, 1);
|
||||||
assertEquals(race.boatsFinished, 0);
|
assertEquals(race.boatsFinished, 0);
|
||||||
|
|
||||||
race.checkPosition(finishedBoat, 100);
|
race.checkPosition(finishedBoat, 100);
|
||||||
@@ -58,10 +67,14 @@ public class RaceTest {
|
|||||||
|
|
||||||
BoatInRace unFinishedBoat = new BoatInRace("Test", 10, Color.ALICEBLUE, "tt");
|
BoatInRace unFinishedBoat = new BoatInRace("Test", 10, Color.ALICEBLUE, "tt");
|
||||||
unFinishedBoat.setDistanceTravelledInLeg(0);
|
unFinishedBoat.setDistanceTravelledInLeg(0);
|
||||||
Leg leg = new Leg("Finish", new GPSCoordinate(0, 0), new GPSCoordinate(1, 1), 0);
|
Leg leg = new Leg("Finish", new GPSCoordinate(0, 0), new GPSCoordinate(0.1, 0.1),
|
||||||
|
new GPSCoordinate(1, 1), new GPSCoordinate(1.1, 1.1), 0);
|
||||||
unFinishedBoat.setCurrentLeg(leg);
|
unFinishedBoat.setCurrentLeg(leg);
|
||||||
|
|
||||||
ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[1], new ArrayList<Leg>(), null, 1);
|
ArrayList<Leg> legs = new ArrayList<>();
|
||||||
|
legs.add(leg);
|
||||||
|
|
||||||
|
ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[1], legs, null, 1);
|
||||||
assertEquals(race.boatsFinished, 0);
|
assertEquals(race.boatsFinished, 0);
|
||||||
|
|
||||||
race.checkPosition(unFinishedBoat, 100);
|
race.checkPosition(unFinishedBoat, 100);
|
||||||
@@ -74,10 +87,12 @@ public class RaceTest {
|
|||||||
|
|
||||||
ArrayList<Leg> legs = new ArrayList<>();
|
ArrayList<Leg> legs = new ArrayList<>();
|
||||||
|
|
||||||
Leg leg1 = new Leg("1", new GPSCoordinate(0, 0), new GPSCoordinate(1, 1), 0);
|
Leg leg1 = new Leg("1", new GPSCoordinate(0, 0), new GPSCoordinate(0.5, 0.5),
|
||||||
Leg leg2 = new Leg("2", new GPSCoordinate(0, 0), new GPSCoordinate(1, 1), 1);
|
new GPSCoordinate(1, 1), new GPSCoordinate(1.5, 1.5), 0);
|
||||||
|
Leg leg2 = new Leg("2", new GPSCoordinate(0, 0), new GPSCoordinate(0.5, 0.5),
|
||||||
|
new GPSCoordinate(1, 1), new GPSCoordinate(1.5, 1.5), 1);
|
||||||
|
|
||||||
legs.add(leg2);
|
legs.add(leg1);
|
||||||
legs.add(leg2);
|
legs.add(leg2);
|
||||||
|
|
||||||
ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[1], legs, null, 1);
|
ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[1], legs, null, 1);
|
||||||
@@ -95,7 +110,11 @@ public class RaceTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void timerDelaysByHalfSecond() {
|
public void timerDelaysByHalfSecond() {
|
||||||
ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[1], new ArrayList<>(), null, 1);
|
|
||||||
|
ArrayList<Leg> legs = new ArrayList<>();
|
||||||
|
legs.add(START_LEG);
|
||||||
|
|
||||||
|
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();
|
||||||
@@ -119,7 +138,10 @@ public class RaceTest {
|
|||||||
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};
|
||||||
|
|
||||||
ConstantVelocityRace race = new ConstantVelocityRace(boats, new ArrayList<Leg>(), null, scaleFactor);
|
ArrayList<Leg> legs = new ArrayList<>();
|
||||||
|
legs.add(START_LEG);
|
||||||
|
|
||||||
|
ConstantVelocityRace race = new ConstantVelocityRace(boats, legs, null, scaleFactor);
|
||||||
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);
|
||||||
@@ -129,7 +151,11 @@ public class RaceTest {
|
|||||||
@Test
|
@Test
|
||||||
public void scalerScalesRaceClockTo1MinCorrectly() {
|
public void scalerScalesRaceClockTo1MinCorrectly() {
|
||||||
int scaleFactor = 10;
|
int scaleFactor = 10;
|
||||||
ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[5], new ArrayList<Leg>(), null, scaleFactor);
|
|
||||||
|
ArrayList<Leg> legs = new ArrayList<>();
|
||||||
|
legs.add(START_LEG);
|
||||||
|
|
||||||
|
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"));
|
||||||
}
|
}
|
||||||
@@ -137,7 +163,10 @@ public class RaceTest {
|
|||||||
@Test
|
@Test
|
||||||
public void scalerScalesRaceClockHoursMinutesAndSecondsCorrectly() {
|
public void scalerScalesRaceClockHoursMinutesAndSecondsCorrectly() {
|
||||||
int scaleFactor = 3;
|
int scaleFactor = 3;
|
||||||
ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[5], new ArrayList<Leg>(), null, scaleFactor);
|
ArrayList<Leg> legs = new ArrayList<>();
|
||||||
|
legs.add(START_LEG);
|
||||||
|
|
||||||
|
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