Moved several classes from seng302.model to its own module - sharedModel (this is supposed to contain any shared data model code between mock and visualiser). Specifically, Regatta, Boat, BoatInRace, Constants, GPSCoordinate, Leg, Marker.

Updated RaceVisionByteEncoder.raceStatus to accept a Racestatus object rather than a bunch of parameters.
Added getters to RaceStatus class.
Updated some tests.
Removed Network tests from Mock, as they were duplicated.
This commit is contained in:
fjc40
2017-04-28 01:27:45 +12:00
parent 50cb31b85f
commit 90f8bec415
56 changed files with 624 additions and 2749 deletions
@@ -13,11 +13,11 @@ public class BoatLocationDecoderTest {
@Test
public void getByteArrayTest(){
long time = System.currentTimeMillis();
BoatLocationMessage testMessage = new BoatLocationMessage(1, time, 2,
3, 1, 180, -180, 4, 5,
6, 7, 8, 9, 10, 11,
12, 13, 14 , 15,
16, 17, 18);
BoatLocationMessage testMessage = new BoatLocationMessage((byte) 1, time, 2,
3, (byte) 1, 180, -180, 4, 5,
(short) 6, (short) 7, 8, 9, 10, 11,
(short) 12, 13, 14 , (short) 15,
16, 17, (short) 18);
RaceVisionByteEncoder raceVisionByteEncoder = new RaceVisionByteEncoder();
byte [] testEncodedMessage = raceVisionByteEncoder.boatLocation(testMessage);
@@ -1,11 +1,10 @@
package seng302.Networking.MessageDecoders;
import javafx.scene.paint.Color;
import org.junit.Assert;
import org.junit.Test;
import seng302.Model.BoatInRace;
import seng302.Model.Leg;
import seng302.Networking.MessageEncoders.RaceVisionByteEncoder;
import seng302.Networking.Utils.BoatStatus;
import seng302.Networking.Utils.RaceStatus;
import java.util.ArrayList;
@@ -16,34 +15,54 @@ public class RaceStatusDecoderTest {
@Test
public void getByteArrayTest(){
long time = System.currentTimeMillis();
BoatInRace boat1 = new BoatInRace("Test", 1, Color.ALICEBLUE, "tt");
Leg testLeg = new Leg("test leg", 1);
boat1.setCurrentLeg(testLeg);
BoatInRace boat2 = new BoatInRace("Test2", 1, Color.ALICEBLUE, "tt");
boat2.setCurrentLeg(testLeg);
ArrayList boats = new ArrayList();
boats.add(boat1);
boats.add(boat2);
long time2 = System.currentTimeMillis();
RaceVisionByteEncoder raceVisionByteEncoder = new RaceVisionByteEncoder();
//Create data to serialize.
int boat1SourceID = 5;
int boat2SourceID = 8;
byte boat1Status = 2;
byte boat2Status = 2;
byte boat1LegNumber = 5;
byte boat2LegNumber = 3;
byte boat1PenaltiesAwarded = 4;
byte boat2PenaltiesAwarded = 0;
byte boat1PenaltiesServed = 2;
byte boat2PenaltiesServed = 0;
long boat1TimeAtNextMark = time + (1000 * 3);
long boat2TimeAtNextMark = time + (1000 * 2);
long boat1TimeAtFinish = boat1TimeAtNextMark + (1000 * 15);
long boat2TimeAtFinish = boat2TimeAtNextMark + (1000 * 7);
byte[] encodedRaceStatus = raceVisionByteEncoder.raceStatus(time, 1, 2, time2,
(short)2, (short)3,4, boats);
BoatStatus boatStatus1 = new BoatStatus(boat1SourceID, boat1Status, boat1LegNumber, boat1PenaltiesAwarded, boat1PenaltiesServed, boat1TimeAtNextMark, boat1TimeAtFinish);
BoatStatus boatStatus2 = new BoatStatus(boat2SourceID, boat2Status, boat2LegNumber, boat2PenaltiesAwarded, boat2PenaltiesServed, boat2TimeAtNextMark, boat2TimeAtFinish);
int raceID = 585;
int raceStatus = 3;
long raceStartTime = time - (1000 * 31);
int windDirection = 2341;
int windSpeed = 10201;
int raceType = 1;
ArrayList<BoatStatus> boatStatuses = new ArrayList<>(2);
boatStatuses.add(boatStatus1);
boatStatuses.add(boatStatus2);
RaceStatus raceStatusObject = new RaceStatus(time, raceID, raceStatus, raceStartTime, windDirection, windSpeed, raceType, boatStatuses);
byte[] encodedRaceStatus = RaceVisionByteEncoder.raceStatus(raceStatusObject);
RaceStatusDecoder decoderTest = new RaceStatusDecoder(encodedRaceStatus);
Assert.assertEquals(0b10, decoderTest.getVersionNum());
Assert.assertEquals(time, decoderTest.getTime());
Assert.assertEquals(1, decoderTest.getRace());
Assert.assertEquals(2, decoderTest.getRaceState());
Assert.assertEquals(time2, decoderTest.getStartTime());
Assert.assertEquals(2, decoderTest.getRaceWindDir());
Assert.assertEquals((short)3, decoderTest.getRaceWindSpeed());
Assert.assertEquals(raceID, decoderTest.getRace());
Assert.assertEquals(raceStatus, decoderTest.getRaceState());
Assert.assertEquals(raceStartTime, decoderTest.getStartTime());
Assert.assertEquals(windDirection, decoderTest.getRaceWindDir());
Assert.assertEquals(windSpeed, decoderTest.getRaceWindSpeed());
Assert.assertEquals(0, decoderTest.getBoats().get(0).getBoatStatus());
Assert.assertEquals(0, decoderTest.getBoats().get(0).getLegNumber());
Assert.assertEquals(0, decoderTest.getBoats().get(0).getNumPenaltiesAwarded());
Assert.assertEquals(boat1Status, decoderTest.getBoats().get(0).getBoatStatus());
Assert.assertEquals(boat1LegNumber, decoderTest.getBoats().get(0).getLegNumber());
Assert.assertEquals(boat1PenaltiesAwarded, decoderTest.getBoats().get(0).getNumPenaltiesAwarded());
}
}