Also got client-server handshake working. Multiple clients can connect and control their own boat. The client's boat has a larger black triangle drawn around it. Probably needs tidying up. Added isClientBoat boolean to VisualiserBoat. WindGenerator is now an interface, implemented by ConstantWindGenerator (useful for testing) and RandomWindGenerator. Added ConstantWindGeneratorTest. RandomWindGenerator was formerly WindGenerator. The WindGenerator is passed in to MockRace. CommandFactory throws a CommandConstructionException if it cannot create a command. MessageSerialiser and MessageDeserialiser correctly terminate on error. Readded VisualiserInput's switch statement in the main loop, pending a refactor. Removed the sleep statement from LobbyController - it was blocking javaFX thread. Lobby.fxml: moved buttons and text input into grid panes, so they don't break when you resize screen. Added some test object creation functions in several test classes (MockRaceTest.createMockRace(), BoatXMLReaderTest.createBoatDataSource(), etc...). #story[1095]
73 lines
1.5 KiB
Java
73 lines
1.5 KiB
Java
package mock.model;
|
|
|
|
import org.junit.Before;
|
|
import org.junit.Test;
|
|
import shared.model.Bearing;
|
|
import shared.model.Wind;
|
|
|
|
import static org.junit.Assert.*;
|
|
|
|
|
|
/**
|
|
* Tests the {@link ConstantWindGenerator}.
|
|
*/
|
|
public class ConstantWindGeneratorTest {
|
|
|
|
WindGenerator windGenerator;
|
|
Bearing windBearing;
|
|
double windSpeedKnots;
|
|
|
|
@Before
|
|
public void setUp() throws Exception {
|
|
|
|
windBearing = Bearing.fromDegrees(78.5);
|
|
windSpeedKnots = 18.54;
|
|
|
|
windGenerator = new ConstantWindGenerator(windBearing, windSpeedKnots);
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
* Tests if the {@link WindGenerator#generateBaselineWind()} function works.
|
|
*/
|
|
@Test
|
|
public void generateBaselineTest() {
|
|
|
|
int repetitions = 100;
|
|
|
|
for (int i = 0; i < repetitions; i++) {
|
|
|
|
Wind wind = windGenerator.generateBaselineWind();
|
|
|
|
assertEquals(windBearing.degrees(), wind.getWindDirection().degrees(), 0.01);
|
|
assertEquals(windSpeedKnots, wind.getWindSpeed(), 0.01);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
* Tests if the {@link WindGenerator#generateNextWind(Wind)} ()} function works.
|
|
*/
|
|
@Test
|
|
public void generateNextWindTest() {
|
|
|
|
int repetitions = 100;
|
|
|
|
Wind wind = windGenerator.generateBaselineWind();
|
|
|
|
for (int i = 0; i < repetitions; i++) {
|
|
|
|
wind = windGenerator.generateNextWind(wind);
|
|
|
|
assertEquals(windBearing.degrees(), wind.getWindDirection().degrees(), 0.01);
|
|
assertEquals(windSpeedKnots, wind.getWindSpeed(), 0.01);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|