Merge remote-tracking branch 'origin/develop' into Story66_Collision

# Conflicts:
#	src/main/java/seng302/gameServer/GameState.java
#	src/main/java/seng302/gameServer/MainServerThread.java
#	src/main/java/seng302/gameServer/ServerToClientThread.java
#	src/main/java/seng302/model/Yacht.java
#	src/main/java/seng302/model/mark/MarkOrder.java
#	src/main/java/seng302/visualiser/GameView.java
#	src/main/java/seng302/visualiser/controllers/RaceViewController.java
This commit is contained in:
Zhi You Tan
2017-08-15 14:30:01 +12:00
42 changed files with 1106 additions and 477 deletions
-22
View File
@@ -1,22 +0,0 @@
package seng302;
import org.junit.Test;
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,6 +1,8 @@
package seng302.model.mark;
import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
import java.util.List;
@@ -1,16 +1,15 @@
package seng302.models;
import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.assertFalse;
import static junit.framework.TestCase.assertTrue;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import seng302.model.mark.CompoundMark;
import seng302.model.mark.Mark;
import seng302.model.mark.MarkOrder;
import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.assertFalse;
import static junit.framework.TestCase.assertTrue;
public class MarkOrderTest {
private static MarkOrder markOrder;
private static Integer currentSeqID;
@@ -0,0 +1,87 @@
package seng302.models;
import static org.junit.Assert.assertEquals;
import java.util.HashMap;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import seng302.gameServer.GameState;
import seng302.model.PolarTable;
import seng302.model.Yacht;
public class YachtTest {
private static Yacht y1;
//Yacht y2;
private static Double windDirection = 180d;
private static Double windSpeed = 20d;
private static GameState gs;
@BeforeClass
public static void setUp() {
y1 = new Yacht("Yacht", 101, "Y1", "Y1", "Yacht 1", "C1");
gs = new GameState("localhost");
}
@Test
public void tackGybeTest() {
HashMap<Double, Double> values = new HashMap<>();
values.put(280.0, 80.0);
values.put(270.0, 90.0);
values.put(359.0, 1.0);
values.put(180.0, 180.0);
values.put(75.0, 285.0);
for (Double begin : values.keySet()) {
y1.setHeading(begin);
y1.tackGybe(windDirection);
for (int i = 0; i < 200; i++) {
y1.runAutoPilot();
}
assertEquals(values.get(begin), y1.getHeading(), 5.0);
}
}
@Test
public void vmgTest() {
PolarTable.parsePolarFile(getClass().getResourceAsStream("/config/acc_polars.csv"));
Double upwind = PolarTable.getOptimalUpwindVMG(windSpeed).keySet().iterator().next();
Double downwind = PolarTable.getOptimalDownwindVMG(windSpeed).keySet().iterator().next();
HashMap<Double, Double> values = new HashMap<>();
upwind = (double) Math.floorMod(upwind.longValue() + windDirection.longValue(), 360L);
Double upwindRight = upwind;
Double upwindLeft = 360 - upwindRight;
downwind = (double) Math.floorMod(downwind.longValue() + windDirection.longValue(), 360L);
Double downwindRight = downwind;
Double downwindLeft = 360 - downwindRight;
values.put(190d, upwindRight);
values.put(170d, upwindLeft);
values.put(10d, downwindLeft);
values.put(350d, downwindRight);
for (Double begin : values.keySet()) {
y1.setHeading(begin);
y1.turnToVMG();
for (int i = 0; i < 200; i++) {
y1.runAutoPilot();
}
y1.disableAutoPilot();
assertEquals(values.get(begin), y1.getHeading(), 5.0);
}
}
@AfterClass
public static void tearDown() {
y1 = null;
}
}
@@ -0,0 +1,80 @@
package seng302.visualiser.ClientToServerTests;
import java.util.ArrayList;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import seng302.gameServer.GameStages;
import seng302.gameServer.GameState;
import seng302.gameServer.MainServerThread;
import seng302.gameServer.server.messages.BoatAction;
import seng302.model.Yacht;
import seng302.visualiser.ClientToServerThread;
/**
* Test for checking how regularly packets are sent from ClientToServer Thread.
*/
public class RegularPacketsTest {
private MainServerThread serverThread;
private ClientToServerThread clientThread;
@Before
public void setup() throws Exception {
new GameState("localhost");
serverThread = new MainServerThread();
clientThread = new ClientToServerThread("localhost", 4942);
GameState.setCurrentStage(GameStages.RACING);
}
@Test
public void packetsSentAtRegularIntervals () throws Exception {
final double TEST_DISTANCE = 10.0;
serverThread.startGame();
SleepThreadMaxDelay();
Yacht yacht = new ArrayList<>(GameState.getYachts().values()).get(0);
double startAngle = yacht.getHeading();
long startTime = System.currentTimeMillis();
clientThread.sendBoatAction(BoatAction.UPWIND);
Thread.sleep(200);
while (Math.abs(yacht.getHeading() - startAngle) < TEST_DISTANCE) {
Thread.sleep(1);
}
clientThread.sendBoatAction(BoatAction.MAINTAIN_HEADING);
long endTime = System.currentTimeMillis();
SleepThreadMaxDelay();
//Allowed to be two loops of delay due to loop delay and processing delay at client + server ends.
Assert.assertEquals(TEST_DISTANCE / Yacht.TURN_STEP * ClientToServerThread.PACKET_SENDING_INTERVAL_MS,
(endTime - startTime), 2 * ClientToServerThread.PACKET_SENDING_INTERVAL_MS);
}
// @Test
// public void testArbitraryPacketSent() throws Exception {
// serverThread.startGame();
// SleepThreadMaxDelay();
// Yacht yacht = new ArrayList<>(GameState.getYachts().values()).get(0);
// boolean startState = yacht.getSailIn();
// clientThread.sendBoatAction(BoatAction.SAILS_IN);
// SleepThreadMaxDelay();
// Assert.assertEquals(startState, !yacht.getSailIn());
// }
/**
* Give time for processing and packet sending. 200ms listed as absolute maximum for an
* acceptable delay.
* @throws Exception Thrown if thread crashes or something
*/
private void SleepThreadMaxDelay() throws Exception {
Thread.sleep(200);
}
@After
public void teardown () throws Exception {
clientThread.setSocketToClose();
serverThread.terminate();
GameState.setCurrentStage(GameStages.LOBBYING);
for (int i = 0; i<20; i++)
SleepThreadMaxDelay(); //Make sure socket is closed and toolkit remade.
}
}
@@ -1,4 +1,4 @@
package seng302.visualizer.annotations;
package seng302.visualiser.annotations;
import static org.junit.Assert.assertEquals;
@@ -0,0 +1,31 @@
package seng302.visualiser.map;
import static junit.framework.TestCase.assertFalse;
import static junit.framework.TestCase.assertTrue;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import seng302.model.Yacht;
import seng302.visualiser.fxObjects.BoatObject;
/**
* Created by kre39 on 6/08/17.
*/
public class BoatSailAnimationToggleTest {
private Yacht yacht;
@Before
public void setup() throws Exception{
yacht = new Yacht("Yacht", 1, "YACHT", "YAC", "Test Yacht", "NZ");
}
@Test
public void sailToggleTest() throws Exception {
assertFalse(yacht.getSailIn());
yacht.toggleClientSail();
assertFalse(yacht.getSailIn());
}
}