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