mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 14:28:43 +00:00
Added testing.
This commit is contained in:
@@ -0,0 +1,98 @@
|
||||
package seng302.models;
|
||||
|
||||
import javafx.scene.paint.*;
|
||||
import javafx.scene.paint.Color;
|
||||
import javafx.scene.shape.Polygon;
|
||||
import javafx.scene.transform.Rotate;
|
||||
import javafx.scene.transform.Transform;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Created by cir27 on 4/05/17.
|
||||
*/
|
||||
public class BoatGroupTest {
|
||||
BoatGroup boatGroup;
|
||||
@Before
|
||||
public void setUp () {
|
||||
Boat b = new Boat("TEST", 0.0, "T" ,0);
|
||||
boatGroup = new BoatGroup(b, Color.BLACK);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setDestinationFirstUseForcesLocationUpdate () {
|
||||
boatGroup.setDestination(10, 10, 90, 0);
|
||||
Polygon bp = (Polygon) boatGroup.getChildren().get(2);
|
||||
Assert.assertTrue(10 == bp.getLayoutX());
|
||||
Assert.assertTrue(10 == bp.getLayoutY());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setDestinationFutureUseDoesntForce () {
|
||||
for (int i = 0; i < 60; i++) {
|
||||
boatGroup.setDestination(200, 200, 90, 0);
|
||||
}
|
||||
boatGroup.setDestination(210, 210, 90, 0);
|
||||
Polygon bp = (Polygon) boatGroup.getChildren().get(2);
|
||||
Assert.assertTrue(200 == bp.getLayoutX());
|
||||
Assert.assertTrue(200 == bp.getLayoutY());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setDestinationUnrealisticMovementForceUpdate () {
|
||||
Polygon bp = (Polygon) boatGroup.getChildren().get(2);
|
||||
double xLocation = bp.getLayoutX();
|
||||
double yLocation = bp.getLayoutY();
|
||||
boatGroup.setDestination(xLocation + 500, yLocation + 500, 90, 0);
|
||||
Assert.assertTrue(xLocation + 500 == bp.getLayoutX());
|
||||
Assert.assertTrue(yLocation + 500 == bp.getLayoutY());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setDestinationUnrealisticNegativeForceUpdate () {
|
||||
Polygon bp = (Polygon) boatGroup.getChildren().get(2);
|
||||
double xLocation = bp.getLayoutX();
|
||||
double yLocation = bp.getLayoutY();
|
||||
boatGroup.setDestination(xLocation - 500, yLocation - 500, 90, 0);
|
||||
Assert.assertTrue(xLocation - 500 == bp.getLayoutX());
|
||||
Assert.assertTrue(yLocation - 500 == bp.getLayoutY());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updatePositionGeneratesExpectedMovement () {
|
||||
Polygon bp = (Polygon) boatGroup.getChildren().get(2);
|
||||
double xLocation = bp.getLayoutX();
|
||||
double yLocation = bp.getLayoutY();
|
||||
int movement = 10;
|
||||
double delay = RaceObject.getExpectedUpdateInterval();
|
||||
double defaultTimePeriod = 1000 / 60;
|
||||
double expectedMovement = movement / delay * defaultTimePeriod;
|
||||
for (int i = 0; i < 60; i++) {
|
||||
boatGroup.setDestination(xLocation, yLocation, 90, 0);
|
||||
}
|
||||
boatGroup.setDestination(xLocation + 10, yLocation + 10, 90, 0);
|
||||
boatGroup.updatePosition(1000/60);
|
||||
Assert.assertEquals(expectedMovement, bp.getLayoutX() - xLocation, 0.0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void correctRaceID () {
|
||||
Assert.assertTrue(boatGroup.hasRaceId(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void incorrectRaceID () {
|
||||
Assert.assertTrue(!boatGroup.hasRaceId(2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nothingOnWrongId () {
|
||||
Polygon bp = (Polygon) boatGroup.getChildren().get(2);
|
||||
double originalX = bp.getLayoutX();
|
||||
double originalY = bp.getLayoutY();
|
||||
boatGroup.setDestination(10, 10, 90, 12);
|
||||
Assert.assertTrue(originalX == bp.getLayoutX());
|
||||
Assert.assertTrue(originalY == bp.getLayoutY());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package seng302.models;
|
||||
|
||||
import javafx.geometry.Point2D;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import seng302.models.mark.*;
|
||||
|
||||
/**
|
||||
* Created by cir27 on 4/05/17.
|
||||
*/
|
||||
public class MarkGroupTest {
|
||||
private MarkGroup gateMG;
|
||||
private MarkGroup singleMG;
|
||||
|
||||
@Before
|
||||
public void setUp () {
|
||||
Mark single = new SingleMark("SM", 0, 0 , 0);
|
||||
Mark gate = new GateMark(
|
||||
"GM",
|
||||
MarkType.OPEN_GATE,
|
||||
new SingleMark("GM1", 0, 0, 1),
|
||||
new SingleMark("GM2", 0, 0, 2),
|
||||
0,
|
||||
0);
|
||||
gateMG = new MarkGroup(gate, new Point2D(10, 10), new Point2D(20, 20));
|
||||
singleMG = new MarkGroup(single, new Point2D(0, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hasIDSingle () {
|
||||
Assert.assertTrue(singleMG.hasRaceId(0));
|
||||
Assert.assertTrue(!singleMG.hasRaceId(100,12));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hasIdGate () {
|
||||
Assert.assertTrue(gateMG.hasRaceId(1));
|
||||
Assert.assertTrue(gateMG.hasRaceId(2));
|
||||
Assert.assertTrue(!gateMG.hasRaceId(100,12));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nothingOnWrongId () {
|
||||
double originalX = singleMG.getChildren().get(0).getLayoutX();
|
||||
double originalY = singleMG.getChildren().get(0).getLayoutY();
|
||||
singleMG.setDestination(10, 10, 0, 4);
|
||||
singleMG.updatePosition(400);
|
||||
Assert.assertTrue(originalX == singleMG.getChildren().get(0).getLayoutX());
|
||||
Assert.assertTrue(originalY == singleMG.getChildren().get(0).getLayoutY());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void correctMovementCorrectId () {
|
||||
double originalX = singleMG.getChildren().get(0).getLayoutX();
|
||||
double originalY = singleMG.getChildren().get(0).getLayoutY();
|
||||
long timeinterval = 100/60;
|
||||
double expectedChange = 10 / 200 * timeinterval;
|
||||
singleMG.setDestination(originalX + 10, originalY + 10, 0, 0);
|
||||
singleMG.updatePosition(timeinterval);
|
||||
Assert.assertTrue(originalX == singleMG.getChildren().get(0).getLayoutX());
|
||||
Assert.assertTrue(originalY == singleMG.getChildren().get(0).getLayoutY());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user