Bug 243 - The queuing passengers are removed in an incorrect order
Summary: The queuing passengers are removed in an incorrect order
Status: RESOLVED FIXED
Alias: None
Product: Bus Monitoring System
Classification: Unclassified
Component: Bus Monitoring System (show other bugs)
Version: unspecified
Hardware: PC Windows
: --- critical
Assignee: Katie
URL:
Depends on:
Blocks:
 
Reported: 2017-12-01 23:15 HKT by Celia
Modified: 2017-12-02 15:39 HKT (History)
0 users

See Also:


Attachments
Error screenshot - AssertionError (17.03 KB, image/png)
2017-12-01 23:15 HKT, Celia
Details

Note You need to log in before you can comment on or make changes to this bug.
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;
}