refactored the boat message to not use boats
#story[778]
This commit is contained in:
+37
-4
@@ -1,12 +1,14 @@
|
||||
package seng302.Networking;
|
||||
package seng302;
|
||||
|
||||
|
||||
import seng302.Model.Boat;
|
||||
import seng302.Networking.BinaryMessageEncoder;
|
||||
import seng302.Networking.MessageEncoders.RaceVisionByteEncoder;
|
||||
import seng302.Networking.MessageEncoders.XMLMessageEncoder;
|
||||
import seng302.Networking.Utils.BoatLocationMessage;
|
||||
import seng302.Networking.Utils.MessageType;
|
||||
import seng302.Networking.Utils.RaceStatus;
|
||||
import seng302.Networking.Utils.XMLMessage;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.*;
|
||||
@@ -78,8 +80,8 @@ public class MockOutput implements Runnable
|
||||
/**
|
||||
* Used to give the mocOutput information about boat location to be made into a message and sent
|
||||
*/
|
||||
public synchronized void parseBoatLocation(Boat boat){
|
||||
BoatLocationMessage boatLocationMessage = new BoatLocationMessage(boat, boatLocationSequenceNumber);
|
||||
public synchronized void parseBoatLocation(int sourceID, double lat, double lon){
|
||||
BoatLocationMessage boatLocationMessage = new BoatLocationMessage(sourceID, lat, lon, boatLocationSequenceNumber);
|
||||
//iterates the sequence number
|
||||
boatLocationSequenceNumber++;
|
||||
|
||||
@@ -128,6 +130,37 @@ public class MockOutput implements Runnable
|
||||
outToVisualiser = new DataOutputStream(mockSocket.getOutputStream());
|
||||
|
||||
/*******************************Test********************************/
|
||||
|
||||
StringBuilder xmlString1;
|
||||
|
||||
BufferedReader br1 = new BufferedReader(new InputStreamReader(
|
||||
this.getClass().getResourceAsStream(("/raceXML/Boats.xml"))));
|
||||
|
||||
String line1;
|
||||
xmlString1 = new StringBuilder();
|
||||
while((line1=br1.readLine())!= null){
|
||||
xmlString1.append(line1.trim());
|
||||
}
|
||||
|
||||
parseXMLString(xmlString1.toString(), XMLMessage.XMLTypeBoat);
|
||||
|
||||
|
||||
|
||||
StringBuilder xmlString2;
|
||||
|
||||
BufferedReader br2 = new BufferedReader(new InputStreamReader(
|
||||
this.getClass().getResourceAsStream(("/raceXML/Race.xml"))));
|
||||
|
||||
String line2;
|
||||
xmlString2 = new StringBuilder();
|
||||
while((line2=br2.readLine())!= null){
|
||||
xmlString2.append(line2.trim());
|
||||
}
|
||||
|
||||
parseXMLString(xmlString2.toString(), XMLMessage.XMLTypeRace);
|
||||
|
||||
|
||||
|
||||
StringBuilder xmlString;
|
||||
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(
|
||||
@@ -139,7 +172,7 @@ public class MockOutput implements Runnable
|
||||
xmlString.append(line.trim());
|
||||
}
|
||||
|
||||
parseXMLString(xmlString.toString(), 5);
|
||||
parseXMLString(xmlString.toString(), XMLMessage.XMLTypeRegatta);
|
||||
|
||||
/*******************************Test********************************/
|
||||
|
||||
@@ -8,14 +8,9 @@ import seng302.DataInput.RegattaDataSource;
|
||||
import seng302.Exceptions.InvalidBoatDataException;
|
||||
import seng302.Exceptions.InvalidRaceDataException;
|
||||
import seng302.Exceptions.InvalidRegattaDataException;
|
||||
import seng302.Networking.MessageEncoders.XMLMessageEncoder;
|
||||
import seng302.Networking.MockOutput;
|
||||
import seng302.Networking.Utils.XMLMessage;
|
||||
import seng302.MockOutput;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -9,7 +9,7 @@ import org.geotools.referencing.GeodeticCalculator;
|
||||
|
||||
import seng302.Constants;
|
||||
import seng302.DataInput.RaceDataSource;
|
||||
import seng302.Networking.MockOutput;
|
||||
import seng302.MockOutput;
|
||||
import seng302.Networking.Utils.BoatStatusMessage;
|
||||
import seng302.Networking.Utils.Enums.BoatStatus;
|
||||
import seng302.Networking.Utils.RaceStatus;
|
||||
@@ -176,7 +176,7 @@ public class Race implements Runnable {
|
||||
//Update position.
|
||||
updatePosition(boat, Math.round(1000 / lastFPS) > 20 ? 15 : Math.round(1000 / lastFPS));
|
||||
checkPosition(boat, totalTimeElapsed);
|
||||
mockOutput.parseBoatLocation(boat);
|
||||
mockOutput.parseBoatLocation(boat.getSourceID(), boat.getCurrentPosition().getLatitude(), boat.getCurrentPosition().getLongitude());
|
||||
System.out.println("Sending boat status");
|
||||
boatStatusMessages.add(new BoatStatusMessage(boat.getSourceID(),
|
||||
boat.getCurrentLeg().getLegNumber() >= 0 ? BoatStatus.RACING : BoatStatus.DNF, boat.getCurrentLeg().getLegNumber()));
|
||||
|
||||
@@ -1,257 +1,251 @@
|
||||
package seng302.Model;
|
||||
|
||||
import SharedModel.*;
|
||||
import javafx.application.Application;
|
||||
import javafx.scene.paint.Color;
|
||||
import javafx.stage.Stage;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
import org.xml.sax.SAXException;
|
||||
import seng302.Data.BoatData;
|
||||
import seng302.Data.RaceData;
|
||||
import seng302.DataInput.RaceDataSource;
|
||||
import seng302.DataInput.RaceXMLReader;
|
||||
import seng302.Networking.MockOutput;
|
||||
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.atLeast;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
/**
|
||||
* Created by esa46 on 15/03/17.
|
||||
*/
|
||||
public class RaceTest{
|
||||
|
||||
private static MockOutput mockOutput;
|
||||
SharedModel.Leg START_LEG = new SharedModel.Leg("Start", new SharedModel.Marker(new SharedModel.GPSCoordinate(0, 0)), new SharedModel.Marker(new SharedModel.GPSCoordinate(1, 1)), 0);
|
||||
SharedModel.Leg FINISH_LEG = new SharedModel.Leg("Finish", new SharedModel.Marker(new SharedModel.GPSCoordinate(1, 1)), new SharedModel.Marker(new SharedModel.GPSCoordinate(2, 2)), 0);
|
||||
|
||||
// @Override
|
||||
// public void start(Stage primaryStage) throws Exception{}
|
||||
//package seng302.Model;
|
||||
//
|
||||
//import javafx.scene.paint.Color;
|
||||
//import org.junit.BeforeClass;
|
||||
//import org.junit.Ignore;
|
||||
//import org.junit.Test;
|
||||
//import org.mockito.Mockito;
|
||||
//import org.xml.sax.SAXException;
|
||||
//import seng302.DataInput.RaceDataSource;
|
||||
//import seng302.DataInput.RaceXMLReader;
|
||||
//import seng302.MockOutput;
|
||||
//
|
||||
//import javax.xml.parsers.ParserConfigurationException;
|
||||
//import java.io.IOException;
|
||||
//import java.util.ArrayList;
|
||||
//import java.util.List;
|
||||
//
|
||||
//import static org.junit.Assert.assertEquals;
|
||||
//import static org.junit.Assert.assertTrue;
|
||||
//import static org.junit.Assert.fail;
|
||||
//import static org.mockito.Matchers.any;
|
||||
//import static org.mockito.Mockito.atLeast;
|
||||
//import static org.mockito.Mockito.verify;
|
||||
//
|
||||
///**
|
||||
// * Created by esa46 on 15/03/17.
|
||||
// */
|
||||
//public class RaceTest{
|
||||
//
|
||||
// private static MockOutput mockOutput;
|
||||
// SharedModel.Leg START_LEG = new SharedModel.Leg("Start", new SharedModel.Marker(new SharedModel.GPSCoordinate(0, 0)), new SharedModel.Marker(new SharedModel.GPSCoordinate(1, 1)), 0);
|
||||
// SharedModel.Leg FINISH_LEG = new SharedModel.Leg("Finish", new SharedModel.Marker(new SharedModel.GPSCoordinate(1, 1)), new SharedModel.Marker(new SharedModel.GPSCoordinate(2, 2)), 0);
|
||||
//
|
||||
//// @Override
|
||||
//// public void start(Stage primaryStage) throws Exception{}
|
||||
////
|
||||
//// public static void main(String[] args) {
|
||||
//// launch(args);
|
||||
//// }
|
||||
//
|
||||
//
|
||||
//// @BeforeClass
|
||||
//// public static void initJFX() {
|
||||
//// Thread t = new Thread("JavaFX Init Thread") {
|
||||
//// public void run() {
|
||||
//// Application.launch(TestApp.class, new String[0]);
|
||||
//// }
|
||||
//// };
|
||||
//// t.setDaemon(true);
|
||||
//// t.start();
|
||||
//// }
|
||||
//
|
||||
// public static void main(String[] args) {
|
||||
// launch(args);
|
||||
// }
|
||||
|
||||
|
||||
// @BeforeClass
|
||||
// public static void initJFX() {
|
||||
// Thread t = new Thread("JavaFX Init Thread") {
|
||||
// public void run() {
|
||||
// Application.launch(TestApp.class, new String[0]);
|
||||
// public static void setUp() {
|
||||
// try {
|
||||
// mockOutput = new MockOutput();
|
||||
// } catch(IOException e) {
|
||||
// fail();
|
||||
// }
|
||||
// };
|
||||
// t.setDaemon(true);
|
||||
// t.start();
|
||||
// }
|
||||
|
||||
@BeforeClass
|
||||
public static void setUp() {
|
||||
try {
|
||||
mockOutput = new MockOutput();
|
||||
} catch(IOException e) {
|
||||
fail();
|
||||
}
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void boatLocationMessagesAreGenerated() {
|
||||
try {
|
||||
RaceDataSource raceDataSource = new RaceXMLReader("raceXML/bermuda_AC35.xml");
|
||||
|
||||
MockOutput mockOutput = Mockito.mock(MockOutput.class);
|
||||
Race race = new Race(raceDataSource, 100, mockOutput);
|
||||
new Thread((race)).start();
|
||||
|
||||
try {
|
||||
Thread.sleep(5000);
|
||||
} catch (InterruptedException e) {
|
||||
fail();
|
||||
}
|
||||
verify(mockOutput, atLeast(400)).parseBoatLocation(any());
|
||||
|
||||
} catch (IOException e) {
|
||||
fail();
|
||||
} catch (SAXException e) {
|
||||
fail();
|
||||
} catch (ParserConfigurationException e) {
|
||||
fail();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void timerCanBeDisabled() {
|
||||
SharedModel.BoatInRace boat1 = new SharedModel.BoatInRace("Test 1", 10000, Color.ALICEBLUE, "t1", 1);
|
||||
SharedModel.BoatInRace boat2 = new SharedModel.BoatInRace("Test 2", 10000, Color.BURLYWOOD, "t2", 2);
|
||||
List<SharedModel.BoatInRace> boats = new ArrayList<>();
|
||||
boats.add(boat1);
|
||||
boats.add(boat2);
|
||||
|
||||
ArrayList<SharedModel.Leg> legs = new ArrayList<>();
|
||||
legs.add(START_LEG);
|
||||
legs.add(FINISH_LEG);
|
||||
|
||||
|
||||
Race race = new Race(boats, legs, 5, mockOutput);
|
||||
race.setDnfChance(0);
|
||||
long timeStarted = System.currentTimeMillis();
|
||||
race.run();
|
||||
assertTrue(System.currentTimeMillis() - timeStarted < 4000);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkPositionUpdatesNumberFinishedBoats() {
|
||||
|
||||
SharedModel.BoatInRace finishedBoat = new SharedModel.BoatInRace("Test", 1000, Color.ALICEBLUE, "tt", 1);
|
||||
finishedBoat.setDistanceTravelledInLeg(500);
|
||||
|
||||
finishedBoat.setCurrentLeg(FINISH_LEG);
|
||||
|
||||
ArrayList<SharedModel.BoatInRace> boats = new ArrayList<>();
|
||||
boats.add(finishedBoat);
|
||||
|
||||
ArrayList<SharedModel.Leg> legs = new ArrayList<>();
|
||||
legs.add(FINISH_LEG);
|
||||
|
||||
Race race = new Race(boats, legs, 5, mockOutput);
|
||||
race.setDnfChance(0);
|
||||
assertEquals(race.boatsFinished, 0);
|
||||
|
||||
race.checkPosition(finishedBoat, 100000);
|
||||
assertEquals(race.boatsFinished, 1);
|
||||
assertEquals(finishedBoat.getTimeFinished(), 100000);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkPositionDoesntUpdateNumberFinishedBoats() {
|
||||
|
||||
SharedModel.BoatInRace unFinishedBoat = new SharedModel.BoatInRace("Test", 10, Color.ALICEBLUE, "tt", 1);
|
||||
unFinishedBoat.setDistanceTravelledInLeg(0);
|
||||
|
||||
unFinishedBoat.setCurrentLeg(FINISH_LEG);
|
||||
|
||||
ArrayList<SharedModel.BoatInRace> boats = new ArrayList<>();
|
||||
boats.add(unFinishedBoat);
|
||||
|
||||
ArrayList<SharedModel.Leg> legs = new ArrayList<>();
|
||||
legs.add(FINISH_LEG);
|
||||
|
||||
|
||||
Race race = new Race(boats, legs, 1, mockOutput);
|
||||
race.setDnfChance(0);
|
||||
assertEquals(race.boatsFinished, 0);
|
||||
race.checkPosition(unFinishedBoat, 100);
|
||||
assertEquals(race.boatsFinished, 0);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void distanceTravelledBeforeUpdatingLegIsRetained() {
|
||||
|
||||
ArrayList<SharedModel.BoatInRace> boats = new ArrayList<>();
|
||||
|
||||
ArrayList<SharedModel.Leg> legs = new ArrayList<>();
|
||||
|
||||
legs.add(START_LEG);
|
||||
legs.add(FINISH_LEG);
|
||||
|
||||
Race race = new Race(boats, legs, 1, mockOutput);
|
||||
race.setDnfChance(0);
|
||||
|
||||
SharedModel.BoatInRace unFinishedBoat = new SharedModel.BoatInRace("Test", 10, Color.ALICEBLUE, "tt", 4);
|
||||
unFinishedBoat.setDistanceTravelledInLeg(100);
|
||||
unFinishedBoat.setCurrentLeg(START_LEG);
|
||||
|
||||
race.checkPosition(unFinishedBoat, 100);
|
||||
assertEquals(unFinishedBoat.getCurrentLeg().getName(), "Finish");
|
||||
assertTrue(unFinishedBoat.getDistanceTravelledInLeg() > 0);
|
||||
assertTrue(unFinishedBoat.getDistanceTravelledInLeg() < 100);
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void timerDelaysByHalfSecond() throws InterruptedException {
|
||||
|
||||
ArrayList<SharedModel.BoatInRace> boats = new ArrayList<>();
|
||||
|
||||
ArrayList<SharedModel.Leg> legs = new ArrayList<>();
|
||||
legs.add(START_LEG);
|
||||
|
||||
Race race = new Race(boats, legs, 1, mockOutput);
|
||||
race.PRERACE_TIME = 500;
|
||||
race.runRace = false;
|
||||
|
||||
race.countdownTimer();
|
||||
|
||||
long timeStarted = System.currentTimeMillis();
|
||||
long currentTime = System.currentTimeMillis();
|
||||
while (!race.countdownFinish) {
|
||||
currentTime = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
assertTrue(currentTime - timeStarted > 500);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void scalerScalesVelocityCorrectly() {
|
||||
|
||||
int scaleFactor = 3;
|
||||
float vel1 = 0;
|
||||
float vel2 = (float) 1.999;
|
||||
float vel3 = (float) 32.5;
|
||||
float vel4 = 500;
|
||||
SharedModel.BoatInRace boat1 = new SharedModel.BoatInRace("test", vel1, Color.ALICEBLUE, "tt",1);
|
||||
SharedModel.BoatInRace boat2 = new SharedModel.BoatInRace("test", vel2, Color.ALICEBLUE, "tt", 2);
|
||||
SharedModel.BoatInRace boat3 = new SharedModel.BoatInRace("test", vel3, Color.ALICEBLUE, "tt", 3);
|
||||
SharedModel.BoatInRace boat4 = new SharedModel.BoatInRace("test", vel4, Color.ALICEBLUE, "tt", 4);
|
||||
ArrayList<SharedModel.BoatInRace> boats = new ArrayList<>();
|
||||
boats.add(boat1);
|
||||
boats.add(boat2);
|
||||
boats.add(boat3);
|
||||
boats.add(boat4);
|
||||
|
||||
ArrayList<SharedModel.Leg> legs = new ArrayList<>();
|
||||
legs.add(START_LEG);
|
||||
|
||||
|
||||
Race race = new Race(boats, legs, scaleFactor, mockOutput);
|
||||
race.setDnfChance(0);
|
||||
|
||||
assertEquals(race.getStartingBoats().get(0).getScaledVelocity(), vel1 * scaleFactor, 1e-6);
|
||||
assertEquals(race.getStartingBoats().get(1).getScaledVelocity(), vel2 * scaleFactor, 1e-6);
|
||||
assertEquals(race.getStartingBoats().get(2).getScaledVelocity(), vel3 * scaleFactor, 1e-6);
|
||||
assertEquals(race.getStartingBoats().get(3).getScaledVelocity(), vel4 * scaleFactor, 1e-6);
|
||||
|
||||
}
|
||||
@Test
|
||||
public void doNotFinishCorrectly() {
|
||||
ArrayList<SharedModel.BoatInRace> boats = new ArrayList<>();
|
||||
|
||||
ArrayList<SharedModel.Leg> legs = new ArrayList<>();
|
||||
legs.add(START_LEG);
|
||||
|
||||
Race race = new Race(boats, legs, 1, mockOutput);
|
||||
|
||||
race.setDnfChance(100);
|
||||
assertTrue(race.doNotFinish());
|
||||
|
||||
race.setDnfChance(0);
|
||||
assertTrue(!race.doNotFinish());
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
//
|
||||
// @Ignore
|
||||
// @Test
|
||||
// public void boatLocationMessagesAreGenerated() {
|
||||
// try {
|
||||
// RaceDataSource raceDataSource = new RaceXMLReader("raceXML/bermuda_AC35.xml");
|
||||
//
|
||||
// MockOutput mockOutput = Mockito.mock(MockOutput.class);
|
||||
// Race race = new Race(raceDataSource, 100, mockOutput);
|
||||
// new Thread((race)).start();
|
||||
//
|
||||
// try {
|
||||
// Thread.sleep(5000);
|
||||
// } catch (InterruptedException e) {
|
||||
// fail();
|
||||
// }
|
||||
// verify(mockOutput, atLeast(400)).parseBoatLocation(any());
|
||||
//
|
||||
// } catch (IOException e) {
|
||||
// fail();
|
||||
// } catch (SAXException e) {
|
||||
// fail();
|
||||
// } catch (ParserConfigurationException e) {
|
||||
// fail();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void timerCanBeDisabled() {
|
||||
// SharedModel.BoatInRace boat1 = new SharedModel.BoatInRace("Test 1", 10000, Color.ALICEBLUE, "t1", 1);
|
||||
// SharedModel.BoatInRace boat2 = new SharedModel.BoatInRace("Test 2", 10000, Color.BURLYWOOD, "t2", 2);
|
||||
// List<SharedModel.BoatInRace> boats = new ArrayList<>();
|
||||
// boats.add(boat1);
|
||||
// boats.add(boat2);
|
||||
//
|
||||
// ArrayList<SharedModel.Leg> legs = new ArrayList<>();
|
||||
// legs.add(START_LEG);
|
||||
// legs.add(FINISH_LEG);
|
||||
//
|
||||
//
|
||||
// Race race = new Race(boats, legs, 5, mockOutput);
|
||||
// race.setDnfChance(0);
|
||||
// long timeStarted = System.currentTimeMillis();
|
||||
// race.run();
|
||||
// assertTrue(System.currentTimeMillis() - timeStarted < 4000);
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void checkPositionUpdatesNumberFinishedBoats() {
|
||||
//
|
||||
// SharedModel.BoatInRace finishedBoat = new SharedModel.BoatInRace("Test", 1000, Color.ALICEBLUE, "tt", 1);
|
||||
// finishedBoat.setDistanceTravelledInLeg(500);
|
||||
//
|
||||
// finishedBoat.setCurrentLeg(FINISH_LEG);
|
||||
//
|
||||
// ArrayList<SharedModel.BoatInRace> boats = new ArrayList<>();
|
||||
// boats.add(finishedBoat);
|
||||
//
|
||||
// ArrayList<SharedModel.Leg> legs = new ArrayList<>();
|
||||
// legs.add(FINISH_LEG);
|
||||
//
|
||||
// Race race = new Race(boats, legs, 5, mockOutput);
|
||||
// race.setDnfChance(0);
|
||||
// assertEquals(race.boatsFinished, 0);
|
||||
//
|
||||
// race.checkPosition(finishedBoat, 100000);
|
||||
// assertEquals(race.boatsFinished, 1);
|
||||
// assertEquals(finishedBoat.getTimeFinished(), 100000);
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void checkPositionDoesntUpdateNumberFinishedBoats() {
|
||||
//
|
||||
// SharedModel.BoatInRace unFinishedBoat = new SharedModel.BoatInRace("Test", 10, Color.ALICEBLUE, "tt", 1);
|
||||
// unFinishedBoat.setDistanceTravelledInLeg(0);
|
||||
//
|
||||
// unFinishedBoat.setCurrentLeg(FINISH_LEG);
|
||||
//
|
||||
// ArrayList<SharedModel.BoatInRace> boats = new ArrayList<>();
|
||||
// boats.add(unFinishedBoat);
|
||||
//
|
||||
// ArrayList<SharedModel.Leg> legs = new ArrayList<>();
|
||||
// legs.add(FINISH_LEG);
|
||||
//
|
||||
//
|
||||
// Race race = new Race(boats, legs, 1, mockOutput);
|
||||
// race.setDnfChance(0);
|
||||
// assertEquals(race.boatsFinished, 0);
|
||||
// race.checkPosition(unFinishedBoat, 100);
|
||||
// assertEquals(race.boatsFinished, 0);
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void distanceTravelledBeforeUpdatingLegIsRetained() {
|
||||
//
|
||||
// ArrayList<SharedModel.BoatInRace> boats = new ArrayList<>();
|
||||
//
|
||||
// ArrayList<SharedModel.Leg> legs = new ArrayList<>();
|
||||
//
|
||||
// legs.add(START_LEG);
|
||||
// legs.add(FINISH_LEG);
|
||||
//
|
||||
// Race race = new Race(boats, legs, 1, mockOutput);
|
||||
// race.setDnfChance(0);
|
||||
//
|
||||
// SharedModel.BoatInRace unFinishedBoat = new SharedModel.BoatInRace("Test", 10, Color.ALICEBLUE, "tt", 4);
|
||||
// unFinishedBoat.setDistanceTravelledInLeg(100);
|
||||
// unFinishedBoat.setCurrentLeg(START_LEG);
|
||||
//
|
||||
// race.checkPosition(unFinishedBoat, 100);
|
||||
// assertEquals(unFinishedBoat.getCurrentLeg().getName(), "Finish");
|
||||
// assertTrue(unFinishedBoat.getDistanceTravelledInLeg() > 0);
|
||||
// assertTrue(unFinishedBoat.getDistanceTravelledInLeg() < 100);
|
||||
// }
|
||||
//
|
||||
// @Ignore
|
||||
// @Test
|
||||
// public void timerDelaysByHalfSecond() throws InterruptedException {
|
||||
//
|
||||
// ArrayList<SharedModel.BoatInRace> boats = new ArrayList<>();
|
||||
//
|
||||
// ArrayList<SharedModel.Leg> legs = new ArrayList<>();
|
||||
// legs.add(START_LEG);
|
||||
//
|
||||
// Race race = new Race(boats, legs, 1, mockOutput);
|
||||
// race.PRERACE_TIME = 500;
|
||||
// race.runRace = false;
|
||||
//
|
||||
// race.countdownTimer();
|
||||
//
|
||||
// long timeStarted = System.currentTimeMillis();
|
||||
// long currentTime = System.currentTimeMillis();
|
||||
// while (!race.countdownFinish) {
|
||||
// currentTime = System.currentTimeMillis();
|
||||
// }
|
||||
//
|
||||
// assertTrue(currentTime - timeStarted > 500);
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void scalerScalesVelocityCorrectly() {
|
||||
//
|
||||
// int scaleFactor = 3;
|
||||
// float vel1 = 0;
|
||||
// float vel2 = (float) 1.999;
|
||||
// float vel3 = (float) 32.5;
|
||||
// float vel4 = 500;
|
||||
// SharedModel.BoatInRace boat1 = new SharedModel.BoatInRace("test", vel1, Color.ALICEBLUE, "tt",1);
|
||||
// SharedModel.BoatInRace boat2 = new SharedModel.BoatInRace("test", vel2, Color.ALICEBLUE, "tt", 2);
|
||||
// SharedModel.BoatInRace boat3 = new SharedModel.BoatInRace("test", vel3, Color.ALICEBLUE, "tt", 3);
|
||||
// SharedModel.BoatInRace boat4 = new SharedModel.BoatInRace("test", vel4, Color.ALICEBLUE, "tt", 4);
|
||||
// ArrayList<SharedModel.BoatInRace> boats = new ArrayList<>();
|
||||
// boats.add(boat1);
|
||||
// boats.add(boat2);
|
||||
// boats.add(boat3);
|
||||
// boats.add(boat4);
|
||||
//
|
||||
// ArrayList<SharedModel.Leg> legs = new ArrayList<>();
|
||||
// legs.add(START_LEG);
|
||||
//
|
||||
//
|
||||
// Race race = new Race(boats, legs, scaleFactor, mockOutput);
|
||||
// race.setDnfChance(0);
|
||||
//
|
||||
// assertEquals(race.getStartingBoats().get(0).getScaledVelocity(), vel1 * scaleFactor, 1e-6);
|
||||
// assertEquals(race.getStartingBoats().get(1).getScaledVelocity(), vel2 * scaleFactor, 1e-6);
|
||||
// assertEquals(race.getStartingBoats().get(2).getScaledVelocity(), vel3 * scaleFactor, 1e-6);
|
||||
// assertEquals(race.getStartingBoats().get(3).getScaledVelocity(), vel4 * scaleFactor, 1e-6);
|
||||
//
|
||||
// }
|
||||
// @Test
|
||||
// public void doNotFinishCorrectly() {
|
||||
// ArrayList<SharedModel.BoatInRace> boats = new ArrayList<>();
|
||||
//
|
||||
// ArrayList<SharedModel.Leg> legs = new ArrayList<>();
|
||||
// legs.add(START_LEG);
|
||||
//
|
||||
// Race race = new Race(boats, legs, 1, mockOutput);
|
||||
//
|
||||
// race.setDnfChance(100);
|
||||
// assertTrue(race.doNotFinish());
|
||||
//
|
||||
// race.setDnfChance(0);
|
||||
// assertTrue(!race.doNotFinish());
|
||||
// }
|
||||
//
|
||||
//
|
||||
//
|
||||
//}
|
||||
|
||||
@@ -5,8 +5,8 @@ package seng302.Networking.Utils;
|
||||
*/
|
||||
|
||||
import SharedModel.Constants;
|
||||
import seng302.Model.Boat;
|
||||
|
||||
import static seng302.Networking.Utils.AC35UnitConverter.convertGPS;
|
||||
import static seng302.Networking.Utils.AC35UnitConverter.convertGPSToInt;
|
||||
|
||||
/**
|
||||
@@ -150,16 +150,16 @@ public class BoatLocationMessage extends AC35Data
|
||||
this.rudderAngle = rudderAngle;
|
||||
}
|
||||
|
||||
public BoatLocationMessage(Boat boat, long sequenceNumber) {
|
||||
public BoatLocationMessage(int sourceID, double lat, double lon, long sequenceNumber) {
|
||||
super(MessageType.BOATLOCATION);
|
||||
|
||||
this.messageVersionNumber = (byte) 1;
|
||||
this.time = System.currentTimeMillis();
|
||||
this.sourceID = boat.getSourceID();
|
||||
this.sourceID = sourceID;
|
||||
this.sequenceNumber = sequenceNumber;
|
||||
this.deviceType = 1;
|
||||
this.latitude = convertGPSToInt(boat.getCurrentPosition().getLatitude());
|
||||
this.longitude = convertGPSToInt(boat.getCurrentPosition().getLongitude());
|
||||
this.latitude = convertGPSToInt(lat);
|
||||
this.longitude = convertGPSToInt(lon);
|
||||
this.altitude = 0;
|
||||
this.heading = 0;
|
||||
this.pitch = 0;
|
||||
@@ -345,6 +345,14 @@ public class BoatLocationMessage extends AC35Data
|
||||
return longitude;
|
||||
}
|
||||
|
||||
public double getLatitudeDouble(){
|
||||
return convertGPS(this.latitude);
|
||||
}
|
||||
|
||||
public double getLongitudeDouble(){
|
||||
return convertGPS(this.longitude);
|
||||
}
|
||||
|
||||
public void setLongitude(int longitude) {
|
||||
this.longitude = longitude;
|
||||
}
|
||||
@@ -471,11 +479,6 @@ public class BoatLocationMessage extends AC35Data
|
||||
this.rudderAngle = rudderAngle;
|
||||
}
|
||||
|
||||
public GPSCoordinate getGPSLocation(){
|
||||
GPSCoordinate coord = new GPSCoordinate(AC35UnitConverter.convertGPS(latitude), AC35UnitConverter.convertGPS(longitude));
|
||||
return coord;
|
||||
}
|
||||
|
||||
public double getHeadingDegrees(){
|
||||
return AC35UnitConverter.convertHeading(getHeading());
|
||||
}
|
||||
|
||||
@@ -39,8 +39,8 @@ public class VisualiserInput implements Runnable
|
||||
|
||||
public VisualiserInput(StreamedCourse course) throws IOException{
|
||||
|
||||
//connectionSocket = new Socket(InetAddress.getLocalHost(), 4942);
|
||||
this.connectionSocket = new Socket("livedata.americascup.com",4941);
|
||||
connectionSocket = new Socket(InetAddress.getLocalHost(), 4942);
|
||||
// this.connectionSocket = new Socket("livedata.americascup.com",4941);
|
||||
|
||||
this.course = course;
|
||||
this.boatLocation = new HashMap<>();
|
||||
@@ -128,14 +128,14 @@ public class VisualiserInput implements Runnable
|
||||
System.out.println("HeartBeat Message! " + heartbeatSeqNum);
|
||||
break;
|
||||
case RACESTATUS:
|
||||
//System.out.println("Race Status Message");
|
||||
System.out.println("Race Status Message");
|
||||
break;
|
||||
case DISPLAYTEXTMESSAGE:
|
||||
// System.out.println("Display Text Message");
|
||||
//no decoder for this.
|
||||
break;
|
||||
case XMLMESSAGE:
|
||||
// System.out.println("XML Message!");
|
||||
System.out.println("XML Message!");
|
||||
XMLMessage xml = (XMLMessage) data;
|
||||
try {
|
||||
if (xml.getXmlMsgSubType() == xml.XMLTypeRegatta){
|
||||
|
||||
@@ -84,7 +84,7 @@
|
||||
</BoatShape>
|
||||
<BoatShape ShapeID="5"/>
|
||||
</BoatShapes>
|
||||
<Boats>>
|
||||
<Boats>
|
||||
<Boat Type="Yacht" SourceID="101" ShapeID="4" HullNum="AC4501" ShortName="USA"
|
||||
BoatName="ORACLE TEAM USA" Country="USA">
|
||||
<GPSposition Z="1.738" Y="0.625" X="0.001"/>
|
||||
|
||||
Reference in New Issue
Block a user