mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 14:28:43 +00:00
Merge remote-tracking branch 'origin/develop' into Story66_Collision
# Conflicts: # src/main/java/seng302/gameServer/GameState.java # src/main/java/seng302/model/Yacht.java # src/main/java/seng302/model/mark/MarkOrder.java # src/main/java/seng302/visualiser/GameClient.java
This commit is contained in:
@@ -1,54 +0,0 @@
|
||||
package seng302.model;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import seng302.model.mark.CompoundMark;
|
||||
import seng302.model.mark.Mark;
|
||||
|
||||
/**
|
||||
* Use this link to test geo distances
|
||||
* http://www.csgnetwork.com/gpsdistcalc.html
|
||||
* Created by wmu16 on 3/08/17.
|
||||
*/
|
||||
public class YachtTest {
|
||||
|
||||
private Yacht yacht;
|
||||
private CompoundMark compoundMark;
|
||||
private Double toleranceRatio = 0.01;
|
||||
private GeoPoint p1 = new GeoPoint(57.670333, 11.827833);
|
||||
private GeoPoint p2 = new GeoPoint(57.671524, 11.844495);
|
||||
private GeoPoint p3 = new GeoPoint(57.670822, 11.843392);
|
||||
private GeoPoint p4 = new GeoPoint(25.694829, 98.392049);
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
yacht = new Yacht("Yacht",
|
||||
0,
|
||||
"0",
|
||||
"WillIsCool",
|
||||
"HaomingIsOk",
|
||||
"NZL");
|
||||
|
||||
yacht.setLocation(57.670333, 11.827833);
|
||||
|
||||
compoundMark = new CompoundMark(0, "HaomingsMark");
|
||||
Mark subMark1 = new Mark("H", 57.671524, 11.844495, 0);
|
||||
Mark subMark2 = new Mark("H", 57.670822, 11.843392, 0);
|
||||
compoundMark.addSubMarks(subMark1, subMark2);
|
||||
|
||||
yacht.setNextMark(compoundMark);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testDistanceToNextMark() {
|
||||
Double actual, expected;
|
||||
actual = yacht.calcDistanceToNextMark();
|
||||
expected = 927d;
|
||||
assertEquals(expected, actual, expected * toleranceRatio);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package seng302.model.mark;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import seng302.model.GeoPoint;
|
||||
|
||||
/**
|
||||
* A class to test the compound mark calss
|
||||
* Created by wmu16 on 10/08/17.
|
||||
*/
|
||||
public class CompoundMarkTest {
|
||||
|
||||
private Mark mark1;
|
||||
private Mark mark2;
|
||||
private CompoundMark gateMark;
|
||||
private CompoundMark singleMark;
|
||||
|
||||
private static Double TOLERANCE_RATIO = 0.01;
|
||||
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
mark1 = new Mark("Mark1", 57.670333, 11.842833, 0);
|
||||
mark2 = new Mark("Mark2", 57.671524, 11.844495, 1);
|
||||
|
||||
List<Mark> gateMarks = new ArrayList<Mark>();
|
||||
gateMarks.add(mark1);
|
||||
gateMarks.add(mark2);
|
||||
|
||||
List<Mark> singleMarks = new ArrayList<Mark>();
|
||||
singleMarks.add(mark1);
|
||||
|
||||
gateMark = new CompoundMark(0, "Fun Mark", gateMarks);
|
||||
singleMark = new CompoundMark(1, "Awesome Mark", singleMarks);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void getSubMark() throws Exception {
|
||||
assertEquals(mark1, gateMark.getSubMark(1));
|
||||
assertEquals(mark2, gateMark.getSubMark(2));
|
||||
|
||||
assertEquals(mark1, singleMark.getSubMark(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getMidPoint() throws Exception {
|
||||
GeoPoint result = gateMark.getMidPoint();
|
||||
assertEquals(57.6709285, result.getLat(), result.getLat() * TOLERANCE_RATIO);
|
||||
assertEquals(11.843664, result.getLng(), result.getLng() * TOLERANCE_RATIO);
|
||||
|
||||
result = singleMark.getMidPoint();
|
||||
assertEquals(result, mark1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isGate() throws Exception {
|
||||
assertTrue(gateMark.isGate());
|
||||
assertFalse(singleMark.isGate());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,19 +3,22 @@ package seng302.models;
|
||||
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.assertFalse;
|
||||
import static junit.framework.TestCase.assertTrue;
|
||||
|
||||
public class MarkOrderTest {
|
||||
private static MarkOrder markOrder;
|
||||
private static Integer currentSeqID;
|
||||
|
||||
@BeforeClass
|
||||
public static void setup(){
|
||||
markOrder = new MarkOrder();
|
||||
currentSeqID = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -26,54 +29,39 @@ public class MarkOrderTest {
|
||||
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;
|
||||
}
|
||||
public void testIsLastMark() {
|
||||
currentSeqID = 0;
|
||||
assertFalse(markOrder.isLastMark(currentSeqID));
|
||||
|
||||
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());
|
||||
currentSeqID = markOrder.getMarkOrder().size() - 1;
|
||||
assertTrue(markOrder.isLastMark(currentSeqID));
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
public void testGetNextMark() {
|
||||
currentSeqID = 4;
|
||||
CompoundMark nextMark = markOrder.getMarkOrder().get(4 + 1);
|
||||
assertEquals(nextMark, markOrder.getNextMark(currentSeqID));
|
||||
|
||||
RacePosition firstRacePos = new RacePosition(0, markOrder.getMarkOrder().get(0), null);
|
||||
|
||||
assertEquals(markOrder.getMarkOrder().get(1).getName(), markOrder.getNextPosition(firstRacePos).getNextMark().getName());
|
||||
currentSeqID = 3;
|
||||
nextMark = markOrder.getMarkOrder().get(3 + 1);
|
||||
assertEquals(nextMark, markOrder.getNextMark(currentSeqID));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if a whole race can be completed
|
||||
*/
|
||||
@Test
|
||||
public void testMarkSequence(){
|
||||
RacePosition current = markOrder.getFirstPosition();
|
||||
public void testGetCurrentMark() {
|
||||
currentSeqID = 0;
|
||||
CompoundMark currentMark = markOrder.getMarkOrder().get(0);
|
||||
assertEquals(currentMark, markOrder.getCurrentMark(0));
|
||||
}
|
||||
|
||||
while (!current.getIsFinishingLeg()){
|
||||
|
||||
current = markOrder.getNextPosition(current);
|
||||
|
||||
if (current.getIsFinishingLeg()){
|
||||
assertEquals(null, current.getNextMark());
|
||||
}
|
||||
}
|
||||
@Test
|
||||
public void testGetPreviousMark() {
|
||||
currentSeqID = 1;
|
||||
CompoundMark prevMark = markOrder.getMarkOrder().get(0);
|
||||
assertEquals(prevMark, markOrder.getPreviousMark(currentSeqID));
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
|
||||
@@ -6,12 +6,11 @@ import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import javafx.geometry.Point2D;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import seng302.model.GeoPoint;
|
||||
import seng302.utilities.GeoUtility;
|
||||
|
||||
/**
|
||||
* http://www.geoplaner.com/ For plotting geo points for visualisation
|
||||
* To test methods in GeoUtility.
|
||||
* Use this site to calculate distances
|
||||
* https://rechneronline.de/geo-coordinates/#distance
|
||||
@@ -150,4 +149,32 @@ public class GeoUtilityTest {
|
||||
assertFalse(GeoUtility.isPointInTriangle(v1, v2, v3, p2));
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testCheckCrossedGate() {
|
||||
GeoPoint mark1 = new GeoPoint(37.40937, -122.62233);
|
||||
GeoPoint mark2 = new GeoPoint(37.40938, -122.62154);
|
||||
GeoPoint location1 = new GeoPoint(37.40964, -122.62196);
|
||||
GeoPoint location2 = new GeoPoint(37.40910, -122.62189);
|
||||
GeoPoint location3 = new GeoPoint(37.40949, -122.62202);
|
||||
GeoPoint location4 = new GeoPoint(37.40927, -122.62152);
|
||||
|
||||
// M1 -> M3 enters from CCW side
|
||||
assertTrue(GeoUtility.checkCrossedLine(mark1, mark2, location1, location2) == 2);
|
||||
// M1 -> M3 doesn't across
|
||||
assertFalse(GeoUtility.checkCrossedLine(mark1, mark2, location1, location3) > 0);
|
||||
// M2 -> M3 enters from CW side
|
||||
assertTrue(GeoUtility.checkCrossedLine(mark1, mark2, location2, location3) == 1);
|
||||
// order changes intersect direction
|
||||
assertTrue(GeoUtility.checkCrossedLine(mark2, mark1, location2, location3) == 2);
|
||||
assertTrue(GeoUtility.checkCrossedLine(mark1, mark2, location3, location2) == 2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDirtyMiddlePoint() {
|
||||
GeoPoint result = GeoUtility.getDirtyMidPoint(p1, p2);
|
||||
assertEquals(57.6709285, result.getLat(), result.getLat() * toleranceRate);
|
||||
assertEquals(11.836164, result.getLng(), result.getLng() * toleranceRate);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user