mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 14:28:43 +00:00
Changed package heirachy. Merged Controller and StartScreenController.
#refactor
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
package seng302.model.map;
|
||||
|
||||
import org.junit.Test;
|
||||
import seng302.utilities.GeoPoint;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Unit test for Mercator Project class.
|
||||
* Created by hyi25 on 15/05/17.
|
||||
*/
|
||||
public class MercatorProjectionTest {
|
||||
@Test
|
||||
public void toMapPoint() throws Exception {
|
||||
GeoPoint geo1 = new GeoPoint(12.485394, 19.38947);
|
||||
javafx.geometry.Point2D actualPoint1 = MercatorProjection.toMapPoint(geo1);
|
||||
javafx.geometry.Point2D expectedPoint1 = new javafx.geometry.Point2D(141.78806755555556, 119.0503853635612);
|
||||
assertEquals(expectedPoint1.getX(), actualPoint1.getX(), 0.0001);
|
||||
assertEquals(expectedPoint1.getY(), actualPoint1.getY(), 0.0001);
|
||||
|
||||
GeoPoint geo2 = new GeoPoint(77.456432, -23.456462);
|
||||
javafx.geometry.Point2D actualPoint2 = MercatorProjection.toMapPoint(geo2);
|
||||
javafx.geometry.Point2D expectedPoint2 = new javafx.geometry.Point2D(111.31984924444444, 38.03143323746788);
|
||||
assertEquals(expectedPoint2.getX(), actualPoint2.getX(), 0.0001);
|
||||
assertEquals(expectedPoint2.getY(), actualPoint2.getY(), 0.0001);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void toMapGeo() throws Exception {
|
||||
javafx.geometry.Point2D point1 = new javafx.geometry.Point2D(123.1234, 25.4565);
|
||||
GeoPoint actualGeo1 = MercatorProjection.toMapGeo(point1);
|
||||
GeoPoint expectedGeo1 = new GeoPoint(80.77043127275441, -6.857718749999995);
|
||||
assertEquals(expectedGeo1.getLat(), actualGeo1.getLat(), 0.0001);
|
||||
assertEquals(expectedGeo1.getLng(), actualGeo1.getLng(), 0.0001);
|
||||
|
||||
javafx.geometry.Point2D point2 = new javafx.geometry.Point2D(1.235, 255.4565);
|
||||
GeoPoint actualGeo2 = MercatorProjection.toMapGeo(point2);
|
||||
GeoPoint expectedGeo2 = new GeoPoint(-84.98475532898011, -178.26328125);
|
||||
assertEquals(expectedGeo2.getLat(), actualGeo2.getLat(), 0.0001);
|
||||
assertEquals(expectedGeo2.getLng(), actualGeo2.getLng(), 0.0001);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package seng302.model.mark;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Created by Haoming on 17/3/17.
|
||||
*/
|
||||
public class MarkTest {
|
||||
|
||||
private SingleMark singleMark1;
|
||||
private SingleMark singleMark2;
|
||||
private GateMark gateMark;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
this.singleMark1 = new SingleMark("testMark_SM1", 12.23234, -34.342, 1, 0);
|
||||
this.singleMark2 = new SingleMark("testMark_SM2", 12.23239, -34.352, 2, 1);
|
||||
this.gateMark = new GateMark("testMark_GM", MarkType.OPEN_GATE, singleMark1, singleMark2, singleMark1.getLatitude(), singleMark2.getLongitude(), 2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getName() throws Exception {
|
||||
assertEquals("testMark_SM1", this.singleMark1.getName());
|
||||
assertEquals("testMark_GM", this.gateMark.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getMarkType() throws Exception {
|
||||
assertTrue(this.singleMark2.getMarkType() == MarkType.SINGLE_MARK);
|
||||
assertTrue(this.gateMark.getMarkType() == MarkType.OPEN_GATE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getMarkContent() throws Exception {
|
||||
assertEquals(12.23234, this.singleMark1.getLatitude(), 1e-10);
|
||||
assertEquals(-34.342, this.singleMark1.getLongitude(), 1e-10);
|
||||
assertEquals("testMark_SM1", this.gateMark.getSingleMark1().getName());
|
||||
assertEquals(-34.352, this.gateMark.getSingleMark2().getLongitude(), 1e-10);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
package seng302.model.stream;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.*;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.Socket;
|
||||
import java.util.Comparator;
|
||||
import java.util.concurrent.PriorityBlockingQueue;
|
||||
import seng302.model.stream.packets.StreamPacket;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* Created by ptg19 on 26/04/17.
|
||||
*/
|
||||
public class StreamReceiverTest {
|
||||
|
||||
private PriorityBlockingQueue pq;
|
||||
private byte[] brokenPacket = {0x47, (byte) 0x83, 37, // sync1 sync2 and message type
|
||||
0b00000000, 0b01000000, 0b00100010, 0b00100100, 0b00011000, 0b00000000, //timestamp
|
||||
0b00000000, 0b00010000, 0b01000000, 0b00000000, //source id
|
||||
0b00100010, 0b00101000, // message length
|
||||
0b00010010, 0b00010010, 0b00010010}; //random start of payload
|
||||
|
||||
private byte[] workingPacket = {0x47, (byte) 0x83, 37, // sync1 sync2 and message type
|
||||
0b00000000, 0b01000000, 0b00100010, 0b00100100, 0b00011000, 0b00000000, //timestamp
|
||||
0b00000000, 0b00010000, 0b01000000, 0b00000000, //source id
|
||||
0b00000010, 0b00000000, // message length
|
||||
0b00010010, 0b00010010, // payload
|
||||
0b00100110, (byte)0b10000111, 0b00110101, 0b01111000}; //crc
|
||||
|
||||
private byte[] crcMismatchPacket = {0x47, (byte) 0x83, 37, // sync1 sync2 and message type
|
||||
0b00000000, 0b01000000, 0b00100010, 0b00100100, 0b00011000, 0b00000000, //timestamp
|
||||
0b00000000, 0b00000000, 0b01000000, 0b00000000, //source id
|
||||
0b00000010, 0b00000000, // message length
|
||||
0b00010010, 0b00010010, // payload
|
||||
0b00100110, (byte)0b10000111, 0b00110101, 0b01111000}; //crc
|
||||
|
||||
|
||||
@Before
|
||||
public void setup(){
|
||||
pq = new PriorityBlockingQueue<>(256, new Comparator<StreamPacket>() {
|
||||
@Override
|
||||
public int compare(StreamPacket s1, StreamPacket s2) {
|
||||
return (int) (s1.getTimeStamp() - s2.getTimeStamp());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void connectExitsOnUnexpectedStreamEnd() throws Exception {
|
||||
Socket host=mock(Socket.class);
|
||||
InputStream stream = new ByteArrayInputStream(brokenPacket);
|
||||
when(host.getInputStream()).thenReturn(stream);
|
||||
StreamReceiver streamReceiver = new StreamReceiver(host, pq);
|
||||
|
||||
streamReceiver.connect();
|
||||
assert pq.size() == 0;
|
||||
}
|
||||
|
||||
// @Test
|
||||
// public void connectReadsAPacket() throws Exception {
|
||||
// Socket host=mock(Socket.class);
|
||||
// InputStream stream = new ByteArrayInputStream(workingPacket);
|
||||
// when(host.getInputStream()).thenReturn(stream);
|
||||
// StreamReceiver streamReceiver = new StreamReceiver(host, pq);
|
||||
//
|
||||
// streamReceiver.connect();
|
||||
// assert pq.size() == 1;
|
||||
// }
|
||||
|
||||
@Test
|
||||
public void connectDropsAMismatchedCrc() throws Exception {
|
||||
Socket host=mock(Socket.class);
|
||||
InputStream stream = new ByteArrayInputStream(crcMismatchPacket);
|
||||
when(host.getInputStream()).thenReturn(stream);
|
||||
StreamReceiver streamReceiver = new StreamReceiver(host, pq);
|
||||
|
||||
streamReceiver.connect();
|
||||
assert pq.size() == 0;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bytestoLongTest() {
|
||||
Socket host=mock(Socket.class);
|
||||
StreamReceiver streamReceiver = new StreamReceiver(host, pq);
|
||||
try {
|
||||
Class[] args = new Class[1];
|
||||
args[0] = byte[].class;
|
||||
Method bytesToLong = streamReceiver.getClass().getDeclaredMethod("bytesToLong", args);
|
||||
bytesToLong.setAccessible(true);
|
||||
byte[] sevenBtyeNumber = {0b01100100, 0b00110100, 0b00010100, 0b00000000, 0b00000000, 0b00000000, (byte)0b10000000};
|
||||
assert bytesToLong.invoke(streamReceiver, sevenBtyeNumber).equals(36028797020288100L);
|
||||
byte[] eightByteNumber = {0b01100100, 0b00110100, 0b00010100, 0b00000000, 0b00000000, 0b00000000, (byte)0b10000000, 0b00100101};
|
||||
assert bytesToLong.invoke(streamReceiver, eightByteNumber).equals(-1L);
|
||||
byte[] emptyArray = {};
|
||||
assert bytesToLong.invoke(streamReceiver, emptyArray).equals(0L);
|
||||
} catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user