Tests for the Race class added
-Mostly to do with checking positions and updating correctly #test #story 9
This commit is contained in:
@@ -176,6 +176,7 @@ public abstract class Race implements Runnable {
|
|||||||
//boat has finished
|
//boat has finished
|
||||||
boatsFinished++;
|
boatsFinished++;
|
||||||
boat.setFinished(true);
|
boat.setFinished(true);
|
||||||
|
boat.setTimeFinished(timeElapsed);
|
||||||
} else {
|
} else {
|
||||||
boat.setDistanceTravelledInLeg(boat.getDistanceTravelledInLeg() - boat.getCurrentLeg().getDistance());
|
boat.setDistanceTravelledInLeg(boat.getDistanceTravelledInLeg() - boat.getCurrentLeg().getDistance());
|
||||||
Leg nextLeg = legs.get(boat.getCurrentLeg().getLegNumber() + 1);
|
Leg nextLeg = legs.get(boat.getCurrentLeg().getLegNumber() + 1);
|
||||||
|
|||||||
@@ -109,8 +109,6 @@ public class BoatInRaceTest {
|
|||||||
assertTrue(testBoat.getCurrentPosition() == null);
|
assertTrue(testBoat.getCurrentPosition() == null);
|
||||||
assertTrue(testBoat.toString().contains("Name can change"));
|
assertTrue(testBoat.toString().contains("Name can change"));
|
||||||
assertEquals(testBoat.getVelocity(), 20.0);
|
assertEquals(testBoat.getVelocity(), 20.0);
|
||||||
//assertTrue(testBoat.getName().equals("Name can change"));
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -14,6 +14,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Observable;
|
import java.util.Observable;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -41,4 +42,60 @@ public class RaceTest {
|
|||||||
for(int i = 0; i < boats.length; i++)
|
for(int i = 0; i < boats.length; i++)
|
||||||
assertTrue(boats[i].equals(race.getStartingBoats().get(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);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user