Merge branch 'develop' into issue38_irregular_key_event_packets

# Conflicts:
#	src/main/java/seng302/gameServer/GameState.java
#	src/main/java/seng302/gameServer/ServerPacketParser.java
#	src/main/java/seng302/gameServer/ServerToClientThread.java
#	src/main/java/seng302/visualiser/ClientToServerThread.java
#	src/main/java/seng302/visualiser/GameClient.java
This commit is contained in:
Calum
2017-08-13 18:44:34 +12:00
25 changed files with 951 additions and 452 deletions
@@ -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,68 @@
package seng302.model.mark;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
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());
}
}
+30 -43
View File
@@ -1,21 +1,23 @@
package seng302.models;
import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.assertFalse;
import static junit.framework.TestCase.assertTrue;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import seng302.model.mark.Mark;
import seng302.model.mark.CompoundMark;
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;
private static Integer currentSeqID;
@BeforeClass
public static void setup(){
markOrder = new MarkOrder();
currentSeqID = 0;
}
/**
@@ -26,54 +28,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
@@ -0,0 +1,89 @@
package seng302.models;
import static org.junit.Assert.assertEquals;
import java.util.HashMap;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import seng302.gameServer.GameState;
import seng302.model.PolarTable;
import seng302.model.Yacht;
public class YachtTest {
private static Yacht y1;
//Yacht y2;
private static Double windDirection = 180d;
private static Double windSpeed = 20d;
private static GameState gs;
@BeforeClass
public static void setUp() {
y1 = new Yacht("Yacht", 101, "Y1", "Y1", "Yacht 1", "C1");
gs = new GameState("localhost");
}
@Test
public void tackGybeTest() {
HashMap<Double, Double> values = new HashMap<>();
values.put(280.0, 80.0);
values.put(270.0, 90.0);
values.put(359.0, 1.0);
values.put(180.0, 180.0);
values.put(75.0, 285.0);
for (Double begin : values.keySet()) {
y1.setHeading(begin);
y1.tackGybe(windDirection);
for (int i = 0; i < 50; i++) {
y1.runAutoPilot();
}
assertEquals(values.get(begin), y1.getHeading(), 5.0);
}
}
@Test
public void vmgTest() {
PolarTable.parsePolarFile(getClass().getResourceAsStream("/config/acc_polars.csv"));
Double upwind = PolarTable.getOptimalUpwindVMG(windSpeed).keySet().iterator().next();
Double downwind = PolarTable.getOptimalDownwindVMG(windSpeed).keySet().iterator().next();
HashMap<Double, Double> values = new HashMap<>();
upwind = (double) Math.floorMod(upwind.longValue() + windDirection.longValue(), 360L);
Double upwindRight = upwind;
Double upwindLeft = 360 - upwindRight;
downwind = (double) Math.floorMod(downwind.longValue() + windDirection.longValue(), 360L);
Double downwindRight = downwind;
Double downwindLeft = 360 - downwindRight;
values.put(190d, upwindRight);
values.put(170d, upwindLeft);
values.put(10d, downwindLeft);
values.put(350d, downwindRight);
for (Double begin : values.keySet()) {
System.out.println(begin);
y1.setHeading(begin);
y1.turnToVMG();
for (int i = 0; i < 50; i++) {
y1.runAutoPilot();
System.out.println(y1.getHeading());
}
y1.disableAutoPilot();
assertEquals(values.get(begin), y1.getHeading(), 5.0);
}
}
@AfterClass
public static void tearDown() {
y1 = null;
}
}
@@ -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);
}
}