mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 06:18:44 +00:00
Merge branch '1124_Mark_Sequence_From_RaceXML' into 'develop'
Loading mark sequence from RaceXML
# Loading mark sequence from RaceXML
## Change Log
1. Added MarkOrder class
* Mark order is read from the generated RaceXML and stored
* Added .getNextMark() to get the next mark in the race
* Added .equals() and .hashCode() for Marks
* NEW: Added RacePosition class to hold players position in the race
* NEW: Fixed issue where the duplicates weren't stored in the mark order
## Testing
* Unit tests in models/MarkOrderTest.java
## Acceptance Criteria
* Use the mark sequence in the raceXML
* Met by change log item (1)
* Store relevant mark details with each participating boat (Last mark, next mark)
* Method in MarkOrder to get next mark, however the last mark and next mark will need to be stored by whoever implements the second task.
See merge request !52
This commit is contained in:
@@ -0,0 +1,83 @@
|
||||
package seng302.models;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
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;
|
||||
|
||||
@BeforeClass
|
||||
public static void setup(){
|
||||
markOrder = new MarkOrder();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test to ensure marks are loaded from XML
|
||||
*/
|
||||
@Test
|
||||
public void testMarkOrderLoadedFromXML(){
|
||||
assertTrue(markOrder != null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if .getNextMark() returns null if it is called with the final mark in the race
|
||||
*/
|
||||
@Test
|
||||
public void testNextMarkAtEnd(){
|
||||
// There are no marks in the XML, therefore this can't be tested
|
||||
if (markOrder.getMarkOrder().size() == 0){
|
||||
return;
|
||||
}
|
||||
|
||||
Mark lastMark = markOrder.getMarkOrder().get(markOrder.getMarkOrder().size() - 1);
|
||||
Integer lastIndex = markOrder.getMarkOrder().size() - 1;
|
||||
|
||||
RacePosition lastRacePosition = new RacePosition(lastIndex, lastMark, null);
|
||||
|
||||
assertEquals(null, markOrder.getNextPosition(lastRacePosition).getNextMark());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if .getNextMark() method returns the next mark in the race
|
||||
*/
|
||||
@Test
|
||||
public void testNextMark(){
|
||||
// There are not enough marks for this to be tested
|
||||
if (markOrder.getMarkOrder().size() < 2){
|
||||
return;
|
||||
}
|
||||
|
||||
RacePosition firstRacePos = new RacePosition(0, markOrder.getMarkOrder().get(0), null);
|
||||
|
||||
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
|
||||
public static void tearDown(){
|
||||
markOrder = null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user