Symantec Interview Question
Senior Software Development EngineersCountry: India
The lift will have a state, so this state can be represented using a state design pattern.
A state would comprise of current direction the lift is going (UP, DOWN) and the current floor number.
States = GoingUp, GoingDown,
When some request comes in then the request would have two parameters (floor number from which the request came, and the direction in which the user wants to go (i.e.UP/DOWN)).
The logic will be like this:
Each time the request comes it will be stored into a queue.
When the lift has completed the current request and is free, it will take the next request from the queue.
It will check what is its current state (direction/floor no.) and take the appropriate action by calling methods on its abstract state pointer.
In case the request is for going down while it is going up and there are suppose n floors and lift is at n-1 floor and someone has placed a reqeust to go down from nth floor, then lift's logic should be such that it should go up and fulfill the request for going down from nth floor first before going down from n-1 th floor.
There might be a better logic so that all the user are served with minimum turn around time(TAT) and average job completion time is minimum.
Happy Path testing:
1. Lift is going in a same direction until the final request is served.
2. Lift is functioning well with accepted load.
Negative testing:
1. Testing the behavior of lift when power failure when its idle and functioning.
2. When acceptable high load
3. Speed with out any load
4. When more than acceptable load
5. Recalculate its function (which floor to stop) in every floor based on internal and external requests without changing its direction until there is no more requests available for the same direction.
6. Is automatic doors functioning well
7. If it s manual doors, check how its functioning without closing it
8. function of alarm button, door close and open button
9. check the behavior when fire happens by simulator
10. Speed must not be vary at any time and in any situation
11. check the function of Air condition system inside lift with / without load
12. Check the backup power for lights and air condition system inside life when there is power failure.
13. check the sensors of automatic doors of lift.
14. Able to accept multiple requests at the same time
15. Check the queuing mechanism, if there are more lifts.
class Lift
{
state : moving, stopped
side : up/Down
currentfloor
openDooe()
closeDoor()
moveUp()
moveDown();
}
Manager
{
queue<Request> RequestQueueUp
queue<Request> RequestQueueDown
Lift * lift
void eventReceived(direction, Floor )
{
if( direction == "UP")
RequestQueueUp.insert( Request(up, floor));
else
RequestQueueUp.insert( Request(down, floor));
}
}
Request
{
requestFromWhichFloor
direction up/down
}
class Lift
{
state : moving, stopped
side : up/Down
currentfloor
openDooe()
closeDoor()
moveUp()
moveDown();
}
Manager
{
queue<Request> RequestQueueUp
queue<Request> RequestQueueDown
Lift * lift
void eventReceived(direction, Floor )
{
if( direction == "UP")
RequestQueueUp.insert( Request(up, floor));
else
RequestQueueUp.insert( Request(down, floor));
}
}
Request
{
requestFromWhichFloor
direction up/down
}
class Lift
{
state : moving, stopped
side : up/Down
currentfloor
openDooe()
closeDoor()
moveUp()
moveDown();
}
Manager
{
queue<Request> RequestQueueUp
queue<Request> RequestQueueDown
Lift * lift
void eventReceived(direction, Floor )
{
if( direction == "UP")
RequestQueueUp.insert( Request(up, floor));
else
RequestQueueUp.insert( Request(down, floor));
}
}
Request
{
requestFromWhichFloor
direction up/down
}
To answer this question in an interview scenario which merely required me to provide a solution I would attempt to 'think aloud' the solution below;
- Billy April 05, 2013* The lift object needs to hold 'state'; current direction of travel and current floor (State pattern)
* It also needs to hold a list of external requests (which floor the request came from and the time the request was sent)
* It also needs to hold a list of internal requests (the floor the request to go to and the time the request was received)
* It also needs to know its boundaries (min = 0 (ground floor) and max = n (top floor))
* We will need an orchestrating object to send information to the lift to simulate users (info : floor request from and to)
* The lift object will need to accept the information sent from the orchestrating object, timestamp it and process it, i.e. change its state.
* The lift needs to recalculate which floors to stop at but not change its direction unless there are no more requests for the current direction
... this was without any preparation so have most probably missed some areas but it is similar to the 'Mars Rover' test in which you send commands to a droid which then change the state (position) of the droid.
Hope this helps someone.