Fixed connecting to hosts. Fixed issue34 and 35 to the point where they can be developed off of.

#refactor #bug #issue[34, 35]
This commit is contained in:
Calum
2017-08-02 00:26:57 +12:00
parent 908c0749cf
commit 87ef37a689
48 changed files with 355 additions and 319 deletions
@@ -0,0 +1,35 @@
package seng302.gameServer.server;
import static junit.framework.TestCase.assertEquals;
import org.junit.Test;
import seng302.gameServer.server.messages.BoatLocationMessage;
/**
* Test conversions used by the boat location messages
*/
public class TestConversions {
@Test
public void testLatLonConversion(){
long binaryPacked = BoatLocationMessage.latLonToBinaryPackedLong(3232.323);
double original = BoatLocationMessage.binaryPackedToLatLon(binaryPacked);
assertEquals(3232.323, original, 0.01);
}
@Test
public void testWindAngleConversion(){
long binaryPacked = BoatLocationMessage.windAngleToBinaryPackedLong(3232.323);
double original = BoatLocationMessage.binaryPackedWindAngleToDouble(binaryPacked);
assertEquals(3232.323, original, 0.01);
}
@Test
public void testHeadingConversion(){
long binaryPacked = BoatLocationMessage.headingToBinaryPackedLong(3232.323);
double original = BoatLocationMessage.binaryPackedHeadingToDouble(binaryPacked);
assertEquals(3232.323, original, 0.01);
}
}
@@ -0,0 +1,27 @@
package seng302.gameServer.server;
import static junit.framework.TestCase.assertTrue;
import org.junit.Test;
import seng302.gameServer.server.messages.Header;
import seng302.gameServer.server.messages.MessageType;
/**
* Tests message header
*/
public class TestHeader {
@Test
public void testHeaderSizeEqualsActualSize(){
Header h = new Header(MessageType.DISPLAY_TEXT_MESSAGE, 1, (short) 1);
assertTrue(h.getSize() == h.getByteBuffer().array().length);
}
@Test
public void headerSizeIsSameAsSpec(){
Header h = new Header(MessageType.DISPLAY_TEXT_MESSAGE, 1, (short) 1);
assertTrue(h.getSize() == 15); // Spec specifies 15 bytes
}
}
@@ -0,0 +1,52 @@
package seng302.gameServer.server;
import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.assertTrue;
import org.junit.Test;
import seng302.gameServer.server.messages.Message;
import seng302.gameServer.server.messages.XMLMessage;
import seng302.gameServer.server.messages.XMLMessageSubType;
public class TestMessage {
private static int XML_MESSAGE_LEN = 14;
private static int CRC_LEN = 4;
/**
* Test output expected is the same as the spec
*/
@Test
public void testXmlMessageSize(){
Message m = new XMLMessage("12345", XMLMessageSubType.BOAT, 1);
assertTrue(m.getSize() == (XML_MESSAGE_LEN + "12345".length()));
}
@Test
public void testMessageBytesReverse(){
byte[] bytes = {1,2,3,4,5};
Message.reverse(bytes);
int testValue = 1;
for (int i = 5; i > 0; i--){
assertEquals((byte) testValue, bytes[i-1]);
testValue++;
}
}
@Test
public void testIntToByteArray(){
long originalValue = 0x5050;
long testValue = 0;
byte[] bytes = Message.intToByteArray(originalValue, 6);
Message.reverse(bytes);
for (int i = 0; i < bytes.length; i++){
testValue += ((long) bytes[i] & 0xffL) << (8 * i);
}
assertEquals(originalValue, testValue);
}
}
@@ -0,0 +1,76 @@
package seng302.gameServer.server.simulator;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import seng302.model.GeoPoint;
import seng302.utilities.GeoUtility;
/**
* To test methods in GeoUtility.
* Created by Haoming on 28/04/17.
*/
public class GeoUtilityTest {
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);
private double toleranceRate = 0.01;
@Test
public void getDistance() throws Exception {
double expected, actual;
actual = GeoUtility.getDistance(p1, p2);
expected = 1000;
assertEquals(expected, actual, expected * toleranceRate);
actual = GeoUtility.getDistance(p1, p3);
expected = 927;
assertEquals(expected, actual, expected * toleranceRate);
actual = GeoUtility.getDistance(p2, p4);
expected = 7430180;
assertEquals(expected, actual, expected * toleranceRate);
}
@Test
public void getBearing() throws Exception {
double expected, actual;
actual = GeoUtility.getBearing(p1, p2);
expected = 82;
assertEquals(expected, actual, expected * toleranceRate);
actual = GeoUtility.getBearing(p1, p3);
expected = 86;
assertEquals(expected, actual, expected * toleranceRate);
actual = GeoUtility.getBearing(p2, p4);
expected = 78;
assertEquals(expected, actual, expected * toleranceRate);
}
@Test
public void getGeoCoordinate() throws Exception {
GeoPoint expected, actual;
actual = GeoUtility.getGeoCoordinate(p1, 82.0, 1000.0);
expected = p2;
assertEquals(expected.getLat(), actual.getLat(), expected.getLat() * toleranceRate);
assertEquals(expected.getLng(), actual.getLng(), expected.getLng() * toleranceRate);
actual = GeoUtility.getGeoCoordinate(p1, 86.0, 927.0);
expected = p3;
assertEquals(expected.getLat(), actual.getLat(), expected.getLat() * toleranceRate);
assertEquals(expected.getLng(), actual.getLng(), expected.getLng() * toleranceRate);
actual = GeoUtility.getGeoCoordinate(p2, 78.0, 7430180.0);
expected = p4;
assertEquals(expected.getLat(), actual.getLat(), expected.getLat() * toleranceRate);
assertEquals(expected.getLng(), actual.getLng(), expected.getLng() * toleranceRate);
}
}