Added delete Route Tests and toString test

main
YaFedImYaEatIm 9 years ago
parent b62bf7f1b1
commit 02c3e3ed99

@ -366,6 +366,21 @@ public class Airport {
public void delArrivalRoutes(int index){
arrivalRoutes.remove(index);
}
/**
* 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){
departureRoutes.remove(index);
}
/**
* Calculates the distance between this airport and another airport in kilometers.
@ -408,7 +423,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.";
}
}

@ -100,6 +100,11 @@ public class AirportUnitTest {
assertEquals(heathrow.getArrivalRoutes().get(2).getArrivalAirport(), "LHR2");
assertEquals(heathrow.getArrivalRoutes().get(3).getArrivalAirport(), "LHR3");
heathrow.delArrivalRoutes(0);
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);
@ -109,6 +114,11 @@ public class AirportUnitTest {
assertEquals(heathrow.getDepartureRoutes().get(2).getDepartureAirport(), "SIN2");
assertEquals(heathrow.getDepartureRoutes().get(3).getDepartureAirport(), "SIN3");
heathrow.delDepartureRoutes(0);
assertTrue(heathrow.getDepartureRoutes().size() == 3);
heathrow.delDepartureRoutes(heathrow.getDepartureRoutes().get(0));
assertTrue(heathrow.getDepartureRoutes().size() == 2);
//check set
heathrow.setArrivalRoutes(routes);
heathrow.setDepartureRoutes(routes);
@ -204,4 +214,13 @@ public class AirportUnitTest {
assertEquals(heathrow.getID(), 544);//check ID no id should be thrown
}
@Test
public void checkToString(){
//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.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.");
}
}

Loading…
Cancel
Save