Merge branch 'master' into story77

# Conflicts:
#	racevisionGame/src/main/java/mock/app/Event.java
#	racevisionGame/src/main/java/visualiser/Controllers/HostController.java
#	racevisionGame/src/main/java/visualiser/model/View3D.java
This commit is contained in:
hba56
2017-09-08 17:28:17 +12:00
79 changed files with 2957 additions and 663 deletions
@@ -1,5 +1,7 @@
package mock.model;
import mock.model.wind.ConstantWindGenerator;
import mock.model.wind.WindGenerator;
import org.junit.Before;
import org.junit.Test;
import shared.model.Bearing;
@@ -3,6 +3,7 @@ package mock.model;
import org.junit.Before;
import org.junit.Test;
import shared.model.Bearing;
import shared.model.Boat;
import shared.model.GPSCoordinate;
import shared.model.Mark;
@@ -13,6 +14,13 @@ public class MockBoatTest {
private Mark near;
private Mark far;
public static MockBoat createMockBoat() {
Boat boat = new Boat(121, "Test boat", "TS");
MockBoat mockBoat = new MockBoat(boat, null);
return mockBoat;
}
@Before
public void setUp() {
boat = new MockBoat(0, "Bob", "NZ", null);
@@ -1,7 +1,8 @@
package mock.model;
import mock.dataInput.PolarParserTest;
import network.Messages.LatestMessages;
import mock.model.wind.ConstantWindGenerator;
import mock.model.wind.WindGenerator;
import shared.dataInput.*;
import shared.exceptions.InvalidBoatDataException;
import shared.exceptions.InvalidRaceDataException;
@@ -9,8 +10,6 @@ import shared.exceptions.InvalidRegattaDataException;
import shared.model.Bearing;
import shared.model.Constants;
import static org.junit.Assert.*;
public class MockRaceTest {
//TODO
@@ -0,0 +1,141 @@
package mock.model;
import mock.dataInput.PolarParser;
import org.junit.Before;
import org.junit.Test;
import shared.model.Bearing;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.*;
/**
* Created by fwy13 on 5/09/17.
*/
public class NewPolarsTest {
@Before
public void setUp(){
PolarParser.parseNewPolars("mock/polars/acc_polars.csv");
NewPolars.linearInterpolatePolars();
// Uncomment if you want to read the linear interpolation in text
// Method getPolars = null;
// try {
// getPolars = NewPolars.class.getDeclaredMethod("printOutLinearInterpolated");
// } catch (NoSuchMethodException e) {
// e.printStackTrace();
// }
// getPolars.setAccessible(true);
// try {
// getPolars.invoke(NewPolars.newPolars);
// } catch (IllegalAccessException e) {
// e.printStackTrace();
// } catch (InvocationTargetException e) {
// e.printStackTrace();
// }
}
@Test
public void testQuads() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
//reflection for private class
Class[] parameterTypes = new Class[1];
parameterTypes[0] = Double.TYPE;
Method getQuads = NewPolars.class.getDeclaredMethod("getQuadrant", parameterTypes);
getQuads.setAccessible(true);
//start invoking
Object[] paras1 = new Object[1];
paras1[0] = (new Double(0)).doubleValue();
int q1 = (int) getQuads.invoke(NewPolars.newPolars, paras1);
assertEquals(q1, 1);
//start invoking
Object[] paras2 = new Object[1];
paras2[0] = (new Double(90)).doubleValue();
int q2 = (int) getQuads.invoke(NewPolars.newPolars, paras2);
assertEquals(q2, 2);
//start invoking
Object[] paras3 = new Object[1];
paras3[0] = (new Double(180)).doubleValue();
int q3 = (int) getQuads.invoke(NewPolars.newPolars, paras3);
assertEquals(q3, 3);
//start invoking
Object[] paras4 = new Object[1];
paras4[0] = (new Double(270)).doubleValue();
int q4 = (int) getQuads.invoke(NewPolars.newPolars, paras4);
assertEquals(q4, 4);
//start invoking
Object[] paras5 = new Object[1];
paras5[0] = (new Double(360)).doubleValue();
int q5 = (int) getQuads.invoke(NewPolars.newPolars, paras5);
assertEquals(q5, 1);
}
@Test
public void testEdgeSpeeds(){
//just make sure that speeds at certain angles do not throw a null exception and are not negative
double maxTWS = 30;
for (double tws = 0; tws < maxTWS; tws += 1){
for (double j = 0; j < 360; j++){
Bearing twa = Bearing.fromDegrees(j);
for (double i = 0; i < 360; i++){
Bearing boatBearing = Bearing.fromDegrees(i);
double speed = NewPolars.calculateSpeed(twa, tws, boatBearing);
assertTrue(speed >= 0);
}
}
}
}
@Test
public void testClosestSpeeds() throws NoSuchMethodException, NoSuchFieldException, InvocationTargetException, IllegalAccessException {
//reflection for private class
Method getClosest = NewPolars.class.getDeclaredMethod("getClosest", double.class, Set.class);
getClosest.setAccessible(true);
Method getPolars = NewPolars.class.getDeclaredMethod("getPolars");
getPolars.setAccessible(true);
double maxTWS = 30;
//only catches for nulls
for (double tws = 0; tws < maxTWS; tws += 1){
Map<Double, TreeMap<Double, Double>> polars = (Map<Double, TreeMap<Double, Double>>) getPolars.invoke(NewPolars.newPolars);
double speed = (double) getClosest.invoke(NewPolars.newPolars, tws, polars.keySet());
assertTrue(speed >= 0);
}
}
@Test
public void testAutoVSCalculated(){
//test that the auto chosen speed is the same speed that is calculated
double maxTWS = 30;
for (double tws = 0; tws < maxTWS; tws ++){
for (double twa = 0; twa < 360; twa ++){
Bearing TW = Bearing.fromDegrees(twa);
for (double ba = 0; ba < 360; ba ++){
Bearing boatBearing = Bearing.fromDegrees(ba);
VMG autoVMG = NewPolars.setBestVMG(TW, tws, boatBearing);
double speed = NewPolars.calculateSpeed(TW, tws, autoVMG.getBearing());
assertTrue(autoVMG.getSpeed() == speed);
}
}
}
}
}
@@ -1,5 +1,6 @@
package mock.model;
import mock.model.wind.RandomWindGenerator;
import org.junit.Before;
import org.junit.Test;
import shared.model.Bearing;
@@ -1,6 +1,7 @@
package mock.model;
import mock.exceptions.SourceIDAllocationException;
import network.Messages.Enums.RaceStatusEnum;
import org.junit.Before;
import org.junit.Test;
@@ -15,30 +16,16 @@ import static org.junit.Assert.*;
*/
public class SourceIdAllocatorTest {
/**
* This is the list of source IDs that we start with.
*/
private List<Integer> originalSourceIDs;
/**
* Used to allocate source IDs.
*/
private MockRace mockRace;
private SourceIdAllocator sourceIdAllocator;
@Before
public void setUp() throws Exception {
originalSourceIDs = new ArrayList<>();
originalSourceIDs.add(120);
originalSourceIDs.add(121);
originalSourceIDs.add(122);
originalSourceIDs.add(123);
originalSourceIDs.add(124);
originalSourceIDs.add(125);
mockRace = MockRaceTest.createMockRace();
sourceIdAllocator = new SourceIdAllocator(originalSourceIDs);
sourceIdAllocator = new SourceIdAllocator(mockRace);
}
@@ -49,11 +36,12 @@ public class SourceIdAllocatorTest {
@Test
public void emptyAllocationTest() {
SourceIdAllocator allocator = new SourceIdAllocator(new ArrayList<>());
mockRace.getRaceDataSource().getParticipants().removeAll(mockRace.getBoatDataSource().getBoats().keySet());
mockRace.getRaceDataSource().getParticipants().addAll(mockRace.getBoatDataSource().getBoats().keySet());
try {
int sourceID = allocator.allocateSourceID();
int sourceID = sourceIdAllocator.allocateSourceID();
fail("Exception should have been thrown, but wasn't.");
@@ -73,6 +61,7 @@ public class SourceIdAllocatorTest {
@Test
public void allocationTest() throws Exception {
mockRace.setRaceStatusEnum(RaceStatusEnum.PRESTART);
int sourceID = sourceIdAllocator.allocateSourceID();
@@ -108,10 +97,7 @@ public class SourceIdAllocatorTest {
@Test
public void reallocationTest() throws Exception {
List<Integer> sourceIDList = new ArrayList<>();
sourceIDList.add(123);
SourceIdAllocator sourceIdAllocator = new SourceIdAllocator(sourceIDList);
mockRace.setRaceStatusEnum(RaceStatusEnum.PRESTART);
//Allocate.
int sourceID = sourceIdAllocator.allocateSourceID();
@@ -1,11 +1,11 @@
package mock.model.commandFactory;
import mock.exceptions.CommandConstructionException;
import mock.model.MockBoat;
import mock.model.MockRace;
import mock.model.MockRaceTest;
import mock.exceptions.SourceIDAllocationException;
import mock.model.*;
import network.Messages.BoatAction;
import network.Messages.Enums.BoatActionEnum;
import network.Messages.Enums.RaceStatusEnum;
import org.junit.Before;
import org.junit.Test;
import shared.exceptions.InvalidBoatDataException;
@@ -21,6 +21,7 @@ import static org.mockito.Mockito.mock;
*/
public class WindCommandTest {
private MockRace race;
private SourceIdAllocator allocator;
private MockBoat boat;
private Command upwind;
private Command downwind;
@@ -29,12 +30,15 @@ public class WindCommandTest {
private double offset = 3.0;
@Before
public void setUp() throws CommandConstructionException, InvalidBoatDataException, InvalidRegattaDataException, InvalidRaceDataException {
public void setUp() throws CommandConstructionException, InvalidBoatDataException, InvalidRegattaDataException, InvalidRaceDataException, SourceIDAllocationException {
race = MockRaceTest.createMockRace();
allocator = new SourceIdAllocator(race);
race.setRaceStatusEnum(RaceStatusEnum.PRESTART);
allocator.allocateSourceID();
boat = race.getBoats().get(0);
//when(race.getWindDirection()).thenReturn(Bearing.fromDegrees(0.0));
boat.setBearing(Bearing.fromDegrees(45.0));
@@ -94,7 +94,7 @@ public class ConnectionToServerParticipantTest {
incomingCommands.put(command);
//Need to wait for connection thread to execute commands.
Thread.sleep(250);
Thread.sleep(500);
assertEquals(ConnectionToServerState.CONNECTED, connectionToServer.getConnectionState());
assertTrue(connectionToServer.getJoinAcceptance() != null);
@@ -5,12 +5,6 @@
<CreationTimeDate>2017-04-19T15:30:00+1200</CreationTimeDate>
<RaceStartTime Postpone="false" Time="2017-04-19T15:33:00+1200"/>
<Participants>
<Yacht SourceID="121"/>
<Yacht SourceID="122"/>
<Yacht SourceID="123"/>
<Yacht SourceID="124"/>
<Yacht SourceID="125"/>
<Yacht SourceID="126"/>
</Participants>
<CompoundMarkSequence>
<Corner CompoundMarkID="1" SeqID="1"/>
@@ -54,4 +48,4 @@
<Limit Lat="32.297164" Lon="-64.856394" SeqID="10"/>
<Limit Lat="32.296148" Lon="-64.849184" SeqID="11"/>
</CourseLimit>
</Race>
</Race>