@ -7,6 +7,7 @@ import seng302.GPSCoordinate;
import java.util.ArrayList ;
import java.util.ArrayList ;
import java.util.Arrays ;
import java.util.Arrays ;
import java.util.List ;
import static org.junit.Assert.assertEquals ;
import static org.junit.Assert.assertEquals ;
import static org.junit.Assert.assertTrue ;
import static org.junit.Assert.assertTrue ;
@ -18,156 +19,175 @@ 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" , 1 ) ;
// BoatInRace boat2 = new BoatInRace("Test 2", 10000, Color.BURLYWOOD, "t2");
BoatInRace boat2 = new BoatInRace ( "Test 2" , 10000 , Color . BURLYWOOD , "t2" , 2 ) ;
// BoatInRace[] boats = new BoatInRace[]{boat1, boat2};
//BoatInRace[] boats = new BoatInRace[]{boat1, boat2};
//
List < BoatInRace > boats = new ArrayList < > ( ) ;
// ArrayList<Leg> legs = new ArrayList<>();
boats . add ( boat1 ) ;
// legs.add(START_LEG); legs.add(FINISH_LEG);
boats . add ( boat2 ) ;
//
// ConstantVelocityRace race = new ConstantVelocityRace(boats, legs, null, 5);
ArrayList < Leg > legs = new ArrayList < > ( ) ;
// race.disableTimer();
legs . add ( START_LEG ) ; legs . add ( FINISH_LEG ) ;
// race.setDnfChance(0);
// long timeStarted = System.currentTimeMillis();
Race race = new Race ( boats , legs , 5 ) ;
// race.run();
race . setDnfChance ( 0 ) ;
//
long timeStarted = System . currentTimeMillis ( ) ;
// assertTrue(System.currentTimeMillis() - timeStarted < 4000);
race . run ( ) ;
// }
assertTrue ( System . currentTimeMillis ( ) - timeStarted < 4000 ) ;
//
}
// @Test
// public void checkPositionUpdatesNumberFinishedBoats() {
@Test
//
public void checkPositionUpdatesNumberFinishedBoats ( ) {
// BoatInRace finishedBoat = new BoatInRace("Test", 1000, Color.ALICEBLUE, "tt");
// finishedBoat.setDistanceTravelledInLeg(500);
BoatInRace finishedBoat = new BoatInRace ( "Test" , 1000 , Color . ALICEBLUE , "tt" , 1 ) ;
//
finishedBoat . setDistanceTravelledInLeg ( 500 ) ;
// finishedBoat.setCurrentLeg(FINISH_LEG);
//
finishedBoat . setCurrentLeg ( FINISH_LEG ) ;
// ArrayList<Leg> legs = new ArrayList<>();
// legs.add(FINISH_LEG);
ArrayList < BoatInRace > boats = new ArrayList < > ( ) ;
//
boats . add ( finishedBoat ) ;
// ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[1], legs, null, 1);
// race.setDnfChance(0);
ArrayList < Leg > legs = new ArrayList < > ( ) ;
// assertEquals(race.boatsFinished, 0);
legs . add ( FINISH_LEG ) ;
//
//
Race race = new Race ( boats , legs , 1 ) ;
// race.checkPosition(finishedBoat, 100000);
race . setDnfChance ( 0 ) ;
// assertEquals(race.boatsFinished, 1);
assertEquals ( race . boatsFinished , 0 ) ;
// assertEquals(finishedBoat.getTimeFinished(), 100000);
// }
//
race . checkPosition ( finishedBoat , 100000 ) ;
// @Test
assertEquals ( race . boatsFinished , 1 ) ;
// public void checkPositionDoesntUpdateNumberFinishedBoats() {
assertEquals ( finishedBoat . getTimeFinished ( ) , 100000 ) ;
//
}
// BoatInRace unFinishedBoat = new BoatInRace("Test", 10, Color.ALICEBLUE, "tt");
// unFinishedBoat.setDistanceTravelledInLeg(0);
@Test
//
public void checkPositionDoesntUpdateNumberFinishedBoats ( ) {
// unFinishedBoat.setCurrentLeg(FINISH_LEG);
//
BoatInRace unFinishedBoat = new BoatInRace ( "Test" , 10 , Color . ALICEBLUE , "tt" , 1 ) ;
// ArrayList<Leg> legs = new ArrayList<>();
unFinishedBoat . setDistanceTravelledInLeg ( 0 ) ;
// legs.add(FINISH_LEG);
//
unFinishedBoat . setCurrentLeg ( FINISH_LEG ) ;
// ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[1], legs, null, 1);
// race.setDnfChance(0);
ArrayList < BoatInRace > boats = new ArrayList < > ( ) ;
// assertEquals(race.boatsFinished, 0);
boats . add ( unFinishedBoat ) ;
//
// race.checkPosition(unFinishedBoat, 100);
ArrayList < Leg > legs = new ArrayList < > ( ) ;
// assertEquals(race.boatsFinished, 0);
legs . add ( FINISH_LEG ) ;
// }
//
Race race = new Race ( boats , legs , 1 ) ;
// @Test
race . setDnfChance ( 0 ) ;
// public void distanceTravelledBeforeUpdatingLegIsRetained() {
assertEquals ( race . boatsFinished , 0 ) ;
//
// ArrayList<Leg> legs = new ArrayList<>();
race . checkPosition ( unFinishedBoat , 100 ) ;
//
assertEquals ( race . boatsFinished , 0 ) ;
//
}
// legs.add(START_LEG);
// legs.add(FINISH_LEG);
@Test
//
public void distanceTravelledBeforeUpdatingLegIsRetained ( ) {
// ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[1], legs, null, 1);
// race.setDnfChance(0);
ArrayList < BoatInRace > boats = new ArrayList < > ( ) ;
//
// BoatInRace unFinishedBoat = new BoatInRace("Test", 10, Color.ALICEBLUE, "tt");
ArrayList < Leg > legs = new ArrayList < > ( ) ;
// unFinishedBoat.setDistanceTravelledInLeg(100);
// unFinishedBoat.setCurrentLeg(START_LEG);
legs . add ( START_LEG ) ;
//
legs . add ( FINISH_LEG ) ;
// race.checkPosition(unFinishedBoat, 100);
// assertEquals(unFinishedBoat.getCurrentLeg().getName(), "Finish");
Race race = new Race ( boats , legs , 1 ) ;
// assertTrue(unFinishedBoat.getDistanceTravelledInLeg() > 0);
race . setDnfChance ( 0 ) ;
// assertTrue(unFinishedBoat.getDistanceTravelledInLeg() < 100);
//
BoatInRace unFinishedBoat = new BoatInRace ( "Test" , 10 , Color . ALICEBLUE , "tt" , 1 ) ;
// }
unFinishedBoat . setDistanceTravelledInLeg ( 100 ) ;
//
unFinishedBoat . setCurrentLeg ( START_LEG ) ;
// /*@Test
//
race . checkPosition ( unFinishedBoat , 100 ) ;
// //Test temporarily removed as countdown timer now uses animation timer
assertEquals ( unFinishedBoat . getCurrentLeg ( ) . getName ( ) , "Finish" ) ;
//
assertTrue ( unFinishedBoat . getDistanceTravelledInLeg ( ) > 0 ) ;
// public void timerDelaysByHalfSecond() {
assertTrue ( unFinishedBoat . getDistanceTravelledInLeg ( ) < 100 ) ;
//
// ArrayList<Leg> legs = new ArrayList<>();
}
// legs.add(START_LEG);
//
@Test
// ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[1], legs, null, 1);
// race.PRERACE_TIME = 500;
public void timerDelaysByHalfSecond ( ) throws InterruptedException {
//
// long timeStarted = System.currentTimeMillis();
ArrayList < BoatInRace > boats = new ArrayList < > ( ) ;
// race.countdownTimer();
//
ArrayList < Leg > legs = new ArrayList < > ( ) ;
// //assertTrue(System.currentTimeMillis() - timeStarted > 500);
legs . add ( START_LEG ) ;
// System.out.println(System.currentTimeMillis() - timeStarted);
//
Race race = new Race ( boats , legs , 1 ) ;
// }*/
race . PRERACE_TIME = 500 ;
//
// @Test
long timeStarted = System . currentTimeMillis ( ) ;
// public void scalerScalesVelocityCorrectly() {
race . countdownTimer ( ) ;
//
// int scaleFactor = 3;
Thread . sleep ( 500 ) ;
// float vel1 = 0;
// float vel2 = (float) 1.999;
assertTrue ( System . currentTimeMillis ( ) - timeStarted > 500 ) ;
// float vel3 = (float) 32.5;
//System.out.println(System.currentTimeMillis() - timeStarted);
// 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");
@Test
// BoatInRace boat4 = new BoatInRace("test", vel4, Color.ALICEBLUE, "tt");
public void scalerScalesVelocityCorrectly ( ) {
// BoatInRace[] boats = new BoatInRace[]{boat1, boat2, boat3, boat4};
//
int scaleFactor = 3 ;
// ArrayList<Leg> legs = new ArrayList<>();
float vel1 = 0 ;
// legs.add(START_LEG);
float vel2 = ( float ) 1.999 ;
//
float vel3 = ( float ) 32.5 ;
// ConstantVelocityRace race = new ConstantVelocityRace(boats, legs, null, scaleFactor);
float vel4 = 500 ;
// race.setDnfChance(0);
BoatInRace boat1 = new BoatInRace ( "test" , vel1 , Color . ALICEBLUE , "tt" , 1 ) ;
//
BoatInRace boat2 = new BoatInRace ( "test" , vel2 , Color . ALICEBLUE , "tt" , 2 ) ;
// assertEquals(race.getStartingBoats().get(0).getScaledVelocity(), vel1 * scaleFactor, 1e-6);
BoatInRace boat3 = new BoatInRace ( "test" , vel3 , Color . ALICEBLUE , "tt" , 3 ) ;
// assertEquals(race.getStartingBoats().get(1).getScaledVelocity(), vel2 * scaleFactor, 1e-6);
BoatInRace boat4 = new BoatInRace ( "test" , vel4 , Color . ALICEBLUE , "tt" , 4 ) ;
// assertEquals(race.getStartingBoats().get(2).getScaledVelocity(), vel3 * scaleFactor, 1e-6);
ArrayList < BoatInRace > boats = new ArrayList < > ( ) ;
// assertEquals(race.getStartingBoats().get(3).getScaledVelocity(), vel4 * scaleFactor, 1e-6);
boats . add ( boat1 ) ;
// }
boats . add ( boat2 ) ;
//
boats . add ( boat3 ) ;
// @Test
boats . add ( boat4 ) ;
// public void scalerScalesRaceClockTo1MinCorrectly() {
// int scaleFactor = 10;
ArrayList < Leg > legs = new ArrayList < > ( ) ;
//
legs . add ( START_LEG ) ;
// ArrayList<Leg> legs = new ArrayList<>();
// legs.add(START_LEG);
Race race = new Race ( boats , legs , scaleFactor ) ;
//
race . setDnfChance ( 0 ) ;
// ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[5], legs, null, scaleFactor);
// race.totalTimeElapsed = 6000; //6 seconds
assertEquals ( race . getStartingBoats ( ) . get ( 0 ) . getScaledVelocity ( ) , vel1 * scaleFactor , 1e-6 ) ;
// assertTrue(race.calcTimer().equals("Race clock: 00:01:00"));
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 scalerScalesRaceClockHoursMinutesAndSecondsCorrectly() {
// int scaleFactor = 3;
@Test
// ArrayList<Leg> legs = new ArrayList<>();
public void scalerScalesRaceClockTo1MinCorrectly ( ) {
// legs.add(START_LEG);
int scaleFactor = 10 ;
//
// ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[5], legs, null, scaleFactor);
ArrayList < BoatInRace > boats = new ArrayList < > ( ) ;
// race.totalTimeElapsed = 3213000;
// assertTrue(race.calcTimer().equals("Race clock: 02:40:39"));
ArrayList < Leg > legs = new ArrayList < > ( ) ;
//
legs . add ( START_LEG ) ;
// }
Race race = new Race ( boats , legs , scaleFactor ) ;
race . totalTimeElapsed = 6000 ; //6 seconds
assertTrue ( race . calcTimer ( ) . equals ( "Race clock: 00:01:00" ) ) ;
}
@Test
public void scalerScalesRaceClockHoursMinutesAndSecondsCorrectly ( ) {
int scaleFactor = 3 ;
ArrayList < BoatInRace > boats = new ArrayList < > ( ) ;
ArrayList < Leg > legs = new ArrayList < > ( ) ;
legs . add ( START_LEG ) ;
Race race = new Race ( boats , legs , scaleFactor ) ;
race . totalTimeElapsed = 3213000 ;
assertTrue ( race . calcTimer ( ) . equals ( "Race clock: 02:40:39" ) ) ;
}
}
}