Bug 243

Summary: The queuing passengers are removed in an incorrect order
Product: Bus Monitoring System Reporter: Celia <rabbitTrip96>
Component: Bus Monitoring SystemAssignee: Katie <bearTrip95>
Status: RESOLVED FIXED    
Severity: critical    
Priority: ---    
Version: unspecified   
Hardware: PC   
OS: Windows   
Attachments: Error screenshot - AssertionError

Description Celia 2017-12-01 23:15:02 HKT
Created attachment 14 [details]
Error screenshot - AssertionError

Celia 2017-11-6 15:00:12 HKT

Problem:
When I test the removeWaitingPassenger() in Station.class which uses to check whether the passenger in the queue can get on the bus based on the bus capacity. The problem is the queuing passengers were removed in an incorrect order.
Step to Reproduce:
Write test case for removeWiatingPassenger()
Run testRemoveWaitingPassenger#()

Actual Result: Child Passenger
Expected Result: Elderly Passenger
Comment 1 Katie 2017-12-02 15:39:30 HKT
Better, handle by creating a list to store the passengers being removed rather than directly remove from the waiting list. And test the passenger have been removed.


public ArrayList<Passenger> removeWaitingPassenger(int availableSize){

   for(int i = 0; i < waitingList.size(); i++){
       if(i < availableSize)
           waitingList.remove(waitingList.get(i));
   }
   return waitingList;

}

⇒
public ArrayList<Passenger> removeWaitingPassenger(int availableSize){
 ArrayList<Passenger> deleteList = new ArrayList<>();
   for(int i = 0; i < waitingList.size(); i++){
       if(i < availableSize)
           deleteList.add(waitingList.get(i));
   }

   for(Passenger p:deleteList){
       waitingList.remove(p);
   }
   return deleteList;
}