Merge branch 'unitTests'

main
YaFedImYaEatIm 9 years ago
commit 0672dfe86b

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

@ -0,0 +1,31 @@
APT,NZCH,0,-43.48664019,172.53368221
VOR,CH,400,-43.50411111,172.51463889000001
FIX,VANDA,34000,-42.421806,169.34450000000004
FIX,UKLAK,34000,-41.4245,166.71119399999998
FIX,SULON,34000,-39.858528,163
FIX,PLUGA,34000,-35.6075,154.68888900000002
FIX,CAWLY,34000,-34.326111,151.95777799999996
VOR,SY,34000,-33.94277778,151.18055556000002
NDB,KAT,34000,-33.710806,150.299622
VOR,PKS,34000,-33.131111,148.23722199999997
FIX,VIMAB,34000,-31.515277999999995,145.358611
FIX,APOMA,34000,-29.898055999999997,142.681667
FIX,POLEV,34000,-26.920277999999996,138.16916700000002
FIX,KALUG,34000,-25.900000000000006,136.72500000000002
VOR,AS,34000,-23.792889000000002,133.87820299999998
FIX,TIMMI,34000,-21.922483,130.65954399999998
FIX,TATUK,34000,-19.429444000000004,126.646389
VOR,CIN,34000,-17.588888889999993,123.85194444000001
FIX,ATMAP,34000,-12,118.255
FIX,ILDAM,34000,-10.592113999999995,116.88456400000001
VOR,BLI,34000,-8.750583329999998,115.16330556000003
FIX,SIPUT,34000,-6.283332999999999,112.58333299999998
FIX,SUMBU,34000,-4.7549999999999955,110.82333299999999
FIX,SABIL,34000,-4.019069000000002,109.93852800000002
FIX,AKULA,34000,-3.119878,108.95092499999998
FIX,APAGA,34000,-2.7826749999999976,108.580897
FIX,APARI,34000,-2.043471999999994,107.84038299999997
FIX,SANOS,34000,-0.7000000000000028,106.316667
FIX,AKTOD,34300,-0.4133329999999944,105.99305600000002
NDB,TI,8800,0.9197280000000063,104.52616899999998
APT,WSSS,0,1.3519171399999976,103.99560303999999
1 APT NZCH 0 -43.48664019 172.53368221
2 VOR CH 400 -43.50411111 172.51463889000001
3 FIX VANDA 34000 -42.421806 169.34450000000004
4 FIX UKLAK 34000 -41.4245 166.71119399999998
5 FIX SULON 34000 -39.858528 163
6 FIX PLUGA 34000 -35.6075 154.68888900000002
7 FIX CAWLY 34000 -34.326111 151.95777799999996
8 VOR SY 34000 -33.94277778 151.18055556000002
9 NDB KAT 34000 -33.710806 150.299622
10 VOR PKS 34000 -33.131111 148.23722199999997
11 FIX VIMAB 34000 -31.515277999999995 145.358611
12 FIX APOMA 34000 -29.898055999999997 142.681667
13 FIX POLEV 34000 -26.920277999999996 138.16916700000002
14 FIX KALUG 34000 -25.900000000000006 136.72500000000002
15 VOR AS 34000 -23.792889000000002 133.87820299999998
16 FIX TIMMI 34000 -21.922483 130.65954399999998
17 FIX TATUK 34000 -19.429444000000004 126.646389
18 VOR CIN 34000 -17.588888889999993 123.85194444000001
19 FIX ATMAP 34000 -12 118.255
20 FIX ILDAM 34000 -10.592113999999995 116.88456400000001
21 VOR BLI 34000 -8.750583329999998 115.16330556000003
22 FIX SIPUT 34000 -6.283332999999999 112.58333299999998
23 FIX SUMBU 34000 -4.7549999999999955 110.82333299999999
24 FIX SABIL 34000 -4.019069000000002 109.93852800000002
25 FIX AKULA 34000 -3.119878 108.95092499999998
26 FIX APAGA 34000 -2.7826749999999976 108.580897
27 FIX APARI 34000 -2.043471999999994 107.84038299999997
28 FIX SANOS 34000 -0.7000000000000028 106.316667
29 FIX AKTOD 34300 -0.4133329999999944 105.99305600000002
30 NDB TI 8800 0.9197280000000063 104.52616899999998
31 APT WSSS 0 1.3519171399999976 103.99560303999999

File diff suppressed because it is too large Load Diff

Binary file not shown.

