Merge branch 'master' of https://eng-git.canterbury.ac.nz/seng302-2017/team-7 into heading-visualisation
This commit is contained in:
@@ -1,16 +0,0 @@
|
||||
package seng302;
|
||||
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Unit test for simple App.
|
||||
*/
|
||||
public class AppTest
|
||||
{
|
||||
@Test
|
||||
public void testApp()
|
||||
{
|
||||
assertTrue( true );
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,6 @@ import static junit.framework.TestCase.assertTrue;
|
||||
public class BoatInRaceTest {
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void calculateDueNorthAzimuthReturns0() {
|
||||
BoatInRace boat = new BoatInRace("Test", 1, Color.ALICEBLUE, "tt");
|
||||
|
||||
@@ -4,11 +4,9 @@ package seng302.Model;
|
||||
import javafx.scene.paint.Color;
|
||||
import org.geotools.referencing.GeodeticCalculator;
|
||||
import org.junit.Test;
|
||||
import org.opengis.geometry.coordinate.Geodesic;
|
||||
import seng302.Constants;
|
||||
import seng302.GPSCoordinate;
|
||||
|
||||
import java.awt.geom.Point2D;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
@@ -18,49 +16,49 @@ import static org.junit.Assert.assertEquals;
|
||||
*/
|
||||
public class ConstantVelocityRaceTest {
|
||||
|
||||
Leg START_LEG = new Leg("Start", new GPSCoordinate(0, 0), new GPSCoordinate(50, 50), 0);
|
||||
int ONE_HOUR = 3600000; //1 hour in milliseconds
|
||||
|
||||
|
||||
@Test
|
||||
public void updatePositionChangesDistanceTravelled() {
|
||||
|
||||
BoatInRace boat = new BoatInRace("Test", 1, Color.ALICEBLUE, "tt");
|
||||
Leg start = new Leg("Start", new GPSCoordinate(0, 0), new GPSCoordinate(50, 50), 0);
|
||||
boat.setCurrentLeg(start);
|
||||
boat.setCurrentLeg(START_LEG);
|
||||
boat.setDistanceTravelledInLeg(0);
|
||||
int timeElapsed = 3600000; //1 hr
|
||||
BoatInRace[] boats = new BoatInRace[]{boat};
|
||||
|
||||
ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[1], new ArrayList<Leg>());
|
||||
ConstantVelocityRace race = new ConstantVelocityRace(boats, new ArrayList<Leg>(), null, 1);
|
||||
|
||||
race.updatePosition(boat, timeElapsed);
|
||||
assertEquals(boat.getDistanceTravelledInLeg(), boat.getVelocity() * timeElapsed / 3600000, 1e-8);
|
||||
race.updatePosition(boat, ONE_HOUR);
|
||||
assertEquals(boat.getDistanceTravelledInLeg(), boat.getVelocity(), 1e-8);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updatePositionHandlesNoChangeToDistanceTravelled() {
|
||||
|
||||
BoatInRace boat = new BoatInRace("Test", 0, Color.ALICEBLUE, "tt");
|
||||
Leg start = new Leg("Start", new GPSCoordinate(0, 0), new GPSCoordinate(50, 50), 0);
|
||||
boat.setCurrentLeg(start);
|
||||
boat.setCurrentLeg(START_LEG);
|
||||
boat.setDistanceTravelledInLeg(0);
|
||||
int timeElapsed = 3600000; //1 hr
|
||||
BoatInRace[] boats = new BoatInRace[]{boat};
|
||||
|
||||
ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[1], new ArrayList<Leg>());
|
||||
ConstantVelocityRace race = new ConstantVelocityRace(boats, new ArrayList<Leg>(), null, 1);
|
||||
|
||||
race.updatePosition(boat, timeElapsed);
|
||||
race.updatePosition(boat, ONE_HOUR);
|
||||
assertEquals(boat.getDistanceTravelledInLeg(), 0, 1e-8);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void changesToDistanceTravelledAreAdditive() {
|
||||
BoatInRace boat = new BoatInRace("Test", 5, Color.ALICEBLUE, "tt");
|
||||
Leg start = new Leg("Start", new GPSCoordinate(0, 0), new GPSCoordinate(50, 50), 0);
|
||||
boat.setCurrentLeg(start);
|
||||
boat.setCurrentLeg(START_LEG);
|
||||
boat.setDistanceTravelledInLeg(50);
|
||||
int timeElapsed = 3600000; //1 hr
|
||||
BoatInRace[] boats = new BoatInRace[]{boat};
|
||||
|
||||
ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[1], new ArrayList<Leg>());
|
||||
ConstantVelocityRace race = new ConstantVelocityRace(boats, new ArrayList<Leg>(), null, 1);
|
||||
|
||||
race.updatePosition(boat, timeElapsed);
|
||||
assertEquals(boat.getDistanceTravelledInLeg(), boat.getVelocity() * timeElapsed / 3600000 + 50, 1e-8);
|
||||
race.updatePosition(boat, ONE_HOUR);
|
||||
assertEquals(boat.getDistanceTravelledInLeg(), boat.getVelocity() + 50, 1e-8);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -72,7 +70,6 @@ public class ConstantVelocityRaceTest {
|
||||
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);
|
||||
|
||||
@@ -20,7 +20,7 @@ public class LegTest {
|
||||
|
||||
GPSCoordinate startPoint = new GPSCoordinate(0, 0);
|
||||
GPSCoordinate endPoint = new GPSCoordinate(calc.getDestinationGeographicPoint().getY(), calc.getDestinationGeographicPoint().getX());
|
||||
Leg test= new Leg("Test", startPoint, endPoint, 0);
|
||||
Leg test = new Leg("Test", startPoint, endPoint, 0);
|
||||
assertEquals(test.getDistance(), 5, 1e-8);
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ public class LegTest {
|
||||
|
||||
GPSCoordinate startPoint = new GPSCoordinate(0, 0);
|
||||
GPSCoordinate endPoint = new GPSCoordinate(calc.getDestinationGeographicPoint().getY(), calc.getDestinationGeographicPoint().getX());
|
||||
Leg test= new Leg("Test", startPoint, endPoint, 0);
|
||||
Leg test = new Leg("Test", startPoint, endPoint, 0);
|
||||
assertEquals(test.getDistance(), 12, 1e-8);
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ public class LegTest {
|
||||
|
||||
GPSCoordinate startPoint = new GPSCoordinate(0, 0);
|
||||
GPSCoordinate endPoint = new GPSCoordinate(calc.getDestinationGeographicPoint().getY(), calc.getDestinationGeographicPoint().getX());
|
||||
Leg test= new Leg("Test", startPoint, endPoint, 0);
|
||||
Leg test = new Leg("Test", startPoint, endPoint, 0);
|
||||
assertEquals(test.getDistance(), 0.5, 1e-8);
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ public class LegTest {
|
||||
|
||||
GPSCoordinate startPoint = new GPSCoordinate(0, 0);
|
||||
GPSCoordinate endPoint = new GPSCoordinate(calc.getDestinationGeographicPoint().getY(), calc.getDestinationGeographicPoint().getX());
|
||||
Leg test= new Leg("Test", startPoint, endPoint, 0);
|
||||
Leg test = new Leg("Test", startPoint, endPoint, 0);
|
||||
assertEquals(test.getDistance(), 0.1, 1e-8);
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ public class LegTest {
|
||||
public void calculateDistanceHandlesZeroDifference() {
|
||||
GPSCoordinate startPoint = new GPSCoordinate(0, 0);
|
||||
GPSCoordinate endPoint = new GPSCoordinate(0, 0);
|
||||
Leg test= new Leg("Test", startPoint, endPoint, 0);
|
||||
Leg test = new Leg("Test", startPoint, endPoint, 0);
|
||||
assertEquals(test.getDistance(), 0, 1e-8);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,18 +1,11 @@
|
||||
package seng302.Model;
|
||||
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.scene.paint.Color;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import seng302.GPSCoordinate;
|
||||
import seng302.Model.BoatInRace;
|
||||
import seng302.Model.ConstantVelocityRace;
|
||||
import seng302.Model.Leg;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Observable;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
@@ -30,16 +23,16 @@ public class RaceTest {
|
||||
new BoatInRace("AU", 2800, Color.BEIGE, "AU")
|
||||
};
|
||||
ArrayList<Leg> legs = new ArrayList<>();
|
||||
legs.add(new Leg("Start", new GPSCoordinate(32.296577, -64.854304),new GPSCoordinate(32.293039, -64.843983),0));
|
||||
legs.add(new Leg("Start", new GPSCoordinate(32.293039, -64.843983),new GPSCoordinate(32.284680, -64.850045),1));
|
||||
Race race = new ConstantVelocityRace(boats, legs);
|
||||
legs.add(new Leg("Start", new GPSCoordinate(32.296577, -64.854304), new GPSCoordinate(32.293039, -64.843983), 0));
|
||||
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.disableTimer();
|
||||
|
||||
// Boats should finish in an order determined by their velocity
|
||||
Arrays.sort(boats, (a,b) -> (int)(b.getVelocity()-a.getVelocity()));
|
||||
Arrays.sort(boats, (a, b) -> (int) (b.getVelocity() - a.getVelocity()));
|
||||
race.run();
|
||||
|
||||
for(int i = 0; i < boats.length; i++)
|
||||
for (int i = 0; i < boats.length; i++)
|
||||
assertTrue(boats[i].equals(race.getStartingBoats().get(i)));
|
||||
}
|
||||
|
||||
@@ -52,7 +45,7 @@ public class RaceTest {
|
||||
Leg leg = new Leg("Finish", new GPSCoordinate(0, 0), new GPSCoordinate(1, 1), 0);
|
||||
finishedBoat.setCurrentLeg(leg);
|
||||
|
||||
ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[1], new ArrayList<Leg>());
|
||||
ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[1], new ArrayList<Leg>(), null, 1);
|
||||
assertEquals(race.boatsFinished, 0);
|
||||
|
||||
race.checkPosition(finishedBoat, 100);
|
||||
@@ -68,7 +61,7 @@ public class RaceTest {
|
||||
Leg leg = new Leg("Finish", new GPSCoordinate(0, 0), new GPSCoordinate(1, 1), 0);
|
||||
unFinishedBoat.setCurrentLeg(leg);
|
||||
|
||||
ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[1], new ArrayList<Leg>());
|
||||
ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[1], new ArrayList<Leg>(), null, 1);
|
||||
assertEquals(race.boatsFinished, 0);
|
||||
|
||||
race.checkPosition(unFinishedBoat, 100);
|
||||
@@ -84,9 +77,10 @@ public class RaceTest {
|
||||
Leg leg1 = new Leg("1", new GPSCoordinate(0, 0), new GPSCoordinate(1, 1), 0);
|
||||
Leg leg2 = new Leg("2", new GPSCoordinate(0, 0), new GPSCoordinate(1, 1), 1);
|
||||
|
||||
legs.add(leg2); legs.add(leg2);
|
||||
legs.add(leg2);
|
||||
legs.add(leg2);
|
||||
|
||||
ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[1], legs);
|
||||
ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[1], legs, null, 1);
|
||||
|
||||
BoatInRace unFinishedBoat = new BoatInRace("Test", 10, Color.ALICEBLUE, "tt");
|
||||
unFinishedBoat.setDistanceTravelledInLeg(100);
|
||||
@@ -101,7 +95,7 @@ public class RaceTest {
|
||||
|
||||
@Test
|
||||
public void timerDelaysByHalfSecond() {
|
||||
ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[1], new ArrayList<>());
|
||||
ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[1], new ArrayList<>(), null, 1);
|
||||
race.PRERACE_TIME = 500;
|
||||
|
||||
long timeStarted = System.currentTimeMillis();
|
||||
@@ -110,4 +104,42 @@ public class RaceTest {
|
||||
assertTrue(System.currentTimeMillis() - timeStarted > 500);
|
||||
|
||||
}
|
||||
|
||||
@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};
|
||||
|
||||
ConstantVelocityRace race = new ConstantVelocityRace(boats, new ArrayList<Leg>(), null, scaleFactor);
|
||||
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;
|
||||
ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[5], new ArrayList<Leg>(), null, scaleFactor);
|
||||
race.totalTimeElapsed = 6000; //6 seconds
|
||||
assertTrue(race.calcTimer().equals("Race clock: 00:01:00"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void scalerScalesRaceClockHoursMinutesAndSecondsCorrectly() {
|
||||
int scaleFactor = 3;
|
||||
ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[5], new ArrayList<Leg>(), null, scaleFactor);
|
||||
race.totalTimeElapsed = 3213000;
|
||||
assertTrue(race.calcTimer().equals("Race clock: 02:40:39"));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user