Loading course mark order from RaceXML

- Re-engineered code to work with the new marks
- Fixed bug where race order wasn't correct (added RacePosition class to fix)
- Rewrote tests to work with new RacePosition class

Tags: #story[1124] (Task 1)
This commit is contained in:
Michael Rausch
2017-08-04 13:20:50 +12:00
parent f9e6df46c1
commit 281ce2d842
3 changed files with 131 additions and 66 deletions
+28 -39
View File
@@ -1,13 +1,14 @@
package seng302.models;
import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.assertTrue;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import seng302.model.mark.CompoundMark;
import seng302.model.mark.Mark;
import seng302.model.mark.MarkOrder;
import seng302.model.mark.RacePosition;
import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.assertTrue;
public class MarkOrderTest {
private static MarkOrder markOrder;
@@ -25,28 +26,6 @@ public class MarkOrderTest {
assertTrue(markOrder != null);
}
// /**
// * Test if .equals() method on returns true on two marks that are equal
// */
// @Test
// public void testMarkEqualsTrue(){
// M mark1 = new SingleMark("asd", 1.1, 2.2, 1, 2);
// Mark mark2 = new SingleMark("asd", 1.1, 2.2, 1, 2);
//
// assertEquals(mark1, mark2);
// }
//
// /**
// * Test if .equals() method on returns false on two marks that are NOT equal
// */
// @Test
// public void testMarkNotEquals(){
// Mark mark1 = new SingleMark("asf", 1.1, 2.2, 2, 2);
// Mark mark2 = new SingleMark("asd", 1.1, 2.2, 1, 2);
//
// assertNotEquals(mark1, mark2);
// }
/**
* Test if .getNextMark() returns null if it is called with the final mark in the race
*/
@@ -57,19 +36,12 @@ public class MarkOrderTest {
return;
}
CompoundMark lastMark = markOrder.getMarkOrder().get(markOrder.getMarkOrder().size() - 1);
Mark lastMark = markOrder.getMarkOrder().get(markOrder.getMarkOrder().size() - 1);
Integer lastIndex = markOrder.getMarkOrder().size() - 1;
assertEquals(null, markOrder.getNextMark(lastMark));
}
RacePosition lastRacePosition = new RacePosition(lastIndex, lastMark, null);
/**
* Test if .getNextMark() method on returns null if the mark does not exist in the race
*/
@Test
public void testNextMarkNotExists(){
CompoundMark someMark = new CompoundMark(1, "something");
assertEquals(null, markOrder.getNextMark(someMark));
assertEquals(null, markOrder.getNextPosition(lastRacePosition).getNextMark());
}
/**
@@ -82,9 +54,26 @@ public class MarkOrderTest {
return;
}
CompoundMark firstMark = markOrder.getMarkOrder().get(0);
RacePosition firstRacePos = new RacePosition(0, markOrder.getMarkOrder().get(0), null);
assertEquals(markOrder.getMarkOrder().get(1), markOrder.getNextMark(firstMark));
assertEquals(markOrder.getMarkOrder().get(1).getName(), markOrder.getNextPosition(firstRacePos).getNextMark().getName());
}
/**
* Test if a whole race can be completed
*/
@Test
public void testMarkSequence(){
RacePosition current = markOrder.getFirstPosition();
while (!current.getIsFinishingLeg()){
current = markOrder.getNextPosition(current);
if (current.getIsFinishingLeg()){
assertEquals(null, current.getNextMark());
}
}
}
@AfterClass