@ -12,6 +12,10 @@ public class AirlineFilter extends Filter{
private ArrayList<Airline> baseArray;
private ArrayList<Airline> filteredList;
/**
* Constructor of the class sets the base array that will be used for filtering
* @param baseList
*/
public AirlineFilter(ArrayList<Airline> baseList){
filteredList = new ArrayList<Airline>();
baseArray = new ArrayList<Airline>();
@ -21,6 +25,10 @@ public class AirlineFilter extends Filter{
}
}
/**
* filters the list base by name case insensitive.
* @param name
*/
public void filterName(String name){
String regexCode = "(?i).*"+name+".*";
int index = 0;
@ -33,6 +41,10 @@ public class AirlineFilter extends Filter{
}
}
/**
* filters list based on alias case insensitive.
* @param alias
*/
public void filterAlias(String alias){
String regexCode = "(?i).*"+alias+".*";
int index = 0;
@ -45,6 +57,10 @@ public class AirlineFilter extends Filter{
}
}
/**
* Filters the list based on IATA code Case Insensitive.
* @param IATA
*/
public void filterIATA(String IATA){
String regexCode = "(?i).*"+IATA+".*";
int index = 0;
@ -57,6 +73,10 @@ public class AirlineFilter extends Filter{
}
}
/**
* Filters the list based on ICAO code Case Insensitive.
* @param ICAO
*/
public void filterICAO(String ICAO){
String regexCode = "(?i).*"+ICAO+".*";
int index = 0;
@ -69,6 +89,10 @@ public class AirlineFilter extends Filter{
}
}
/**
* FIlters the list based on Callsign case Insensitive.
* @param callsign
*/
public void filterCallsign(String callsign){
String regexCode = "(?i).*"+callsign+".*";
int index = 0;
@ -81,6 +105,10 @@ public class AirlineFilter extends Filter{
}
}
/**
* Filters the list based on the country case insensitive.
* @param country
*/
public void filterCountry(String country){
String regexCode = "(?i).*"+country+".*";
int index = 0;
@ -93,6 +121,10 @@ public class AirlineFilter extends Filter{
}
}
/**
* Filters the list by activity.
* @param active
*/
public void filterActive(String active){
String regexCode = "(?i).*"+active+".*";
int index = 0;
@ -105,6 +137,9 @@ public class AirlineFilter extends Filter{
}
}
/**
* resets the filtered list back to the original list.
*/
public void reset() {
filteredList = new ArrayList<Airline>();
for (Airline airline: filteredList){
@ -112,10 +147,18 @@ public class AirlineFilter extends Filter{
}
}
/**
* gets the filtered list.
* @return
*/
public ArrayList getFilteredData() {
return filteredList;
}
/**
* sets a new base list of the filter.
* @param arrayList
*/
public void setBaseList(ArrayList<Airline> arrayList) {
baseArray = new ArrayList<Airline>();
for (Airline airline: arrayList){
@ -123,6 +166,9 @@ public class AirlineFilter extends Filter{
}
}
/**
* prints the filter to the console.
*/
public void printFilter(){
for (Airline airline: filteredList){
System.out.println(airline);

@ -25,9 +25,9 @@ public class App extends Application
private ArrayList<Dataset> datasets = new ArrayList<Dataset>();
private Dataset currentDataset = null;
private Stage primaryStage = null;
private VBox mainContainer;
private Session session;
private MenuController menuController;
private VBox mainContainer = null;
private Session session = null;
private MenuController menuController = null;
public static void main( String[] args )
{
@ -65,60 +65,11 @@ public class App extends Application
//testing out dataset
try {
currentDataset = new Dataset("test's", Dataset.getExisting);
datasets.add(currentDataset);
}catch (DataException e){
e.printStackTrace();
}
/*
AirlineFilter filter = new AirlineFilter(currentDataset.getAirlines());
filter.filterName("NZ");
filter.filterAlias("flight");
filter.printFilter();
//testout single route adding
try {
currentDataset.addRoute("D2", "MAC", "WIN", "Y", "0", "NOW");
}catch (DataException e){
e.printStackTrace();
}
//testout single airport adding
try {
currentDataset.addAirport("Windows 10", "PC", "Windows", "WIN", "WIND", "0.0", "0.0", "0.0", "0.0", "U", "PC/Windows");
}catch (DataException e){
e.printStackTrace();
}
//testout single airline adding
try {
currentDataset.addAirline("Dota2", "Valve", "D2", "DOT", "Defence of the Ancients", "Steam", "Y");
}catch (DataException e){
e.printStackTrace();
}
//testing out airport parser
try {
System.out.println(currentDataset.importAirport("res/Samples/Airports.txt"));
} catch (DataException e) {
e.printStackTrace();
}
//testing out airline parser
try{
System.out.println(currentDataset.importAirline("res/Samples/Airlines.txt"));
} catch (DataException e){
e.printStackTrace();
}
//testing out route parser
try {
System.out.println(currentDataset.importRoute("res/Samples/Routes.txt"));
} catch (DataException e) {
e.printStackTrace();
}
//testing out flight parser
try {
System.out.println(currentDataset.importFlight("res/Samples/NZCH-WSSS.csv"));
} catch (DataException e) {
e.printStackTrace();
}*/
//after all loading then load the previous session
try{
FileInputStream fileIn = new FileInputStream("res/session.ser");
@ -189,8 +140,25 @@ public class App extends Application
return currentDataset;
}
public void createDataset(String datasetName) throws DataException{
Dataset newDataset = new Dataset(datasetName, Dataset.createNew);
datasets.add(newDataset);
currentDataset = newDataset;
}
public ArrayList<Dataset> getDatasets() {
return datasets;
}
public void deleteDataset(Dataset dataset){
dataset.deleteDataset();
datasets.remove(dataset);
if (dataset == currentDataset){
if (datasets.size() > 0){
currentDataset = datasets.get(0);
}else{
currentDataset = null;
}
}
}
}

@ -709,6 +709,7 @@ public class Dataset {
insertFlightPointQuery += "(" + flightPathId +", \""+ flightName +"\", \"" + flightType + "\", "+ flightAltitude + ", " +
"" + flightLatitude + ", " + flightLongitude + ")";
flightPointsToImport.get(i).setID(nextID);
flightPointsToImport.get(i).setIndexID(flightPathId);
//add data to dataset array.
//this is placed after incase the database messes up
flightPathToAdd.addFlightPoint(flightPointsToImport.get(i));
@ -739,11 +740,23 @@ public class Dataset {
public void createDataLinks(){
//this may be seperated into more sepearate function in the future for time optimisation
HashMap<String, Airline> airlineByIATA= new HashMap<String, Airline>();
for (Country country: countries){
country.setAirlines(new ArrayList<Airline>());
country.setCities(new ArrayList<City>());
}
for (City city: cities){
city.setAirports(new ArrayList<Airport>());
}
//create Airline country link
for (Airline airline: airlines){
airlineByIATA.put(airline.getIATA(), airline);
//System.out.println(airline.getAlias());
airline.setRoutes(new ArrayList<Route>());
airline.setCountry(countryDictionary.get(airline.getCountryName()));
Country country = countryDictionary.get(airline.getCountryName());
if (country != null){
country.addAirline(airline);
}
}
//create Airport City and Country Link
HashMap<String, Airport> airportsByIATA = new HashMap<String, Airport>(); //this is used later for connecting the routes
@ -757,6 +770,8 @@ public class Dataset {
//TODO Add City in country (This is extra work).
airport.setCity(cityDictionary.get(airport.getCityName()));
airport.getCity().addAirport(airport);
airport.setDepartureRoutes(new ArrayList<Route>());
airport.setArrivalRoutes(new ArrayList<Route>());
}
//set Airport variables for route
for (Route route: routes){
@ -771,6 +786,10 @@ public class Dataset {
route.setDestinationAirport(airportsByIATA.get(route.getArrivalAirport()));
}
route.setAirline(airlineByIATA.get(route.getAirlineName()));
Airline airline = airlineByIATA.get(route.getAirlineName());
if (airline != null){
airline.addRoutes(route);
}
}
System.out.println("Links Made");
}
@ -873,7 +892,11 @@ public class Dataset {
}
}
public void addAirport(Airport airportToAdd) throws DataException{
public String getName() {
return name;
}
private void addAirport(Airport airportToAdd) throws DataException{
if (airportToAdd.getIATA_FFA().length() != 0 && airportToAdd.getIATA_FFA().length() != 3){
throw new DataException("IATA/FFA either empty or 3 letters");
}
@ -907,6 +930,7 @@ public class Dataset {
ResultSet airportIDRes= stmt.executeQuery(airportIDQuery);
int airportID = 0;
while (airportIDRes.next()){
airportID = Integer.parseInt(airportIDRes.getString("seq"));
}
airportToAdd.setID(airportID);
@ -1040,7 +1064,7 @@ public class Dataset {
routeToAdd.setID(routeID);
routes.add(routeToAdd);
//routeAirline + routeSourceAirport + routeArrvAirport + routeCodeShare + routeStops + routeEquip
String routeKey = routeToAdd.getAirline() + routeToAdd.getDepartureAirport() + routeToAdd.getArrivalAirport() + routeToAdd.getCode() + routeToAdd.getStops() + routeToAdd.getEquipment();
String routeKey = routeToAdd.getAirlineName() + routeToAdd.getDepartureAirport() + routeToAdd.getArrivalAirport() + routeToAdd.getCode() + routeToAdd.getStops() + routeToAdd.getEquipment();
routeDictionary.put(routeKey, routeToAdd);
stmt.close();
c.close();
@ -1100,7 +1124,7 @@ public class Dataset {
* @param totDist
*/
public void addFlightPointToPath(int id, String name, String type, String via, String altitude, String latitude, String longitude,
String heading, String legDist, String totDist) throws DataException{
String heading, String legDist, String totDist , int index) throws DataException{
double altitudeVal = 0.0;
double latitudeVal = 0.0;
double longitudeVal = 0.0;
@ -1171,9 +1195,24 @@ public class Dataset {
FlightPoint pointToAdd = new FlightPoint(name, pointID+1, id, type, via, headingVal, altitudeVal, legDistVal,
totalDistVal,latitudeVal, longitudeVal);
flightPathDictionary.get(id).addFlightPoint(pointToAdd);
flightPathDictionary.get(Integer.valueOf(id)).addFlightPoint(pointToAdd, index);
}
public void addFlightPointToPath(FlightPoint point, int index) throws DataException{
addFlightPointToPath(point.getIndex(), point.getName(), point.getType(), point.getVia(), String.valueOf(point.getAltitude()),
String.valueOf( point.getLatitude()),String.valueOf(point.getLongitude()),
String.valueOf(point.getHeading()), String.valueOf(point.getLegDistance()), String.valueOf(point.getTotalDistance()), index);
}
public void addFlightPointToPath(FlightPoint point) throws DataException{
addFlightPointToPath(point.getIndex(), point.getName(), point.getType(), point.getVia(), String.valueOf(point.getAltitude()),
String.valueOf( point.getLatitude()),String.valueOf(point.getLongitude()),
String.valueOf(point.getHeading()), String.valueOf(point.getLegDistance()), String.valueOf(point.getTotalDistance()), -1);
}
public void addFlightPointToPath(int id, String name, String type, String via, String altitude, String latitude, String longitude,
String heading, String legDist, String totDist) throws DataException{
addFlightPointToPath(id, name, type, via, altitude, latitude, longitude, heading, legDist, totDist, -1);
}
/**
* This is called in conjunction to the App deleteDataset DO NOT CALL UNLESS THROUGH APP.DELETEDATASET
@ -1259,6 +1298,8 @@ public class Dataset {
//System.exit(0);
}
airlines.remove(airline);
airlineDictionary.remove(airline.getName());
createDataLinks();
}
public void deleteAirline(int index){
@ -1307,6 +1348,8 @@ public class Dataset {
String deleteCountry = "DELETE FROM `"+this.name+"_Country` WHERE `Country_Name` = \""+airport.getCountry().getName()+"\"";
stmt.execute(deleteCountry);
stmt.close();
countries.remove(countryDictionary.get(airport.getCountryName()));
countryDictionary.remove(airport.getCountryName());
}
//cehck if number cities that contain airports > 0 else delete the city
String countCity = "SELECT COUNT(*) FROM `"+this.name+"_Airport` JOIN `"+this.name+"_City` ON" +
@ -1325,6 +1368,8 @@ public class Dataset {
String deleteCity = "DELETE FROM `"+this.name+"_City` WHERE `City_Name` = \""+airport.getCityName()+"\"";
stmt.execute(deleteCity);
stmt.close();
cities.remove(cityDictionary.get(airport.getCityName()));
cityDictionary.remove(airport.getCityName());
}
c.close();
} catch ( Exception e ) {
@ -1332,6 +1377,8 @@ public class Dataset {
System.exit(0);
}
airports.remove(airport);
airportDictionary.remove(airport.getName());
createDataLinks();
}
public void deleteAirport(int index){
@ -1357,6 +1404,10 @@ public class Dataset {
System.exit(0);
}
routes.remove(route);
//routeAirline + routeSourceAirport + routeArrvAirport + routeCodeShare + routeStops + routeEquip
String key = route.getAirlineName() + route.getDepartureAirport() + route.getArrivalAirport() + route.getCode() + route.getStops() + route.getEquipment();
routeDictionary.remove(key);
createDataLinks();
}
public void deleteRoute(int index){
@ -1386,6 +1437,11 @@ public class Dataset {
System.exit(0);
}
flightPaths.remove(flightPath);
try {
flightPathDictionary.remove(flightPath.getID());
} catch (DataException e) {
e.printStackTrace();
}
}
public void deleteFlightPath(int index){
@ -1415,7 +1471,7 @@ public class Dataset {
}
public void deleteFlightPoint(int pathIndex, int pointIndex){
deleteFlightPoint(flightPaths.get(pathIndex).getFlightPoints().get(pointIndex), flightPaths.get(pathIndex));
deleteFlightPoint(flightPathDictionary.get(pathIndex).getFlightPoints().get(pointIndex), flightPathDictionary.get(pathIndex));
}
public ArrayList<Airline> getAirlines() {

@ -2,6 +2,7 @@ package seng202.group9.Core;
import seng202.group9.Controller.DataException;
import javax.xml.crypto.Data;
import java.util.ArrayList;
/**
@ -251,8 +252,12 @@ public class Airline{
* deletes a route by matching index keep in mind that the array position will change for all indexs after this.
* @param index
*/
public void delRoutes(int index){
routes.remove(index);
public void delRoutes(int index) throws DataException{
if (routes.size() > index && index >= 0) {
routes.remove(index);
}else{
throw new DataException("The Route at index "+index+ "does not exist to be deleted.");
}
}
/**
@ -264,7 +269,7 @@ public class Airline{
if (this.name.equals(airline.getName())){
throw new DataException("This Airline Name already Exists, Please Choose Another.");
}
if (this.name.equals("")){
if (airline.getName().equals("")){
throw new DataException("This Airline Name cannot be Empty");
}
if (!this.IATA.equals("") && this.IATA.equals(airline.getIATA())){

@ -2,6 +2,7 @@ package seng202.group9.Core;
import java.util.ArrayList;
import javafx.scene.chart.PieChart;
import seng202.group9.Controller.DataException;
/**
* Airport Class
@ -363,8 +364,31 @@ public class Airport {
* deletes a member of arrival routes by index
* @param index
*/
public void delArrivalRoutes(int index){
arrivalRoutes.remove(index);
public void delArrivalRoutes(int index) throws DataException{
if (arrivalRoutes.size() > index && index >= 0) {
arrivalRoutes.remove(index);
}else{
throw new DataException("Index "+index+" of number of Arrival Routes array size.");
}
}
/**
* deletes a member of departure routes by matching route pointer
* @param route
*/
public void delDepartureRoutes(Route route){
departureRoutes.remove(route);
}
/**
* deletes a member of departure routes by index
* @param index
*/
public void delDepartureRoutes(int index) throws DataException{
if (departureRoutes.size() > index && index >= 0) {
departureRoutes.remove(index);
}else{
throw new DataException("Index "+index+" is out of number of Departure Routes array size.");
}
}
/**
@ -376,8 +400,10 @@ public class Airport {
double distance = 0;
double dLong = this.longitude - airport.getLongitude();
double dLat = this.latitude - airport.getLatitude();
double a = Math.pow((Math.sin(dLat/2)), 2) + Math.cos(this.latitude) * Math.cos(airport.getLatitude()) * Math.pow(Math.sin(dLong/2), 2);
double c = a * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
dLong = Math.toRadians(dLong);
dLat = Math.toRadians(dLat);
double a = Math.pow((Math.sin(dLat/2)), 2) + Math.cos(Math.toRadians(this.latitude)) * Math.cos(Math.toRadians(airport.getLatitude())) * Math.pow(Math.sin(dLong/2), 2);
double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
distance = 6371 * c;
return distance;
}
@ -388,13 +414,16 @@ public class Airport {
* @throws DataException
*/
public void hasDuplicate(Airport airport) throws DataException{
if (airport.getName().equals("") || airport.getName().equals(this.name)){
if (airport.getName().equals(this.name)){
throw new DataException("Airport Name already Exists, Please Choose Another.");
}
if (!airport.getIATA_FFA().equals("") && airport.getIATA_FFA().equals(this.name)){
if (airport.getName().equals("")){
throw new DataException("Airport name cannot be Empty. Please Choose Another.");
}
if (!airport.getIATA_FFA().equals("") && airport.getIATA_FFA().equals(this.IATA_FFA)){
throw new DataException("Airport IATA/FFA already Exists, Please Choose Another.");
}
if (!airport.getICAO().equals("") && airport.getICAO().equals(this.name)){
if (!airport.getICAO().equals("") && airport.getICAO().equals(this.ICAO)){
throw new DataException("Airport ICAO already Exists, Please Choose Another.");
}
}
@ -403,7 +432,7 @@ public class Airport {
*/
@Override
public String toString(){
return this.cityName +" Airport has ICAO: "+this.ICAO+", IATA/FFA: "+this.IATA_FFA+" and is located at ("+this.latitude+", "+this.longitude
return this.name +" Airport has ICAO: "+this.ICAO+", IATA/FFA: "+this.IATA_FFA+" and is located at ("+this.latitude+", "+this.longitude
+ ").\n It has "+this.departureRoutes.size()+" departing routes and "+this.arrivalRoutes.size()+" arriving routes.";
}
}

@ -1,5 +1,7 @@
package seng202.group9.Core;
import seng202.group9.Controller.DataException;
import java.util.ArrayList;
public class City {
@ -137,8 +139,12 @@ public class City {
* Deletes an Airport by Index from this City.
* @param index
*/
public void delAirport(int index) {
airports.remove(index);
public void delAirport(int index) throws DataException{
if (airports.size() > index && index >= 0) {
airports.remove(index);
}else{
throw new DataException("Index "+index+" is out of number of City Airports array size.");
}
}
@Override
public String toString(){

@ -1,11 +1,16 @@
package seng202.group9.Core;
import seng202.group9.Controller.DataException;
import java.util.ArrayList;
import java.util.HashMap;
public class Country {
private String DST, name;
private ArrayList<City> cities = new ArrayList<City>();
private ArrayList<Airline> airlines = new ArrayList<Airline>();
private HashMap<String, Airline> airlineDict = new HashMap<String, Airline>();
private HashMap<String, City> cityDict = new HashMap<String, City>();
private Position position;
/**
@ -40,8 +45,10 @@ public class Country {
*/
public void setAirlines(ArrayList<Airline> airlines) {
this.airlines = new ArrayList<Airline>();
this.airlineDict = new HashMap<String, Airline>();
for (int i = 0; i < airlines.size(); i ++) {
this.airlines.add(airlines.get(i));
airlineDict.put(airlines.get(i).getName(), airlines.get(i));
}
}
@ -74,7 +81,10 @@ public class Country {
* @param airline
*/
public void addAirline(Airline airline){
this.airlines.add(airline);
if (!airlineDict.containsKey(airline.getName())) {
this.airlines.add(airline);
airlineDict.put(airline.getName(), airline);
}
}
/**
@ -93,14 +103,20 @@ public class Country {
*/
public void delAirline(Airline airline){
airlines.remove(airline);
airlineDict.remove(airline.getName());
}
/**
* deletes an Airline in this country.
* @param index
*/
public void delAirline(int index){
airlines.remove(index);
public void delAirline(int index) throws DataException{
if (airlines.size() > index && index >= 0) {
airlineDict.remove(airlines.get(index).getName());
airlines.remove(index);
}else{
throw new DataException("Index " + index + " does not exist in list of Airlines in this Country.");
}
}
/**
@ -109,8 +125,10 @@ public class Country {
*/
public void setCities(ArrayList<City> cities){
this.cities = new ArrayList<City>();
this.cityDict = new HashMap<String, City>();
for (int i = 0; i < cities.size(); i++){
this.cities.add(cities.get(i));
cityDict.put(cities.get(i).getName(), cities.get(i));
}
}
@ -119,7 +137,10 @@ public class Country {
* @param city
*/
public void addCities(City city){
this.cities.add(city);
if (!cityDict.containsKey(city.getName())) {
this.cities.add(city);
cityDict.put(city.getName(), city);
}
}
/**
@ -144,8 +165,12 @@ public class Country {
* Deletes Cities in this Country
* @param index
*/
public void delCities(int index){
this.cities.remove(index);
public void delCities(int index) throws DataException{
if (cities.size() > index && index >= 0) {
this.cities.remove(index);
}else{
throw new DataException("City at Index "+ index + " does not exist.");
}
}
/**

@ -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,11 @@ public class FlightPath {
* @param index
*/
public void addFlightPoint(FlightPoint flightPoint, int index){
flightPoints.add(index, flightPoint);
if (index >= flightPoints.size() || index < 0){
flightPoints.add(flightPoint);
}else {
flightPoints.add(index, flightPoint);
}
}
/**
@ -140,8 +149,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.");
}
}
/**

@ -197,7 +197,10 @@ public class FlightPoint {
* gets the Path Index ID at this point.
* @return
*/
public int getIndex(){
public int getIndex() throws DataException{
if (indexID == -1){
throw new DataException("Index ID is not set.");
}
return indexID;
}

@ -268,6 +268,9 @@ public class Route {
* @return
*/
public RoutePath getRoutePath(){
if (getSourceAirport() == null || getDestinationAirport() == null){
return new RoutePath();
}
if (routePath == null) {
routePath = new RoutePath(
new Position(getSourceAirport().getLatitude(), getSourceAirport().getLongitude()),

@ -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"));
@ -199,7 +204,14 @@ public class FlightRDController extends Controller {
*/
public void deletePoint() {
FlightPoint toDelete = flightTableView.getSelectionModel().getSelectedItem();
int pathID = toDelete.getIndex();
int pathID = 0;
try {
pathID = toDelete.getIndex();
} catch (DataException e) {
e.printStackTrace();
System.out.println("Point is Undeletable as the Index ID is not set.");
return;
}
LinkedHashMap<Integer, FlightPath> flightPathDict = theDataSet.getFlightPathDictionary();
FlightPath toDeletesPath = flightPathDict.get(pathID);
theDataSet.deleteFlightPoint(toDelete, toDeletesPath);

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

@ -0,0 +1,31 @@
APT,NZCH,0,-43.48664019,172.53368221
VOR,CH,400,-43.50411111,172.51463889000001
FIX,VANDA,34000,-42.421806,169.34450000000004
FIX,UKLAK,34000,-41.4245,166.71119399999998
FIX,SULON,34000,-39.858528,163
FIX,PLUGA,34000,-35.6075,154.68888900000002
FIX,CAWLY,34000,-34.326111,151.95777799999996
VOR,SY,34000,-33.94277778,151.18055556000002
NDB,KAT,34000,-33.710806,150.299622
VOR,PKS,34000,-33.131111,148.23722199999997
FIX,VIMAB,34000,-31.515277999999995,145.358611
FIX,APOMA,34000,-29.898055999999997,142.681667
FIX,POLEV,34000,-26.920277999999996,138.16916700000002
FIX,KALUG,34000,-25.900000000000006,136.72500000000002
VOR,AS,34000,-23.792889000000002,133.87820299999998
FIX,TIMMI,34000,-21.922483,130.65954399999998
FIX,TATUK,34000,-19.429444000000004,126.646389
VOR,CIN,34000,-17.588888889999993,123.85194444000001
FIX,ATMAP,34000,-12,118.255
FIX,ILDAM,34000,-10.592113999999995,116.88456400000001
VOR,BLI,34000,-8.750583329999998,115.16330556000003
FIX,SIPUT,34000,-6.283332999999999,112.58333299999998
FIX,SUMBU,34000,-4.7549999999999955,110.82333299999999
FIX,SABIL,34000,-4.019069000000002,109.93852800000002
FIX,AKULA,34000,-3.119878,108.95092499999998
FIX,APAGA,34000,-2.7826749999999976,108.580897
FIX,APARI,34000,-2.043471999999994,107.84038299999997
FIX,SANOS,34000,-0.7000000000000028,106.316667
FIX,AKTOD,34300,-0.4133329999999944,105.99305600000002
NDB,TI,8800,0.9197280000000063,104.52616899999998
APT,WSSS,0,1.3519171399999976,103.99560303999999
1 APT NZCH 0 -43.48664019 172.53368221
2 VOR CH 400 -43.50411111 172.51463889000001
3 FIX VANDA 34000 -42.421806 169.34450000000004
4 FIX UKLAK 34000 -41.4245 166.71119399999998
5 FIX SULON 34000 -39.858528 163
6 FIX PLUGA 34000 -35.6075 154.68888900000002
7 FIX CAWLY 34000 -34.326111 151.95777799999996
8 VOR SY 34000 -33.94277778 151.18055556000002
9 NDB KAT 34000 -33.710806 150.299622
10 VOR PKS 34000 -33.131111 148.23722199999997
11 FIX VIMAB 34000 -31.515277999999995 145.358611
12 FIX APOMA 34000 -29.898055999999997 142.681667
13 FIX POLEV 34000 -26.920277999999996 138.16916700000002
14 FIX KALUG 34000 -25.900000000000006 136.72500000000002
15 VOR AS 34000 -23.792889000000002 133.87820299999998
16 FIX TIMMI 34000 -21.922483 130.65954399999998
17 FIX TATUK 34000 -19.429444000000004 126.646389
18 VOR CIN 34000 -17.588888889999993 123.85194444000001
19 FIX ATMAP 34000 -12 118.255
20 FIX ILDAM 34000 -10.592113999999995 116.88456400000001
21 VOR BLI 34000 -8.750583329999998 115.16330556000003
22 FIX SIPUT 34000 -6.283332999999999 112.58333299999998
23 FIX SUMBU 34000 -4.7549999999999955 110.82333299999999
24 FIX SABIL 34000 -4.019069000000002 109.93852800000002
25 FIX AKULA 34000 -3.119878 108.95092499999998
26 FIX APAGA 34000 -2.7826749999999976 108.580897
27 FIX APARI 34000 -2.043471999999994 107.84038299999997
28 FIX SANOS 34000 -0.7000000000000028 106.316667
29 FIX AKTOD 34300 -0.4133329999999944 105.99305600000002
30 NDB TI 8800 0.9197280000000063 104.52616899999998
31 APT WSSS 0 1.3519171399999976 103.99560303999999

File diff suppressed because it is too large Load Diff

@ -2,13 +2,17 @@ package seng202.group9;
import java.util.ArrayList;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import seng202.group9.Controller.DataException;
import seng202.group9.Core.Airline;
import seng202.group9.Core.Country;
import seng202.group9.Core.Route;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
/**
* Test the functions for the Airline
* this is the get, set methods for in the class Airline
@ -16,30 +20,13 @@ import seng202.group9.Core.Route;
* @author Fan-Wu Yang
*
*/
public class AirlineTest extends TestCase {
/**
* Create the test case
*
* @param testName name of the test case
*/
public AirlineTest(String testName){
super(testName);
}
/**
* @return the suite of tests being tested
*/
public static Test suite()
{
return new TestSuite( AirlineTest.class );
}
public class AirlineTest{
/**
* Test for Airline get and setting methods
* (Currently missing ADD ROUTES)
*/
@Test
public void testAirlineGetSet(){
//ID, Name, Alias, IATA, ICAO, CallSign, Country, Active
//324,"All Nippon Airways","ANA All Nippon Airways","NH","ANA","ALL NIPPON","Japan","Y"
@ -116,8 +103,119 @@ public class AirlineTest extends TestCase {
assertEquals(allNipponAirways.getRoutes().get(1), route2);
assertEquals(allNipponAirways.getRoutes().get(2), route1);
assertEquals(allNipponAirways.getRoutes().get(3), route2);
try {
allNipponAirways.delRoutes(3);
}catch (DataException e){
fail("3 is a valid deletable index.");
}
assertTrue(allNipponAirways.getRoutes().size() == 3);
allNipponAirways.delRoutes(route2);
assertTrue(allNipponAirways.getRoutes().size() == 2);
}
@Test(expected = DataException.class)
public void testInvalidRouteDelete() throws DataException{
//ID, Name, Alias, IATA, ICAO, CallSign, Country, Active
//324,"All Nippon Airways","ANA All Nippon Airways","NH","ANA","ALL NIPPON","Japan","Y"
Airline allNipponAirways = new Airline(324, "All Nippon Airways", "ANA All Nippon Airways",
"NH", "ANA", "ALL NIPPON", "Japan", "Y");
allNipponAirways.delRoutes(0);
}
@Test(expected = DataException.class)
public void testInvalidIndexRouteDelete() throws DataException{
//ID, Name, Alias, IATA, ICAO, CallSign, Country, Active
//324,"All Nippon Airways","ANA All Nippon Airways","NH","ANA","ALL NIPPON","Japan","Y"
Airline allNipponAirways = new Airline(324, "All Nippon Airways", "ANA All Nippon Airways",
"NH", "ANA", "ALL NIPPON", "Japan", "Y");
allNipponAirways.delRoutes(-1);
}
@Test(expected = DataException.class)
public void hasDuplicateNameTest() throws DataException {
Airline allNipponAirways = new Airline(324, "All Nippon Airways", "ANA All Nippon Airways",
"NH", "ANA", "ALL NIPPON", "Japan", "Y");
Airline allNipponAirway = new Airline(325, "All Nippon Airways", "ANA All Nippon Airway",
"NP", "ANP", "ALL NIPPONP", "Japan", "Y");//duplicate name should be thrown
allNipponAirways.hasDuplicate(allNipponAirway);
}
@Test(expected = DataException.class)
public void hasDuplicateMissingNameTest() throws DataException {
Airline allNipponAirways = new Airline(324, "All Nippon Airways", "ANA All Nippon Airways",
"NH", "ANA", "ALL NIPPON", "Japan", "Y");
Airline allNipponAirway = new Airline(325, "", "ANA All Nippon Airway",
"NP", "ANP", "ALL NIPPONP", "Japan", "Y");//duplicate name should be thrown
allNipponAirways.hasDuplicate(allNipponAirway);
}
@Test(expected = DataException.class)
public void hasDuplicateIATATest() throws DataException {
Airline allNipponAirways = new Airline(324, "All Nippon Airways", "ANA All Nippon Airways",
"NH", "ANA", "ALL NIPPON", "Japan", "Y");
Airline allNipponAirway = new Airline(325, "All Nippon Airway", "ANA All Nippon Airway",
"NH", "ANP", "ALL NIPPONP", "Japan", "Y");//duplicate name should be thrown
allNipponAirways.hasDuplicate(allNipponAirway);
}
@Test(expected = DataException.class)
public void hasDuplicateICAOTest() throws DataException {
Airline allNipponAirways = new Airline(324, "All Nippon Airways", "ANA All Nippon Airways",
"NH", "ANA", "ALL NIPPON", "Japan", "Y");
Airline allNipponAirway = new Airline(325, "All Nippon Airway", "ANA All Nippon Airway",
"NP", "ANA", "ALL NIPPONP", "Japan", "Y");//duplicate name should be thrown
allNipponAirways.hasDuplicate(allNipponAirway);
}
@Test(expected = DataException.class)
public void hasDuplicateAliasTest() throws DataException {
Airline allNipponAirways = new Airline(324, "All Nippon Airways", "ANA All Nippon Airways",
"NH", "ANA", "ALL NIPPON", "Japan", "Y");
Airline allNipponAirway = new Airline(325, "All Nippon Airway", "ANA All Nippon Airways",
"NH", "ANA", "ALL NIPPONP", "Japan", "Y");//duplicate name should be thrown
allNipponAirways.hasDuplicate(allNipponAirway);
}
@Test(expected = DataException.class)
public void hasDuplicateCallTest() throws DataException {
Airline allNipponAirways = new Airline(324, "All Nippon Airways", "ANA All Nippon Airways",
"NH", "ANA", "ALL NIPPON", "Japan", "Y");
Airline allNipponAirway = new Airline(325, "All Nippon Airway", "ANA All Nippon Airway",
"NH", "ANP", "ALL NIPPON", "Japan", "Y");//duplicate name should be thrown
allNipponAirways.hasDuplicate(allNipponAirway);
}
@Test
public void testCountry(){
Airline allNipponAirways = new Airline(324, "All Nippon Airways", "ANA All Nippon Airways",
"NH", "ANA", "ALL NIPPON", "Japan", "Y");
//,9,"U","Asia/Tokyo"
Country japan = new Country("U", "Japan");
allNipponAirways.setCountry(japan);
assertEquals(japan, allNipponAirways.getCountry());
}
@Test(expected = DataException.class)
public void getIDNullError() throws DataException{
Airline allNipponAirways = new Airline("All Nippon Airways", "ANA All Nippon Airways",
"NH", "ANA", "ALL NIPPON", "Japan", "Y");
allNipponAirways.getID();
}
@Test
public void testToString(){
//ID, Name, Alias, IATA, ICAO, CallSign, Country, Active
//324,"All Nippon Airways","ANA All Nippon Airways","NH","ANA","ALL NIPPON","Japan","Y"

@ -7,6 +7,8 @@ import org.junit.rules.ExpectedException;
import seng202.group9.Controller.DataException;
import seng202.group9.Core.Airport;
import seng202.group9.Core.City;
import seng202.group9.Core.Country;
import seng202.group9.Core.Route;
import java.util.ArrayList;
@ -35,6 +37,7 @@ public class AirportUnitTest {
}
assertEquals(heathrow.getName(), "Heathrow");
assertEquals(heathrow.getCityName(), "London");//check city
assertEquals(heathrow.getCountryName(), "United Kingdom");
assertEquals(heathrow.getIATA_FFA(), "LHR");//check IATA/FFA
assertEquals(heathrow.getICAO(), "EGLL");//check ICAO
assertTrue(heathrow.getLatitude() == 51.4775);//check latitude
@ -53,6 +56,8 @@ public class AirportUnitTest {
assertEquals(heathrow.getName(), "Hearthstone");
heathrow.setCityName("Blizzard Servers");//check city
assertEquals(heathrow.getCityName(), "Blizzard Servers");
heathrow.setCountryName("America");
assertEquals(heathrow.getCountryName(), "America");
heathrow.setIATA_FFA("HTS");//test set IATA/FFA
assertEquals(heathrow.getIATA_FFA(), "HTS");
heathrow.setICAO("BLIZ");// test set ICAO
@ -95,6 +100,16 @@ public class AirportUnitTest {
assertEquals(heathrow.getArrivalRoutes().get(2).getArrivalAirport(), "LHR2");
assertEquals(heathrow.getArrivalRoutes().get(3).getArrivalAirport(), "LHR3");
try {
heathrow.delArrivalRoutes(0);
} catch (DataException e) {
}
assertTrue(heathrow.getArrivalRoutes().size() == 3);
heathrow.delArrivalRoutes(heathrow.getArrivalRoutes().get(0));
assertTrue(heathrow.getArrivalRoutes().size() == 2);
//check add departrue routes;
heathrow.addDepartureRoutes(route1);
heathrow.addDepartureRoutes(routes);
@ -104,6 +119,15 @@ public class AirportUnitTest {
assertEquals(heathrow.getDepartureRoutes().get(2).getDepartureAirport(), "SIN2");
assertEquals(heathrow.getDepartureRoutes().get(3).getDepartureAirport(), "SIN3");
try {
heathrow.delDepartureRoutes(0);
} catch (DataException e) {
}
assertTrue(heathrow.getDepartureRoutes().size() == 3);
heathrow.delDepartureRoutes(heathrow.getDepartureRoutes().get(0));
assertTrue(heathrow.getDepartureRoutes().size() == 2);
//check set
heathrow.setArrivalRoutes(routes);
heathrow.setDepartureRoutes(routes);
@ -118,17 +142,126 @@ public class AirportUnitTest {
}
@Test
public void checkIDException(){
public void testCountryAndCity(){
Airport heathrow = new Airport(507, "Heathrow", "London", "United Kingdom", "LHR", "EGLL", 51.4775, -0.41389, 83);
Country UnitedKing = new Country("E", "United Kingdom");
heathrow.setCountry(UnitedKing);
City london = new City("London", "United Kingdom", 0, "Europe/London");
UnitedKing.addCities(london);
heathrow.setCity(london);
assertEquals(heathrow.getCity().getName(), "London");
assertEquals(heathrow.getCity().getCountry(), "United Kingdom");
assertEquals(heathrow.getCity().getTimeOlson(), "Europe/London");
assertTrue(heathrow.getCity().getTimezone() == 0);
//country tests
assertEquals(heathrow.getCountry().getDST(), "E");
assertEquals(heathrow.getCountry().getName(), "United Kingdom");
//check if the country has city london
assertEquals(heathrow.getCountry().getCities().get(0), london);
//check the get commands from the airport city
assertEquals(heathrow.getDST(), "E");
assertEquals(heathrow.getDST(), heathrow.getCountry().getDST());
assertEquals(heathrow.getCityName(), heathrow.getCity().getName());
assertEquals(heathrow.getCity().getCountry(), heathrow.getCountryName());
assertEquals(heathrow.getCity().getCountry(), "United Kingdom");
assertEquals(heathrow.getTz(), "Europe/London");
assertEquals(heathrow.getTz(), heathrow.getCity().getTimeOlson());
assertTrue(heathrow.getTimezone() == 0);
assertTrue(heathrow.getTimezone() == heathrow.getCity().getTimezone());
//check the get commands for airport countries
assertEquals(heathrow.getCountryName(), heathrow.getCountry().getName());
assertEquals(heathrow.getCountry().getDST(), heathrow.getDST());
assertEquals(heathrow.getCountry().getDST(), "E");
}
@Test
public void checkCalculateDistance(){
//check whether the airport distance between teh same airport is 0
Airport heathrow = new Airport(507, "Heathrow", "London", "United Kingdom", "LHR", "EGLL", 51.4775, -0.41389, 83);
Airport heathrow2 = new Airport(507, "Heathrow", "London", "United Kingdom", "LHR", "EGLL", 51.4775, -0.41389, 83);
assertTrue(heathrow.calculateDistance(heathrow2) == 0);
//check the correct distance between this and Edmonton
Airport edmonton = new Airport(26,"Kugaaruk","Pelly Bay","Canada","YBB","CYBB",68.534444,-89.808056,56);
//must be correct with a 0.3% margin of error calculations from http://www.movable-type.co.uk/scripts/latlong.html
assertTrue(heathrow.calculateDistance(edmonton) <= 4789 * 1.003);
assertTrue(heathrow.calculateDistance(edmonton) >= 4789 * 0.997);
}
@Test(expected = DataException.class)
public void checkNameDuplicate() throws DataException{
Airport heathrow = new Airport(507, "Heathrow", "London", "United Kingdom", "LHR", "EGLL", 51.4775, -0.41389, 83);
Airport heathrow2 = new Airport(507, "Heathrow", "Londons", "United Ksingdom", "LRR", "EPLL", 51.4775, -0.41389, 83);
heathrow.hasDuplicate(heathrow2);
}
@Test(expected = DataException.class)
public void checkEmptyNameDuplicate() throws DataException{
Airport heathrow = new Airport(507, "Heathrow", "London", "United Kingdom", "LHR", "EGLL", 51.4775, -0.41389, 83);
Airport heathrow2 = new Airport(507, "", "Londons", "United Ksingdom", "LRR", "EPLL", 51.4775, -0.41389, 83);
heathrow.hasDuplicate(heathrow2);
}
@Test(expected = DataException.class)
public void checkIATADuplicate() throws DataException{
Airport heathrow = new Airport(507, "Heathrow", "London", "United Kingdom", "LHR", "EGLL", 51.4775, -0.41389, 83);
Airport heathrow2 = new Airport(507, "Heathrsow", "Lossndon", "United Kisssngdom", "LHR", "EKLL", 51.4775, -0.41389, 83);
heathrow.hasDuplicate(heathrow2);
}
@Test(expected = DataException.class)
public void checkICAODuplicate() throws DataException{
Airport heathrow = new Airport(507, "Heathrow", "London", "United Kingdom", "LHR", "EGLL", 51.4775, -0.41389, 83);
Airport heathrow2 = new Airport(507, "Heathrows", "Lonsdon", "United Kisngdom", "LJR", "EGLL", 51.4775, -0.41389, 83);
heathrow.hasDuplicate(heathrow2);
}
@Test(expected = DataException.class)
public void checkIDException() throws DataException{
//507,"Heathrow","London","United Kingdom","LHR","EGLL",51.4775,-0.461389,83,0,"E","Europe/London"
//ID, NaWme, City, Country, IATA/FFA, ICAO, Latitude, Longitude, Altitude, Timezone, DST, Tz Data
Airport heathrow = new Airport("Heathrow", "London", "United Kingdom", "LHR", "EGLL", 51.4775, -0.41389, 83);
assertEquals(heathrow.getID(), 544);//check ID no id should be thrown
}
@Test(expected = DataException.class)
public void checkDelArrivalNoIndexFailure() throws DataException{
//507,"Heathrow","London","United Kingdom","LHR","EGLL",51.4775,-0.461389,83,0,"E","Europe/London"
//ID, NaWme, City, Country, IATA/FFA, ICAO, Latitude, Longitude, Altitude, Timezone, DST, Tz Data
Airport heathrow = new Airport("Heathrow", "London", "United Kingdom", "LHR", "EGLL", 51.4775, -0.41389, 83);
heathrow.delArrivalRoutes(0);
}
@Test(expected = DataException.class)
public void checkDelArrivalNegativeIndexFailure() throws DataException{
//507,"Heathrow","London","United Kingdom","LHR","EGLL",51.4775,-0.461389,83,0,"E","Europe/London"
//ID, NaWme, City, Country, IATA/FFA, ICAO, Latitude, Longitude, Altitude, Timezone, DST, Tz Data
Airport heathrow = new Airport("Heathrow", "London", "United Kingdom", "LHR", "EGLL", 51.4775, -0.41389, 83);
heathrow.delArrivalRoutes(-1);
}
@Test(expected = DataException.class)
public void checkDelDepartureNoIndexFailure() throws DataException{
//507,"Heathrow","London","United Kingdom","LHR","EGLL",51.4775,-0.461389,83,0,"E","Europe/London"
//ID, NaWme, City, Country, IATA/FFA, ICAO, Latitude, Longitude, Altitude, Timezone, DST, Tz Data
Airport heathrow = new Airport("Heathrow", "London", "United Kingdom", "LHR", "EGLL", 51.4775, -0.41389, 83);
heathrow.delDepartureRoutes(0);
}
@Test(expected = DataException.class)
public void checkDelDepatureNegativeIndexFailure() throws DataException{
//507,"Heathrow","London","United Kingdom","LHR","EGLL",51.4775,-0.461389,83,0,"E","Europe/London"
//ID, NaWme, City, Country, IATA/FFA, ICAO, Latitude, Longitude, Altitude, Timezone, DST, Tz Data
Airport heathrow = new Airport("Heathrow", "London", "United Kingdom", "LHR", "EGLL", 51.4775, -0.41389, 83);
heathrow.delDepartureRoutes(-1);
}
@Test
public void checkToString(){
//507,"Heathrow","London","United Kingdom","LHR","EGLL",51.4775,-0.461389,83,0,"E","Europe/London"
//ID, Name, City, Country, IATA/FFA, ICAO, Latitude, Longitude, Altitude, Timezone, DST, Tz Data
//ID, NaWme, City, Country, IATA/FFA, ICAO, Latitude, Longitude, Altitude, Timezone, DST, Tz Data
Airport heathrow = new Airport("Heathrow", "London", "United Kingdom", "LHR", "EGLL", 51.4775, -0.41389, 83);
thrown.expect(DataException.class);
thrown.expectMessage("ID not set.");
try {
assertEquals(heathrow.getID(), 544);//check ID no id should be thrown
} catch (DataException e) {
}
assertEquals(heathrow.toString(), "Heathrow Airport has ICAO: EGLL, IATA/FFA: LHR and is located at (51.4775, -0.41389).\n" +
" It has 0 departing routes and 0 arriving routes.");
}
}

@ -1,38 +1,32 @@
package seng202.group9;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.junit.Test;
import seng202.group9.Controller.App;
import seng202.group9.Controller.DataException;
import static org.junit.Assert.*;
/**
* Unit test for simple App.
*/
public class AppTest
extends TestCase
{
/**
* Create the test case
*
* @param testName name of the test case
*/
public AppTest( String testName )
{
super( testName );
}
public class AppTest {
@Test
public void testApp(){
App app = new App();
assertTrue(app.getMenuController() == null);
assertTrue(app.getPrimaryStage() == null);
try {
app.createDataset("FORUNITTESTINGDATASET");
} catch (DataException e) {
e.printStackTrace();
}
assertEquals(app.getCurrentDataset().getName(), "FORUNITTESTINGDATASET");
/**
* @return the suite of tests being tested
*/
public static Test suite()
{
return new TestSuite( AppTest.class );
}
app.deleteDataset(app.getCurrentDataset());
/**
* Rigourous Test :-)
*/
public void testApp()
{
assertTrue( true );
for (int i = 0; i < app.getDatasets().size(); i++){
assertTrue(!app.getDatasets().get(i).getName().equals("FORUNITTESTINGDATASET"));
}
//more to come as the program upgrades for for as of now this is the limit.
}
}

@ -0,0 +1,84 @@
package seng202.group9;/**
* Created by Gondr on 18/09/2016.
*/
import static org.junit.Assert.*;
import org.junit.Test;
import seng202.group9.Controller.DataException;
import seng202.group9.Core.Airport;
import seng202.group9.Core.City;
import java.util.ArrayList;
public class CityTest {
@Test
public void testConstructor(){
//Matsumoto, Japan 9,"Asia/Tokyo"
City matsumoto = new City("Matsumoto", "Japan", 9, "Asia/Tokyo");
assertEquals(matsumoto.getName(), "Matsumoto");
assertEquals(matsumoto.getCountry(), "Japan");
assertTrue(matsumoto.getTimezone() == 9);
assertEquals(matsumoto.getTimeOlson(), "Asia/Tokyo");
//check setters
matsumoto.setName("matsumoto");
matsumoto.setCountry("japan");
matsumoto.setTimezone(10);
matsumoto.setTimeOlson("Japan/Tokyo");
assertEquals(matsumoto.getName(), "matsumoto");
assertEquals(matsumoto.getCountry(), "japan");
assertTrue(matsumoto.getTimezone() == 10);
assertEquals(matsumoto.getTimeOlson(), "Japan/Tokyo");
}
@Test
public void testAirports(){
City matsumoto = new City("Matsumoto", "Japan", 9, "Asia/Tokyo");
Airport matsumotoAirport = new Airport(2280, "Matsumoto", "Matsumoto", "Japan", "MMJ", "RJAF", 36.166758, 137.922669, 2182);
assertTrue(matsumoto.getAirports().size() == 0);
matsumoto.addAirport(matsumotoAirport);
assertEquals(matsumoto.getAirports().get(0), matsumotoAirport);
assertTrue(matsumoto.getAirports().size() == 1);
matsumoto.delAirport(matsumotoAirport);
assertTrue(matsumoto.getAirports().size() == 0);
ArrayList<Airport> airports = new ArrayList<Airport>();
airports.add(matsumotoAirport);
airports.add(matsumotoAirport);
matsumoto.addAirport(airports);
assertTrue(matsumoto.getAirports().size() == 2);
try {
matsumoto.delAirport(0);
assertTrue(matsumoto.getAirports().size() == 1);
matsumoto.delAirport(0);
}catch (DataException e){
}
matsumoto.delAirport(matsumotoAirport);
//set the airports
matsumoto.setAirports(airports);
assertTrue(matsumoto.getAirports().size() == 2);
}
@Test(expected = DataException.class)
public void testDelAirportsMissingIndexErrors() throws DataException{
City matsumoto = new City("Matsumoto", "Japan", 9, "Asia/Tokyo");
matsumoto.delAirport(0);
}
@Test(expected = DataException.class)
public void testDelAirportsNegativeIndexErrors() throws DataException{
City matsumoto = new City("Matsumoto", "Japan", 9, "Asia/Tokyo");
matsumoto.delAirport(-1);
}
@Test
public void testString(){
City matsumoto = new City("Matsumoto", "Japan", 9, "Asia/Tokyo");
assertEquals(matsumoto.toString(), "Matsumoto has 0 Airports and is in Asia/Tokyo");
}
}

@ -0,0 +1,118 @@
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.Airline;
import seng202.group9.Core.City;
import seng202.group9.Core.Country;
import seng202.group9.Core.Position;
import java.lang.reflect.Array;
import java.util.ArrayList;
public class CountryTest {
@Test
public void testConstructor(){
Country country = new Country("A", "Japan");
assertEquals(country.getName(), "Japan");
assertEquals(country.getDST(), "A");
country.setName("United Kingdom");
country.setDST("E");
assertEquals(country.getName(), "United Kingdom");
assertEquals(country.getDST(), "E");
}
@Test
public void testAirlines(){
Country country = new Country("A", "Japan");
//71,"Advanced Air Co.",\N,"","ADD","","Japan","N"
Airline advancedAir = new Airline(71,"Advanced Air Co.","\\N","","ADD","","Japan","N");
//248,"ANA & JP Express",\N,"","AJV","AYJAY CARGO","Japan","N"
Airline jPExpress = new Airline(248,"ANA & JP Express","\\N","","AJV","AYJAY CARGO","Japan","N");
country.addAirline(advancedAir);
assertEquals(country.getAirlines().get(0), advancedAir);
assertTrue(country.getAirlines().size() == 1);
country.delAirline(advancedAir);
assertTrue(country.getAirlines().size() == 0);
ArrayList<Airline> airlines = new ArrayList<Airline>();
airlines.add(advancedAir);
airlines.add(jPExpress);
country.addAirline(airlines);
assertTrue(country.getAirlines().size() == 2);
try {
country.delAirline(0);
} catch (DataException e) {
e.printStackTrace();
}
assertTrue(country.getAirlines().size() == 1);
country.setAirlines(airlines);
assertTrue(country.getAirlines().size() == 2);
//Tokyo, Japan,9,"Asia/Tokyo"
City tokyo = new City("Tokyo", "Japan", 9, "Asia/Tokyo");
City matsumoto = new City("Matsumoto", "Japan", 9, "Asia/Tokyo");
country.addCities(tokyo);
assertEquals(country.getCities().get(0), tokyo);
country.delCities(tokyo);
assertTrue(country.getCities().size() == 0);
ArrayList<City> cities = new ArrayList<City>();
cities.add(tokyo);
cities.add(matsumoto);
country.addCities(cities);
assertTrue(country.getCities().size() == 2);
try {
country.delCities(0);
} catch (DataException e) {
fail("There is a city deletable");
}
country.setCities(cities);
assertTrue(country.getCities().size() == 2);
Position position = new Position(0, 0);
country.setPosition(position);
assertEquals(country.getPosition(), position);
}
@Test (expected = DataException.class)
public void delAirlineIndexOutOfRange() throws DataException{
Country country = new Country("A", "Japan");
country.delAirline(0);
}
@Test (expected = DataException.class)
public void delAirlineIndexNegative() throws DataException{
Country country = new Country("A", "Japan");
country.delAirline(-1);
}
@Test (expected = DataException.class)
public void delCityIndexOutOfRange() throws DataException{
Country country = new Country("A", "Japan");
country.delCities(0);
}
@Test (expected = DataException.class)
public void delCityIndexNegative() throws DataException{
Country country = new Country("A", "Japan");
country.delCities(-1);
}
}

@ -0,0 +1,210 @@
package seng202.group9;/**
* Created by Gondr on 19/09/2016.
*/
import static org.junit.Assert.*;
import org.junit.AfterClass;
import org.junit.Test;
import seng202.group9.Controller.App;
import seng202.group9.Controller.DataException;
import seng202.group9.Controller.Dataset;
import seng202.group9.Core.*;
public class DatasetTest {
static App app = new App();
@Test
public void DatasetConstructor(){
try {
app.createDataset("FORUNITTESTINGONLY");
} catch (DataException e) {
fail("There seems to be database already by this name");
}
Dataset dataset = app.getCurrentDataset();
assertEquals(dataset.getName(), "FORUNITTESTINGONLY");
try {
dataset.importAirline("res/Reduced Samples/Airlines.txt");
} catch (DataException e) {
fail("The sample file is missing");
}
assertTrue(dataset.getAirlines().size() == dataset.getAirlineDictionary().size());
try {
dataset.importAirport("res/Reduced Samples/Airports.txt");
} catch (DataException e) {
fail("The sample file is missing");
}
assertTrue(dataset.getAirports().size() == dataset.getAirportDictionary().size());
assertTrue(dataset.getCities().size() == dataset.getCityDictionary().size());
assertTrue(dataset.getCountries().size() == dataset.getCountryDictionary().size());
try {
dataset.importRoute("res/Reduced Samples/Routes.txt");
} catch (DataException e) {
fail("The sample file is missing");
}
assertTrue(dataset.getRoutes().size() == dataset.getRouteDictionary().size());
try {
dataset.importFlight("res/Reduced Samples/NZCH-WSSS.csv");
} catch (DataException e) {
fail("The sample file is missing");
}
assertTrue(dataset.getFlightPaths().size() == dataset.getFlightPathDictionary().size());
dataset.createDataLinks();
assertTrue(dataset.getAirlines().size() == dataset.getAirlineDictionary().size());
assertTrue(dataset.getAirports().size() == dataset.getAirportDictionary().size());
assertTrue(dataset.getCities().size() == dataset.getCityDictionary().size());
assertTrue(dataset.getCountries().size() == dataset.getCountryDictionary().size());
assertTrue(dataset.getRoutes().size() == dataset.getRouteDictionary().size());
assertTrue(dataset.getFlightPaths().size() == dataset.getFlightPathDictionary().size());
//make sure that datalinks does not increase the size of the dictionaries etc
app.deleteDataset(app.getCurrentDataset());
}
@Test
public void checkoutDataLinks() throws DataException {
try {
app.createDataset("FORUNITTESTINGONLY");
} catch (DataException e) {
fail("There seems to be database already by this name");
}
Dataset dataset = app.getCurrentDataset();
Airline allNipponAirways = new Airline(324, "All Nippon Airways", "ANA All Nippon Airways",
"NH", "ANA", "ALL NIPPON", "Japan", "Y");
dataset.addAirline(allNipponAirways);
assertEquals(dataset.getAirlines().get(0), allNipponAirways);
dataset.addAirline("British Airways","\\N","BA","BAW","SPEEDBIRD","United Kingdom","Y");
assertEquals(dataset.getAirlines().get(1).getName(), "British Airways");
assertTrue(dataset.getAirlines().get(0).getID() != -1);
assertTrue(dataset.getAirlines().get(1).getID() != -1);
dataset.addAirport("Heathrow","London","United Kingdom","LHR","EGLL","51.4775","-0.461389","83","0","E","Europe/London");
dataset.addAirport("Changi Intl","Singapore","Singapore","SIN","WSSS","1.350189","103.994433","22","8","N","Asia/Singapore");
dataset.addAirport("Matsumoto","Matsumoto","Japan","MMJ","RJAF","36.166758","137.922669","2182","9","U","Asia/Tokyo");
assertTrue(dataset.getAirports().size() == 3);
assertTrue(dataset.getCities().size() == 3);
assertTrue(dataset.getCountries().size() == 3);
Route route = new Route("BA", "SIN", "LHR", "", 0, "744 777");
dataset.addRoute(route);
dataset.addRoute("NH", "SIN", "LHR", "", "0","777");
//checked if everything is linked together properly
assertTrue(dataset.getAirlines().get(0).getCountry() != null);
assertTrue(dataset.getAirlines().get(1).getCountry() != null);
assertTrue(dataset.getAirlines().get(0).getRoutes().size() == 1);
assertTrue(dataset.getAirlines().get(1).getRoutes().size() == 1);
assertTrue(dataset.getCountryDictionary().get("United Kingdom").getAirlines().size() == 1);
assertTrue(dataset.getCountryDictionary().get("Japan").getAirlines().size() == 1);
assertEquals(dataset.getRoutes().get(0).getSourceAirport(), dataset.getAirportDictionary().get("Changi Intl"));
assertEquals(dataset.getRoutes().get(0).getDestinationAirport(), dataset.getAirportDictionary().get("Heathrow"));
assertEquals(dataset.getRoutes().get(0).getAirline(), dataset.getAirlineDictionary().get("British Airways"));
assertEquals(dataset.getRoutes().get(1).getSourceAirport(), dataset.getAirportDictionary().get("Changi Intl"));
assertEquals(dataset.getRoutes().get(1).getDestinationAirport(), dataset.getAirportDictionary().get("Heathrow"));
assertEquals(dataset.getRoutes().get(1).getAirline(), dataset.getAirlineDictionary().get("All Nippon Airways"));
//slowly delete everything and check if the links are retained/gone.
dataset.deleteRoute(0);
assertTrue(dataset.getRoutes().size() == 1);
assertTrue(dataset.getRoutes().size() == dataset.getRouteDictionary().size());
assertTrue(dataset.getAirlines().get(0).getRoutes().size() == 1);
assertTrue(dataset.getAirlines().get(1).getRoutes().size() == 0);
//add the route back
dataset.addRoute(route);
dataset.deleteAirport(0);
assertTrue(dataset.getCityDictionary().get("London") == null);
assertTrue(dataset.getCountryDictionary().get("United Kingdom") == null);
assertTrue(dataset.getRoutes().get(0).getDestinationAirport() == null);
assertTrue(dataset.getRoutes().get(1).getDestinationAirport() == null);
dataset.addAirport("Heathrow","London","United Kingdom","LHR","EGLL","51.4775","-0.461389","83","0","E","Europe/London");
//check that all changes are now back;
assertTrue(dataset.getCityDictionary().get("London") != null);
assertTrue(dataset.getCountryDictionary().get("United Kingdom") != null);
assertTrue(dataset.getRoutes().get(0).getDestinationAirport() != null);
assertTrue(dataset.getRoutes().get(1).getDestinationAirport() != null);
dataset.deleteAirline(dataset.getAirlines().get(0));
assertTrue(dataset.getRoutes().get(0).getAirline() == null);
assertTrue(dataset.getCountryDictionary().get("Japan").getAirlines().size() == 0);
//clean database and check whether dictionarys and arrays are empty
dataset.deleteAirline(0);
dataset.deleteAirport(0);
dataset.deleteAirport(0);
dataset.deleteAirport(0);
dataset.deleteRoute(0);
dataset.deleteRoute(0);
assertTrue(dataset.getAirlines().size() == 0);
assertTrue(dataset.getAirports().size() == 0);
assertTrue(dataset.getAirlineDictionary().size() == 0);
assertTrue(dataset.getAirportDictionary().size() == 0);
assertTrue(dataset.getRoutes().size() == 0);
assertTrue(dataset.getRouteDictionary().size() == 0);
assertTrue(dataset.getCities().size() == 0);
assertTrue(dataset.getCityDictionary().size() == 0);
assertTrue(dataset.getCountries().size() == 0);
assertTrue(dataset.getCountryDictionary().size() == 0);
app.deleteDataset(app.getCurrentDataset());
}
@Test
public void flightPathTester() throws DataException {
try {
app.createDataset("FORUNITTESTINGONLY");
} catch (DataException e) {
fail("There seems to be database already by this name");
}
Dataset dataset = app.getCurrentDataset();
try {
dataset.importFlight("res/Reduced Samples/NZCH-WSSS.csv");
} catch (DataException e) {
fail("The sample file is missing");
}
FlightPoint flightPoint = dataset.getFlightPaths().get(0).getFlightPoints().get(6);
FlightPoint flightPoint1 = dataset.getFlightPaths().get(0).getFlightPoints().get(5);
dataset.deleteFlightPoint(1, 5);
assertEquals(dataset.getFlightPaths().get(0).getFlightPoints().get(5), flightPoint);
int currentSize = dataset.getFlightPaths().get(0).getFlightPoints().size();
dataset.deleteFlightPoint(flightPoint, dataset.getFlightPaths().get(0));
assertTrue(dataset.getFlightPaths().get(0).getFlightPoints().size() == currentSize - 1);
dataset.addFlightPointToPath(flightPoint1, 5);
dataset.addFlightPointToPath(flightPoint, 6);
assertEquals(dataset.getFlightPaths().get(0).getFlightPoints().get(5).getName(), flightPoint1.getName());
assertEquals(dataset.getFlightPaths().get(0).getFlightPoints().get(6).getName(), flightPoint.getName());
app.deleteDataset(app.getCurrentDataset());
}
@AfterClass
public static void deleteDataset(){
while(app.getCurrentDataset() != null) {
app.deleteDataset(app.getCurrentDataset());
}
}
}

@ -0,0 +1,222 @@
package seng202.group9;/**
* Created by Gondr on 19/09/2016.
*/
import static org.junit.Assert.*;
import org.junit.AfterClass;
import org.junit.Test;
import seng202.group9.Controller.*;
public class FilterUnitTest {
static App app = new App();
@Test
public void airlineFilterTest(){
try {
app.createDataset("FORUNITTESTINGONLY");
} catch (DataException e) {
fail("There seems to be database already by this name");
}
Dataset dataset = app.getCurrentDataset();
try {
dataset.importAirline("res/Reduced Samples/Airlines.txt");
} catch (DataException e) {
fail("The sample file is missing");
}
AirlineFilter airlineFilter = new AirlineFilter(dataset.getAirlines());
int size = airlineFilter.getFilteredData().size();
airlineFilter.filterActive("Y");
assertTrue(size != airlineFilter.getFilteredData().size());
airlineFilter.reset();
airlineFilter.filterAlias("A");
assertTrue(size != airlineFilter.getFilteredData().size());
airlineFilter.reset();
airlineFilter.filterCallsign("Y");
assertTrue(size != airlineFilter.getFilteredData().size());
airlineFilter.reset();
airlineFilter.filterCountry("E");
assertTrue(size != airlineFilter.getFilteredData().size());
airlineFilter.reset();
airlineFilter.filterIATA("I");
assertTrue(size != airlineFilter.getFilteredData().size());
airlineFilter.reset();
airlineFilter.filterICAO("O");
assertTrue(size != airlineFilter.getFilteredData().size());
airlineFilter.reset();
airlineFilter.filterName("T");
assertTrue(size != airlineFilter.getFilteredData().size());
airlineFilter.printFilter();
airlineFilter.setBaseList(airlineFilter.getFilteredData());
app.deleteDataset(app.getCurrentDataset());
}
@Test
public void airportFilterTest(){
try {
app.createDataset("FORUNITTESTINGONLY");
} catch (DataException e) {
fail("There seems to be database already by this name");
}
Dataset dataset = app.getCurrentDataset();
try {
dataset.importAirport("res/Reduced Samples/Airports.txt");
} catch (DataException e) {
fail("The sample file is missing");
}
AirportFilter filter = new AirportFilter(dataset.getAirports());
int size = dataset.getAirports().size();
filter.filterName("d");
assertTrue(size != filter.getFilteredData().size());
filter.reset();
filter.filterCity("P");
assertTrue(size != filter.getFilteredData().size());
filter.reset();
filter.filterCountry("Q");
assertTrue(size != filter.getFilteredData().size());
filter.reset();
filter.filterIATA_FFA("U");
assertTrue(size != filter.getFilteredData().size());
filter.reset();
filter.filterICAO("L");
assertTrue(size != filter.getFilteredData().size());
filter.reset();
filter.filterLatitude("7");
assertTrue(size != filter.getFilteredData().size());
filter.reset();
filter.filterLongitude("4");
assertTrue(size != filter.getFilteredData().size());
filter.reset();
filter.filterAltitude("0");
assertTrue(size != filter.getFilteredData().size());
filter.reset();
filter.filterTimezone("1");
assertTrue(size != filter.getFilteredData().size());
filter.reset();
filter.filterOlson("Europe");
assertTrue(size != filter.getFilteredData().size());
filter.reset();
filter.filterDST("A");
assertTrue(size != filter.getFilteredData().size());
filter.printFilter();
filter.setBaseList(filter.getFilteredData());
size = filter.getFilteredData().size();
filter.reset();
assertTrue(size == filter.getFilteredData().size());
app.deleteDataset(app.getCurrentDataset());
}
@Test
public void routeFilterTest(){
try {
app.createDataset("FORUNITTESTINGONLY");
} catch (DataException e) {
fail("There seems to be database already by this name");
}
Dataset dataset = app.getCurrentDataset();
try {
dataset.importRoute("res/Reduced Samples/Routes.txt");
} catch (DataException e) {
fail("The sample file is missing");
}
RouteFilter filter = new RouteFilter(dataset.getRoutes());
int size = dataset.getRoutes().size();
filter.filterAirline("N");
assertTrue(size != filter.getFilteredData().size());
filter.reset();
filter.filterSourceAirport("H");
assertTrue(size != filter.getFilteredData().size());
filter.reset();
filter.filterDestinationAirport("P");
assertTrue(size != filter.getFilteredData().size());
filter.reset();
filter.filterCodeshare("Y");
assertTrue(size != filter.getFilteredData().size());
filter.reset();
filter.filterDestinationStops("3");
assertTrue(size != filter.getFilteredData().size());
filter.reset();
filter.filterEquipment("777");
assertTrue(size != filter.getFilteredData().size());
filter.printFilter();
filter.setBaseList(filter.getFilteredData());
size = filter.getFilteredData().size();
filter.reset();
assertTrue(filter.getFilteredData().size() == size);
app.deleteDataset(app.getCurrentDataset());
}
@AfterClass
public static void deleteDataset(){
while(app.getCurrentDataset() != null) {
app.deleteDataset(app.getCurrentDataset());
}
}
}

@ -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(4), 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);
}
}

@ -0,0 +1,82 @@
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.FlightPoint;
public class FlightPointTest {
@Test
public void testConstructor(){
FlightPoint startPoint = new FlightPoint("NZCH", 1, 1, "APT", "", 0, 0, 0, 0, 172.5336822, -43.48664019);
try {
assertTrue(startPoint.getID() == 1);
assertTrue(startPoint.getIndexID() == 1);
} catch (DataException e) {
fail("The Initial ID is set for this class");
}
assertEquals(startPoint.getName(), "NZCH");
assertEquals(startPoint.getType(), "APT");
assertEquals(startPoint.getVia(), "");
assertTrue(startPoint.getHeading() == 0);
assertTrue(startPoint.getLegDistance() == 0);
assertTrue(startPoint.getAltitude() == 0);
assertTrue(startPoint.getTotalDistance() == 0);
assertTrue(startPoint.getLatitude() == 172.5336822);
assertTrue(startPoint.getLongitude() == -43.48664019);
startPoint.setName("NZAK");
startPoint.setType("FIX");
startPoint.setID(2);
startPoint.setIndexID(2);
startPoint.setVia("SIN");
startPoint.setHeading(15);
startPoint.setLegDistance(95.4);
startPoint.setAltitude(0.5);
startPoint.setTotalDistance(540.8);
startPoint.setLatitude(172.5);
startPoint.setLongitude(-43.5);
try {
assertTrue(startPoint.getID() == 2);
assertTrue(startPoint.getIndexID() == 2);
} catch (DataException e) {
fail("The Initial ID is set for this class");
}
assertEquals(startPoint.getName(), "NZAK");
assertEquals(startPoint.getType(), "FIX");
assertEquals(startPoint.getVia(), "SIN");
assertTrue(startPoint.getHeading() == 15);
assertTrue(startPoint.getLegDistance() == 95.4);
assertTrue(startPoint.getAltitude() == 0.5);
assertTrue(startPoint.getTotalDistance() == 540.8);
assertTrue(startPoint.getLatitude() == 172.5);
assertTrue(startPoint.getLongitude() == -43.5);
}
@Test (expected = DataException.class)
public void checkIDFail() throws DataException{
FlightPoint endPoint = new FlightPoint("APT", "WSSS", 0, 103.995603, 1.35191714);
endPoint.getID();
}
@Test (expected = DataException.class)
public void checkIndexIDFail() throws DataException{
FlightPoint endPoint = new FlightPoint("APT", "WSSS", 0, 103.995603, 1.35191714);
endPoint.getIndexID();
}
@Test (expected = DataException.class)
public void checkIndexFail() throws DataException{
FlightPoint endPoint = new FlightPoint("APT", "WSSS", 0, 103.995603, 1.35191714);
endPoint.getIndex();
}
}

@ -0,0 +1,37 @@
package seng202.group9;/**
* Created by Gondr on 19/09/2016.
*/
import static org.junit.Assert.*;
import org.junit.Test;
import seng202.group9.Core.Position;
import seng202.group9.Core.RoutePath;
public class RoutePathTest {
@Test
public void testConstructors(){
RoutePath routePath = new RoutePath(
new Position(5, 6),
new Position(0, 1)
);
assertTrue(routePath.getRoute().get(0).lat == 5);
assertTrue(routePath.getRoute().get(0).lng == 6);
assertTrue(routePath.getRoute().get(1).lat == 0);
assertTrue(routePath.getRoute().get(1).lng == 1);
assertTrue(routePath.getRoute().size() == 2);
routePath.addPosition(new Position(3, 4));
assertTrue(routePath.getRoute().size() == 3);
assertTrue(routePath.getRoute().get(2).lat == 3);
assertTrue(routePath.getRoute().get(2).lng == 4);
assertEquals(routePath.toJSONArray(), "[{lat: 5.000000, lng: 6.000000}, {lat: 0.000000, lng: 1.000000}, {lat: 3.000000, lng: 4.000000}, ]");
RoutePath routePath1 = new RoutePath();
assertTrue(routePath1.getRoute().size() == 0);
}
}

@ -1,20 +1,26 @@
package seng202.group9;
import org.junit.rules.ExpectedException;
import javafx.scene.chart.PieChart;
import org.junit.Test;
import junit.framework.TestCase;
import seng202.group9.Controller.DataException;
import seng202.group9.Core.Airline;
import seng202.group9.Core.Airport;
import seng202.group9.Core.Route;
import seng202.group9.Core.RoutePath;
import static junit.framework.TestCase.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
/**
*
* Route tests
* @author Fan-Wu Yang
*
*/
public class RouteTest extends TestCase {
//exception checker
public ExpectedException thrown = ExpectedException.none();
public class RouteTest{
@Test
public void testRouteGetSet(){
@ -36,6 +42,7 @@ public class RouteTest extends TestCase {
///////////////
//test setters
///////////////
route.setID(5);
route.setAirlineName("BAH");
route.setArrivalAirport("LEFT-HAND-RULE");
route.setDepartureAirport("SING-SONG");
@ -43,7 +50,12 @@ public class RouteTest extends TestCase {
route.setStops(5);
route.setEquipment("747 840");
assertEquals(route.getDepartureAirport(), "SING-SONG");
try {
assertTrue(route.getID() == 5);
} catch (DataException e) {
fail("ID has been set it shouldn't fail.");
}
assertEquals(route.getDepartureAirport(), "SING-SONG");
assertEquals(route.getArrivalAirport(), "LEFT-HAND-RULE");
assertEquals(route.getAirlineName(), "BAH");
assertEquals(route.getCode(), "Y");
@ -59,23 +71,112 @@ public class RouteTest extends TestCase {
}
}
@Test
public void testRouteIDException() throws DataException{
@Test(expected = DataException.class)
public void testRouteIDException() throws DataException {
//sample entry
//BA,1355,SIN,3316,LHR,507,,0,744 777
//airline, airline ID (This is not parsed as this will be different
//from our database id for this route), source Aiport, source Airport ID (not parsed),
//destination airport, destination ID (not parsed), Codeshare, stops, Equipment
Route route = new Route("BA", "SIN", "LHR", "", 0, "744 777");
/////////////////////////////////////////////////
//test that id is not set and throws an exception
/////////////////////////////////////////////////
thrown.expect(DataException.class);
thrown.expectMessage("ID not set. Error in Database Implementation for adding code.");
try{
route.getID();
}catch (DataException e){
//e.printStackTrace();
}
route.getID();
}
@Test
public void testAirlineAdding(){
//1355,"British Airways",\N,"BA","BAW","SPEEDBIRD","United Kingdom","Y" AIrline
Airline airline = new Airline(1355,"British Airways","\\N","BA","BAW","SPEEDBIRD","United Kingdom","Y");
//sample entry
//BA,1355,SIN,3316,LHR,507,,0,744 777
//airline, airline ID (This is not parsed as this will be different
//from our database id for this route), source Aiport, source Airport ID (not parsed),
//destination airport, destination ID (not parsed), Codeshare, stops, Equipment
Route route = new Route("BA", "SIN", "LHR", "", 0, "744 777");
route.setAirline(airline);
assertEquals(airline, route.getAirline());
try {
assertTrue(airline.getID() == route.getAirlineID());
assertTrue(route.getAirlineID() == 1355);
}catch(DataException e){
fail("The ID is set before it should not fail.");
}
Airport sourceAirport = new Airport(3316,"Changi Intl","Singapore","Singapore","SIN","WSSS",1.350189,103.994433,22);
Airport destAirport = new Airport(507,"Heathrow","London","United Kingdom","LHR","EGLL",51.4775,-0.461389,83);
route.setSourceAirport(sourceAirport);
route.setDestinationAirport(destAirport);
assertEquals(sourceAirport, route.getSourceAirport());
assertEquals(destAirport, route.getDestinationAirport());
try {
assertTrue(route.getSourceID() == 3316);
assertTrue(route.getDestID() == 507);
} catch (DataException e) {
e.printStackTrace();
}
assertEquals(route.getDepartureAirport(), route.getSourceAirport().getIATA_FFA());
assertEquals(route.getArrivalAirport(), route.getDestinationAirport().getIATA_FFA());
}
@Test(expected = DataException.class)
public void testNameDuplicate() throws DataException{
//sample entry
//BA,1355,SIN,3316,LHR,507,,0,744 777
//airline, airline ID (This is not parsed as this will be different
//from our database id for this route), source Aiport, source Airport ID (not parsed),
//destination airport, destination ID (not parsed), Codeshare, stops, Equipment
//should only be a duplicate if every entry is the same
Route route = new Route("BA", "SIN", "LHR", "", 0, "744 777");
Route route1 = new Route("BA", "SIN", "LHR", "", 0, "744 777");
Route route2 = new Route("BA", "SII", "LHR", "", 0, "744 777");
Route route3 = new Route("BQ", "SIN", "LHR", "", 0, "744 777");
Route route4 = new Route("BA", "SIN", "RHR", "", 0, "744 777");
Route route5 = new Route("BA", "SIN", "LHR", "Y", 0, "744 777");
Route route6 = new Route("BA", "SIN", "LHR", "", 8, "744 777");
Route route7 = new Route("BA", "SIN", "LHR", "", 0, "745 777");
//this shouldn't throw
try {
route.hasDuplicate(route2);
route.hasDuplicate(route3);
route.hasDuplicate(route4);
route.hasDuplicate(route5);
route.hasDuplicate(route6);
route.hasDuplicate(route7);
} catch (DataException e) {
fail("These two routes are different they should not throw an error");
}
//this should throw an exception.
route.hasDuplicate(route1);
}
@Test
public void testGetPath(){
//sample entry
//BA,1355,SIN,3316,LHR,507,,0,744 777
//airline, airline ID (This is not parsed as this will be different
//from our database id for this route), source Aiport, source Airport ID (not parsed),
//destination airport, destination ID (not parsed), Codeshare, stops, Equipment
//should only be a duplicate if every entry is the same
Route route = new Route("BA", "SIN", "LHR", "", 0, "744 777");
Airport sourceAirport = new Airport(3316,"Changi Intl","Singapore","Singapore","SIN","WSSS",1.350189,103.994433,22);
Airport destAirport = new Airport(507,"Heathrow","London","United Kingdom","LHR","EGLL",51.4775,-0.461389,83);
assertTrue(route.getRoutePath().getRoute().size() == 0);
route.setSourceAirport(sourceAirport);
assertTrue(route.getRoutePath().getRoute().size() == 0);
route.setDestinationAirport(destAirport);
assertTrue(route.getRoutePath().getRoute().size() == 2);
}
@Test
public void testToString() {
//sample entry
//BA,1355,SIN,3316,LHR,507,,0,744 777
//airline, airline ID (This is not parsed as this will be different
//from our database id for this route), source Aiport, source Airport ID (not parsed),
//destination airport, destination ID (not parsed), Codeshare, stops, Equipment
//should only be a duplicate if every entry is the same
Route route = new Route("BA", "SIN", "LHR", "", 0, "744 777");
assertEquals(route.toString(), "BA flies from SIN to LHR on a 744 777 stopping 0 amount of times");
}
}

@ -0,0 +1,23 @@
package seng202.group9;/**
* Created by Gondr on 19/09/2016.
*/
import static org.junit.Assert.*;
import org.junit.Test;
import seng202.group9.Controller.SceneCode;
import seng202.group9.Controller.Session;
public class SessionTest {
@Test
public void testConstructor(){
Session session = new Session();
assertTrue(session.getSceneDisplayed() == SceneCode.INITIAL);
session.setSceneDisplayed(SceneCode.AIRLINE_RAW_DATA);
assertTrue(session.getSceneDisplayed() == SceneCode.AIRLINE_RAW_DATA);
Session session1 = new Session(SceneCode.ROUTE_RAW_DATA);
assertTrue(session1.getSceneDisplayed() == SceneCode.ROUTE_RAW_DATA);
}
}
Loading…
Cancel
Save