You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
102 lines
3.5 KiB
102 lines
3.5 KiB
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;
|
|
|
|
/**
|
|
* Created by esa46 on 15/03/17.
|
|
*/
|
|
public class RaceTest {
|
|
|
|
|
|
@Test
|
|
public void finishOrderDeterminedByVelocity() {
|
|
BoatInRace[] boats = {
|
|
new BoatInRace("NZ", 2000, Color.BEIGE, "NZ"),
|
|
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);
|
|
race.disableTimer();
|
|
|
|
// Boats should finish in an order determined by their velocity
|
|
Arrays.sort(boats, (a,b) -> (int)(b.getVelocity()-a.getVelocity()));
|
|
race.run();
|
|
|
|
for(int i = 0; i < boats.length; i++)
|
|
assertTrue(boats[i].equals(race.getStartingBoats().get(i)));
|
|
}
|
|
|
|
|
|
@Test
|
|
public void checkPositionUpdatesNumberFinishedBoats() {
|
|
|
|
BoatInRace finishedBoat = new BoatInRace("Test", 1000, Color.ALICEBLUE, "tt");
|
|
finishedBoat.setDistanceTravelledInLeg(500);
|
|
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>());
|
|
assertEquals(race.boatsFinished, 0);
|
|
|
|
race.checkPosition(finishedBoat, 100);
|
|
assertEquals(race.boatsFinished, 1);
|
|
assertEquals(finishedBoat.getTimeFinished(), 100);
|
|
}
|
|
|
|
@Test
|
|
public void checkPositionDoesntUpdateNumberFinishedBoats() {
|
|
|
|
BoatInRace unFinishedBoat = new BoatInRace("Test", 10, Color.ALICEBLUE, "tt");
|
|
unFinishedBoat.setDistanceTravelledInLeg(0);
|
|
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>());
|
|
assertEquals(race.boatsFinished, 0);
|
|
|
|
race.checkPosition(unFinishedBoat, 100);
|
|
assertEquals(race.boatsFinished, 0);
|
|
}
|
|
|
|
|
|
@Test
|
|
public void distanceTravelledBeforeUpdatingLegIsRetained() {
|
|
|
|
ArrayList<Leg> legs = new ArrayList<>();
|
|
|
|
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);
|
|
|
|
ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[1], legs);
|
|
|
|
BoatInRace unFinishedBoat = new BoatInRace("Test", 10, Color.ALICEBLUE, "tt");
|
|
unFinishedBoat.setDistanceTravelledInLeg(100);
|
|
unFinishedBoat.setCurrentLeg(leg1);
|
|
|
|
race.checkPosition(unFinishedBoat, 100);
|
|
assertEquals(unFinishedBoat.getCurrentLeg().getName(), "2");
|
|
assertTrue(unFinishedBoat.getDistanceTravelledInLeg() > 0);
|
|
assertTrue(unFinishedBoat.getDistanceTravelledInLeg() < 100);
|
|
|
|
}
|
|
}
|