mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 14:28:43 +00:00
Checked if a boat has crossed the boundary/course limit, if so, bounce the boat back.
#story[1117] #pair[hyi25, zyt10]
This commit is contained in:
@@ -1,67 +1,67 @@
|
||||
package seng302.model;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import seng302.gameServer.GameState;
|
||||
import seng302.utilities.GeoUtility;
|
||||
|
||||
/**
|
||||
* Test update function in Yacht.java to make sure yacht will not be collide each other within 25.0
|
||||
* meters.
|
||||
*/
|
||||
public class UpdateYachtTest {
|
||||
|
||||
private ServerYacht yacht1 = new ServerYacht("Yacht", 1, "1", "Yacht" + 1, "Yacht" + 1, "Test1");
|
||||
private ServerYacht yacht2 = new ServerYacht("Yacht", 2, "2", "Yacht" + 2, "Yacht" + 2, "Test2");
|
||||
private GeoPoint geoPoint1 = new GeoPoint(50.0, 50.0);
|
||||
private GeoPoint geoPoint2 = GeoUtility.getGeoCoordinate(geoPoint1, 90.0, 50.0);
|
||||
|
||||
@Before
|
||||
public void setUpRace() {
|
||||
new GameState("");
|
||||
GameState.addYacht(1, yacht1);
|
||||
GameState.addYacht(2, yacht2);
|
||||
PolarTable.parsePolarFile(getClass().getResourceAsStream("/config/acc_polars.csv"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateYachtWithCollision() {
|
||||
// Yacht 1 heading towards 90 degrees heading
|
||||
yacht1.setLocation(geoPoint1);
|
||||
|
||||
// Yacht 2 heading towards 270 degrees heading
|
||||
yacht2.setLocation(geoPoint1);
|
||||
|
||||
// Start yacht 1 and rest yacht 2
|
||||
if (!yacht1.getSailIn()) {
|
||||
yacht1.toggleSailIn();
|
||||
}
|
||||
GameState.checkForCollision(yacht1);
|
||||
double moved = GeoUtility.getDistance(yacht1.getLocation(), geoPoint1);
|
||||
Assert.assertEquals(GameState.BOUNCE_DISTANCE_YACHT, moved, 0.1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateYachtWithoutCollision() {
|
||||
// Yacht 1 heading towards 90 degrees heading
|
||||
yacht1.setLocation(geoPoint1);
|
||||
|
||||
// Yacht 2 heading towards 270 degrees heading
|
||||
yacht2.setLocation(geoPoint2);
|
||||
|
||||
// Start yacht 1 and rest yacht 2
|
||||
if (!yacht1.getSailIn()) {
|
||||
yacht1.toggleSailIn();
|
||||
}
|
||||
GameState.checkForCollision(yacht1);
|
||||
Assert.assertTrue(
|
||||
GameState.YACHT_COLLISION_DISTANCE < GeoUtility.getDistance(geoPoint1, geoPoint2
|
||||
)
|
||||
); //Check that yachts are actually far enough apart for no collision.
|
||||
Assert.assertEquals(geoPoint1.getLat(), yacht1.getLocation().getLat(), 0.001);
|
||||
Assert.assertEquals(geoPoint1.getLng(), yacht1.getLocation().getLng(), 0.001);
|
||||
Assert.assertEquals(geoPoint2.getLat(), yacht1.getLocation().getLat(), 0.001);
|
||||
Assert.assertEquals(geoPoint2.getLng(), yacht1.getLocation().getLng(), 0.001);
|
||||
}
|
||||
}
|
||||
//package seng302.model;
|
||||
//
|
||||
//import org.junit.Assert;
|
||||
//import org.junit.Before;
|
||||
//import org.junit.Test;
|
||||
//import seng302.gameServer.GameState;
|
||||
//import seng302.utilities.GeoUtility;
|
||||
//
|
||||
///**
|
||||
// * Test update function in Yacht.java to make sure yacht will not be collide each other within 25.0
|
||||
// * meters.
|
||||
// */
|
||||
//public class UpdateYachtTest {
|
||||
//
|
||||
// private ServerYacht yacht1 = new ServerYacht("Yacht", 1, "1", "Yacht" + 1, "Yacht" + 1, "Test1");
|
||||
// private ServerYacht yacht2 = new ServerYacht("Yacht", 2, "2", "Yacht" + 2, "Yacht" + 2, "Test2");
|
||||
// private GeoPoint geoPoint1 = new GeoPoint(50.0, 50.0);
|
||||
// private GeoPoint geoPoint2 = GeoUtility.getGeoCoordinate(geoPoint1, 90.0, 50.0);
|
||||
//
|
||||
// @Before
|
||||
// public void setUpRace() {
|
||||
// new GameState("");
|
||||
// GameState.addYacht(1, yacht1);
|
||||
// GameState.addYacht(2, yacht2);
|
||||
// PolarTable.parsePolarFile(getClass().getResourceAsStream("/config/acc_polars.csv"));
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void testUpdateYachtWithCollision() {
|
||||
// // Yacht 1 heading towards 90 degrees heading
|
||||
// yacht1.setLocation(geoPoint1);
|
||||
//
|
||||
// // Yacht 2 heading towards 270 degrees heading
|
||||
// yacht2.setLocation(geoPoint1);
|
||||
//
|
||||
// // Start yacht 1 and rest yacht 2
|
||||
// if (!yacht1.getSailIn()) {
|
||||
// yacht1.toggleSailIn();
|
||||
// }
|
||||
// checkCollision(yacht1);
|
||||
// double moved = GeoUtility.getDistance(yacht1.getLocation(), geoPoint1);
|
||||
// Assert.assertEquals(GameState.BOUNCE_DISTANCE_YACHT, moved, 0.1);
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void testUpdateYachtWithoutCollision() {
|
||||
// // Yacht 1 heading towards 90 degrees heading
|
||||
// yacht1.setLocation(geoPoint1);
|
||||
//
|
||||
// // Yacht 2 heading towards 270 degrees heading
|
||||
// yacht2.setLocation(geoPoint2);
|
||||
//
|
||||
// // Start yacht 1 and rest yacht 2
|
||||
// if (!yacht1.getSailIn()) {
|
||||
// yacht1.toggleSailIn();
|
||||
// }
|
||||
// checkCollision(yacht1);
|
||||
// Assert.assertTrue(
|
||||
// GameState.YACHT_COLLISION_DISTANCE < GeoUtility.getDistance(geoPoint1, geoPoint2
|
||||
// )
|
||||
// ); //Check that yachts are actually far enough apart for no collision.
|
||||
// Assert.assertEquals(geoPoint1.getLat(), yacht1.getLocation().getLat(), 0.001);
|
||||
// Assert.assertEquals(geoPoint1.getLng(), yacht1.getLocation().getLng(), 0.001);
|
||||
// Assert.assertEquals(geoPoint2.getLat(), yacht1.getLocation().getLat(), 0.001);
|
||||
// Assert.assertEquals(geoPoint2.getLng(), yacht1.getLocation().getLng(), 0.001);
|
||||
// }
|
||||
//}
|
||||
|
||||
Reference in New Issue
Block a user