|
|
|
|
@ -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;
|
|
|
|
|
@ -121,17 +123,85 @@ 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, 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.getID(), 544);//check ID no id should be thrown
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|