@Test
/**
* Find the nearest ambulance when there are none free.
*/
public void findAmbulanceNoneFree()
{
shadow.clear();
control = new AmbulanceControl();
makeAmbulance(1, 1, false);
assertEquals(null, control.findNearestFree(1));
}
@Test
/**
* Find the nearest ambulance when there is one free.
*/
public void findAmbulanceOneFree()
{
shadow.clear();
control = new AmbulanceControl();
makeAmbulance(1, 1, false);
Ambulance ambulance = makeAmbulance(2, 1, true);
assertEquals(ambulance, control.findNearestFree(1));
}
@Test
/**
* Find the nearest ambulance when there is more than one free.
*/
public void findAmbulanceLowest()
{
shadow.clear();
control = new AmbulanceControl();
makeAmbulance(2, 1, true);
Ambulance ambulance = makeAmbulance(1, 1, true);
assertEquals(ambulance, control.findNearestFree(1));
}
@Test
/**
* Find the nearest ambulance when there are none.
*/
public void findAmbulanceLowestMultiple()
{
shadow.clear();
control = new AmbulanceControl();
for(int id = 5; id >= 2; id--) {
makeAmbulance(id, 1, true);
}
Ambulance ambulance = makeAmbulance(1, 1, true);
assertEquals(ambulance, control.findNearestFree(1));
}
@Test
/**
* Find the nearest ambulance in neighbouring areas.
*/
public void findAmbulanceNeighbours()
{
shadow.clear();
control = new AmbulanceControl();
Ambulance ambulance = makeAmbulance(1, 1, true);
makeAmbulance(2, 3, true);
assertEquals(ambulance, control.findNearestFree(2));
}
@Test
/**
* Find the nearest ambulance in neighbouring areas
* when only one is free.
*/
public void findAmbulanceNeighboursOneFree()
{
shadow.clear();
control = new AmbulanceControl();
makeAmbulance(1, 1, false);
Ambulance ambulance = makeAmbulance(2, 3, true);
assertEquals(ambulance, control.findNearestFree(2));
}
@Test
/**
* Find the nearest ambulance in neighbouring areas.
*/
public void findAmbulanceNeighboursFurther()
{
shadow.clear();
control = new AmbulanceControl();
makeAmbulance(1, 2, false);
Ambulance ambulance = makeAmbulance(5, 1, true);
assertEquals(ambulance, control.findNearestFree(3));
}