Merge branch 'make-tests' into 'master'

Added tests

Tags: #test

See merge request !15
This commit is contained in:
Michael Rausch
2017-03-09 12:23:23 +13:00
4 changed files with 44 additions and 2 deletions
+1 -1
View File
@@ -56,7 +56,7 @@ public class Boat {
* *
* @param velocity The velocity of boat * @param velocity The velocity of boat
*/ */
public void setVelocity(float velocity) { public void setVelocity(double velocity) {
this.velocity = velocity; this.velocity = velocity;
} }
} }
+10
View File
@@ -13,6 +13,7 @@ public class BoatTest {
public void testBoatCreation() { public void testBoatCreation() {
Boat boat1 = new Boat("Team 1"); Boat boat1 = new Boat("Team 1");
assertEquals(boat1.getTeamName(), "Team 1"); assertEquals(boat1.getTeamName(), "Team 1");
assertEquals(boat1.getVelocity(), (double) 10.0, 1e-15);
} }
@Test @Test
@@ -21,4 +22,13 @@ public class BoatTest {
boat1.setTeamName("Team 2"); boat1.setTeamName("Team 2");
assertEquals(boat1.getTeamName(), "Team 2"); assertEquals(boat1.getTeamName(), "Team 2");
} }
@Test
public void testSetVelocity() {
Boat boat1 = new Boat("Team 1", 29.0);
assertEquals(boat1.getVelocity(), (double) 29.0, 1e-15);
boat1.setVelocity(12.0);
assertEquals(boat1.getVelocity(), (double)12.0, 1e-15);
}
} }
+21 -1
View File
@@ -12,9 +12,29 @@ public class EventTest {
@Test @Test
public void getTimeString() throws Exception { public void getTimeString() throws Exception {
Leg leg = new Leg(035, 100, "Start"); Leg leg = new Leg(35, 100, "Start");
Boat boat = new Boat("testBoat"); Boat boat = new Boat("testBoat");
Event event = new Event(1231242, boat, leg); Event event = new Event(1231242, boat, leg);
assertEquals("20:31:242", event.getTimeString()); assertEquals("20:31:242", event.getTimeString());
} }
/**
* ensure all boats are added as they pass the marker
*/
@Test
public void boatOrderTest() throws Exception {
Leg leg = new Leg(35, 100, "1");
Boat boat1 = new Boat("testBoat");
Boat boat2 = new Boat("testBoat2");
Event event1 = new Event(1231242, boat1, leg);
Event event2 = new Event(1231242, boat2, leg);
event1.boatPassedMarker();
event2.boatPassedMarker();
assertEquals(event1.getLeg().getMarker().getBoats()[0].getTeamName(), "testBoat");
assertEquals(event2.getLeg().getMarker().getBoats()[1].getTeamName(), "testBoat2");
}
} }
+12
View File
@@ -24,4 +24,16 @@ public class RaceTest {
assertEquals(Array.getLength(race.getBoats()), 2); assertEquals(Array.getLength(race.getBoats()), 2);
} }
@Test
public void testGetShuffledBoats(){
Boat boat1 = new Boat("Team 1");
Boat boat2 = new Boat("Team 2");
Race race = new Race();
race.addBoat(boat1);
race.addBoat(boat2);
assertEquals(Array.getLength(race.getShuffledBoats()), 2);
}
} }