Added Flight Path Tests

main
YaFedImYaEatIm 9 years ago
parent 9391b31092
commit 548b5fe321

@ -1,5 +1,7 @@
package seng202.group9.Core;
import seng202.group9.Controller.DataException;
import java.util.ArrayList;
public class FlightPath {
@ -49,7 +51,7 @@ public class FlightPath {
public void setFlightPoints(ArrayList<FlightPoint> flightPoints) {
this.flightPoints = new ArrayList<FlightPoint>();
for (int i = 0; i < flightPoints.size(); i ++) {
this.flightPoints = flightPoints;
this.flightPoints.add(flightPoints.get(i));
}
}
@ -82,7 +84,10 @@ public class FlightPath {
* gets the ID of the Flight Path.
* @return
*/
public int getID(){
public int getID() throws DataException{
if (ID == -1){
throw new DataException("This Flight Path has no ID set yet");
}
return ID;
}
@ -125,7 +130,13 @@ public class FlightPath {
* @param index
*/
public void addFlightPoint(FlightPoint flightPoint, int index){
flightPoints.add(index, flightPoint);
if (index >= flightPoints.size()){
flightPoints.add(flightPoint);
}else if (index < 0){
flightPoints.add(0, flightPoint);
}else {
flightPoints.add(index, flightPoint);
}
}
/**
@ -140,8 +151,12 @@ public class FlightPath {
* delets a point from the flight at a specific index.
* @param index
*/
public void delFlightPoint(int index){
flightPoints.remove(index);
public void delFlightPoint(int index) throws DataException{
if (flightPoints.size() > index && index >= 0) {
flightPoints.remove(index);
}else{
throw new DataException("Flight Point at Index " + index + " does not exist for this flight Path.");
}
}
/**

@ -9,6 +9,7 @@ import javafx.scene.control.*;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.input.MouseEvent;
import seng202.group9.Controller.App;
import seng202.group9.Controller.DataException;
import seng202.group9.Controller.Dataset;
import seng202.group9.Core.FlightPath;
import seng202.group9.Core.FlightPoint;
@ -121,7 +122,11 @@ public class FlightRDController extends Controller {
*/
public void load() {
theDataSet = getParent().getCurrentDataset();
currentPathId = theDataSet.getFlightPaths().get(0).getID(); //Sets the default to the 1st Path
try {
currentPathId = theDataSet.getFlightPaths().get(0).getID(); //Sets the default to the 1st Path
} catch (DataException e) {
e.printStackTrace();
}
flightIdCol.setCellValueFactory(new PropertyValueFactory<FlightPoint, String>("ID"));
flightNameCol.setCellValueFactory(new PropertyValueFactory<FlightPoint, String>("Name"));
flightTypeCol.setCellValueFactory(new PropertyValueFactory<FlightPoint, String>("Type"));

@ -0,0 +1,115 @@
package seng202.group9;/**
* Created by Gondr on 19/09/2016.
*/
import static org.junit.Assert.*;
import org.junit.Test;
import seng202.group9.Controller.DataException;
import seng202.group9.Core.FlightPath;
import seng202.group9.Core.FlightPoint;
import seng202.group9.Core.RoutePath;
import java.lang.reflect.Array;
import java.util.ArrayList;
public class FlightPathTest {
@Test
public void testConstructor(){
FlightPath flightPath = new FlightPath(1, "NZCH", "WSSS");
try {
assertTrue(flightPath.getID() == 1);
} catch (DataException e) {
fail("There is an ID set already.");
}
assertEquals(flightPath.arrivesAt(), "WSSS");
assertEquals(flightPath.departsFrom(), "NZCH");
flightPath.setArrivalAirport("WSSI");
flightPath.setDepartureAirport("NZAK");
flightPath.setID(2);
try {
assertTrue(flightPath.getID() == 2);
} catch (DataException e) {
fail("There is an ID set already.");
}
assertEquals(flightPath.arrivesAt(), "WSSI");
assertEquals(flightPath.departsFrom(), "NZAK");
}
@Test(expected = DataException.class)
public void testIDError() throws DataException{
FlightPath flightPath = new FlightPath("NZCH", "WSSS");
flightPath.getID();
}
@Test
public void testFlightPoints(){
FlightPath flightPath = new FlightPath(1, "NZCH", "WSSS");
FlightPoint startPoint = new FlightPoint("NZCH", 1, 1, "APT", "", 0, 0, 0, 0, 172.5336822, -43.48664019);
FlightPoint endPoint = new FlightPoint("WSSS", 2, 1, "APT", "", 0, 0, 0, 0, 103.995603, 1.35191714);
ArrayList<FlightPoint> flightPoints = new ArrayList<FlightPoint>();
flightPoints.add(startPoint);
flightPoints.add(endPoint);
flightPath.setFlightPoints(flightPoints);
assertTrue(flightPath.getFlightPoints().size() == 2);
assertTrue(flightPath.getFlight().size() == 2);
flightPath.delFlightPoint(endPoint);
assertTrue(flightPath.getFlightPoints().size() == 1);
flightPath.addFlightPoint(endPoint);
assertTrue(flightPath.getFlightPoints().size() == 2);
assertEquals(flightPath.getFlightPoints().get(1), endPoint);
try {
flightPath.delFlightPoint(0);
} catch (DataException e) {
fail("There is an existing point therefore it should be deletable");
}
flightPath.addFlightPoint(startPoint, 0);
assertEquals(flightPath.getFlightPoints().get(0), startPoint);
flightPath.addFlightPoint(flightPoints);
assertTrue(flightPath.getFlightPoints().size() == 4);
}
@Test
public void testAddingFlightPointAtInvalidPoints(){
FlightPath flightPath = new FlightPath(1, "NZCH", "WSSS");
FlightPoint startPoint = new FlightPoint("NZCH", 1, 1, "APT", "", 0, 0, 0, 0, 172.5336822, -43.48664019);
FlightPoint endPoint = new FlightPoint("WSSS", 2, 1, "APT", "", 0, 0, 0, 0, 103.995603, 1.35191714);
flightPath.addFlightPoint(startPoint);
flightPath.addFlightPoint(startPoint);
flightPath.addFlightPoint(startPoint);
flightPath.addFlightPoint(endPoint, -1);
flightPath.addFlightPoint(endPoint, 100);
assertEquals(flightPath.getFlightPoints().get(0), endPoint);
assertEquals(flightPath.getFlightPoints().get(4), endPoint);
}
@Test
public void getRoutePath(){
FlightPath flightPath = new FlightPath(1, "NZCH", "WSSS");
FlightPoint startPoint = new FlightPoint("NZCH", 1, 1, "APT", "", 0, 0, 0, 0, 172.5336822, -43.48664019);
FlightPoint endPoint = new FlightPoint("WSSS", 2, 1, "APT", "", 0, 0, 0, 0, 103.995603, 1.35191714);
flightPath.addFlightPoint(startPoint);
flightPath.addFlightPoint(endPoint);
RoutePath routePath = flightPath.getRoutePath();
assertTrue(routePath.getRoute().get(0).lat == 172.5336822);
assertTrue(routePath.getRoute().get(0).lng == -43.48664019);
assertTrue(routePath.getRoute().get(1).lat == 103.995603);
assertTrue(routePath.getRoute().get(1).lng == 1.35191714);
}
}
Loading…
Cancel
Save