mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 06:18:44 +00:00
Merge branch 'Story29' into merge_branch_front
# Conflicts: # src/main/java/seng302/App.java # src/main/java/seng302/controllers/CanvasController.java # src/main/java/seng302/controllers/Controller.java # src/main/java/seng302/controllers/RaceViewController.java # src/main/java/seng302/models/Boat.java # src/main/java/seng302/models/Colors.java # src/main/java/seng302/models/Event.java # src/main/java/seng302/models/Race.java # src/main/java/seng302/models/mark/GateMark.java # src/main/java/seng302/models/mark/Mark.java # src/main/java/seng302/models/mark/MarkType.java # src/main/java/seng302/models/mark/SingleMark.java # src/main/java/seng302/models/parsers/CourseParser.java # src/main/java/seng302/models/parsers/TeamsParser.java # src/main/resources/views/MainView.fxml # src/main/resources/views/RaceView.fxml # src/test/java/seng302/BoatTest.java # src/test/java/seng302/ColorsTest.java # src/test/java/seng302/EventTest.java # src/test/java/seng302/models/mark/MarkTest.java # src/test/java/seng302/models/parsers/CourseParserTest.java
This commit is contained in:
@@ -1,54 +0,0 @@
|
||||
package seng302;
|
||||
|
||||
import org.junit.Test;
|
||||
import seng302.models.Leg;
|
||||
import seng302.models.mark.SingleMark;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* Unit test for the Leg class.
|
||||
*/
|
||||
public class LegTest {
|
||||
|
||||
/**
|
||||
* Test creation of the leg by specifying a string
|
||||
* for the marker label
|
||||
*/
|
||||
@Test
|
||||
public void testLegCreationUsingMarkerLabel() {
|
||||
Leg leg = new Leg(010, 100, "SingleMark");
|
||||
|
||||
assertEquals(leg.getHeading(), 010);
|
||||
assertEquals(leg.getDistance(), 100);
|
||||
assertEquals(leg.getMarkerLabel(), "SingleMark");
|
||||
assertEquals(leg.getIsFinishingLeg(), false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test creation of the leg by providing a
|
||||
* SingleMark object
|
||||
*/
|
||||
@Test
|
||||
public void testLegCreation() {
|
||||
Leg leg = new Leg(010, 100, new SingleMark("SingleMark"));
|
||||
|
||||
assertEquals(leg.getHeading(), 010);
|
||||
assertEquals(leg.getDistance(), 100);
|
||||
assertEquals(leg.getMarkerLabel(), "SingleMark");
|
||||
assertEquals(leg.getIsFinishingLeg(), false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test changing whether or not a
|
||||
* leg is the finishing leg
|
||||
*/
|
||||
@Test
|
||||
public void testSetFinishLeg() {
|
||||
Leg leg = new Leg(010, 100, "SingleMark");
|
||||
|
||||
leg.setFinishingLeg(true);
|
||||
assertEquals(leg.getIsFinishingLeg(), true);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
package seng302;
|
||||
|
||||
import org.junit.Test;
|
||||
import seng302.models.Boat;
|
||||
import seng302.models.Race;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* Unit test for the Race class.
|
||||
*/
|
||||
public class RaceTest {
|
||||
/**
|
||||
* Test that all boats were added to the race
|
||||
*/
|
||||
@Test
|
||||
public void testAddingBoatsToRace() {
|
||||
Boat boat1 = new Boat("Team 1");
|
||||
Boat boat2 = new Boat("Team 2");
|
||||
|
||||
Race race = new Race();
|
||||
race.addBoat(boat1);
|
||||
race.addBoat(boat2);
|
||||
|
||||
assertEquals(Array.getLength(race.getBoats()), 2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetShuffledBoats(){
|
||||
Boat boat1 = new Boat("Team 1");
|
||||
Boat boat2 = new Boat("Team 2");
|
||||
|
||||
Race race = new Race();
|
||||
race.addBoat(boat1);
|
||||
race.addBoat(boat2);
|
||||
|
||||
assertEquals(Array.getLength(race.getShuffledBoats()), 2);
|
||||
}
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
package seng302;
|
||||
|
||||
import org.junit.Test;
|
||||
import seng302.controllers.RaceViewController;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
|
||||
public class TestRaceTimer {
|
||||
@Test
|
||||
public void testPositiveTimeString(){
|
||||
RaceViewController controller = new RaceViewController();
|
||||
String result = controller.convertTimeToMinutesSeconds(61);
|
||||
|
||||
assertTrue(result.equals("01:01"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNegativeTimeString(){
|
||||
RaceViewController controller = new RaceViewController();
|
||||
String result = controller.convertTimeToMinutesSeconds(-61);
|
||||
|
||||
assertTrue(result.equals("-01:01"));
|
||||
}
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
package seng302.models.parsers;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Created by Haoming on 23/03/17.
|
||||
*/
|
||||
public class ConfigParserTest {
|
||||
|
||||
private ConfigParser cp;
|
||||
|
||||
@Before
|
||||
public void initializeParser() throws Exception {
|
||||
cp = new ConfigParser("/config/config.xml");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getWindDirection() throws Exception {
|
||||
assertEquals(135, cp.getWindDirection(), 1e-10);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getTimeScale() throws Exception {
|
||||
assertEquals(10.0, cp.getTimeScale(), 1e-10);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getDoubleByTagName() throws Exception {
|
||||
assertEquals(6, cp.getDoubleByTagName("race-size", 0), 1e-10);
|
||||
assertEquals(100, cp.getDoubleByTagName("noTag", 100), 1e-10);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getStringByTagName() throws Exception {
|
||||
assertEquals("AC35", cp.getStringByTagName("race-name", "11"));
|
||||
assertEquals("oops", cp.getStringByTagName("noTag", "oops"));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
package seng302.models.parsers;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import seng302.models.Boat;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Created by Haoming on 18/03/17.
|
||||
*/
|
||||
public class TeamsParserTest {
|
||||
|
||||
private TeamsParser tp;
|
||||
@Before
|
||||
public void readFile() {
|
||||
tp = new TeamsParser("/config/teams.xml");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getBoats() throws Exception {
|
||||
ArrayList<Boat> boats = tp.getBoats();
|
||||
|
||||
assertEquals(6, boats.size(), 1e-10);
|
||||
|
||||
assertEquals("Oracle Team USA", boats.get(0).getTeamName());
|
||||
//assertEquals(30.9, boats.get(0).getVelocity(), 1e-10);
|
||||
|
||||
assertEquals("Groupama Team France", boats.get(5).getTeamName());
|
||||
//assertEquals(45.6, boats.get(5).getVelocity(), 1e-10);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package seng302.server;
|
||||
|
||||
import org.junit.Test;
|
||||
import seng302.server.messages.BoatLocationMessage;
|
||||
|
||||
import static junit.framework.TestCase.assertEquals;
|
||||
|
||||
/**
|
||||
* 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,26 @@
|
||||
package seng302.server;
|
||||
|
||||
import org.junit.Test;
|
||||
import seng302.server.messages.*;
|
||||
|
||||
import static junit.framework.TestCase.assertTrue;
|
||||
|
||||
/**
|
||||
* 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,56 @@
|
||||
package seng302.server;
|
||||
|
||||
import org.junit.Test;
|
||||
import seng302.server.messages.*;
|
||||
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static junit.framework.TestCase.assertEquals;
|
||||
import static junit.framework.TestCase.assertTrue;
|
||||
|
||||
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,75 @@
|
||||
package seng302.server.simulator;
|
||||
|
||||
import org.junit.Test;
|
||||
import seng302.server.simulator.mark.Position;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* To test methods in GeoUtility.
|
||||
* Created by Haoming on 28/04/17.
|
||||
*/
|
||||
public class GeoUtilityTest {
|
||||
|
||||
private Position p1 = new Position(57.670333, 11.827833);
|
||||
private Position p2 = new Position(57.671524, 11.844495);
|
||||
private Position p3 = new Position(57.670822, 11.843392);
|
||||
private Position p4 = new Position(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 {
|
||||
Position 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);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user