//Response to service by sending elevator public Elevator ServiceRequest(Floor floor) { Elevator returnElevator = new Elevator(); foreach (Elevator elevator in elevators) { if (elevator.Status == Utility.Status_Dormant) { elevator.CureentFloor = floor.CureentFloor; returnElevator = elevator; return returnElevator; } } //If all above elevators are busy then add in pending foreach (Elevator elevator in elevators) { if (elevator.Status != Utility.Status_Disabled) { //all elevators are busy store in pending request; if (!returnElevator.PendingRequests.ContainsKey(floor.CureentFloor)) { returnElevator = elevator; //add pending request returnElevator.PendingRequests.Add(floor.CureentFloor, floor.Direction); return returnElevator; } } } return returnElevator; }
public void ControllerConfigureElevatorFloor() { Floor floor50 = new Floor(50); //Get first elevator elevator1 = _controller.elevators[0]; elevator1.CureentFloor = 48; floor50.CureentFloor = 50; _controller.ConfigureElevatorForFloor(elevator1, floor50); //wait for 10 secs = 2 floors 6 seconds + 4 for door open and close System.Threading.Thread.Sleep(10500); Assert.AreEqual(elevator1.CureentFloor, 50); }
//send particular elevator to floor request public Elevator ConfigureElevatorForFloor(Elevator elevator, Floor floor) { int floorcount = (elevator.CureentFloor - floor.CureentFloor) * -1; int direction = 0; if (floor.CureentFloor >= elevator.CureentFloor) { direction = 1; } else { direction = 0; } elevator.Direction = direction; elevator.FloorCount = floorcount; this.StartService(elevator); return elevator; }
public void OutstandingRequestCheckFloorNo() { Elevator elevator3 = new Elevator(); Elevator elevator4 = new Elevator(); Floor floor10 = new Floor(10); Floor floor70 = new Floor(70); elevator1 = _controller.ServiceRequest(floor30); elevator1.CureentFloor = 30; elevator1.Direction = 1; elevator1.FloorCount = 2; _controller.StartService(elevator1); elevator2 = _controller.ServiceRequest(floor80); elevator2.CureentFloor = 30; elevator2.Direction = 1; elevator2.FloorCount = 2; _controller.StartService(elevator2); elevator3 = _controller.ServiceRequest(floor100); elevator3.CureentFloor = 30; elevator3.Direction = 1; elevator3.FloorCount = 2; _controller.StartService(elevator3); elevator4 = _controller.ServiceRequest(floor0); elevator4.CureentFloor = 30; elevator4.Direction = 1; elevator4.FloorCount = 2; _controller.StartService(elevator4); //Fifth request outstanding elevator1 = _controller.ServiceRequest(floor70); string floorNumber = ""; string direction; //loop through all pending request foreach (DictionaryEntry entry in elevator1.PendingRequests) { floorNumber = entry.Key.ToString(); direction = entry.Value.ToString(); if (direction == "1") { direction = Utility.Status_Moving_Up; } else { direction = Utility.Status_Moving_Down; } } Assert.AreEqual(floorNumber, "70"); }
public void OutstandingRequestCheck() { Elevator elevator3 = new Elevator(); Elevator elevator4 = new Elevator(); Floor floor10 = new Floor(10); Floor floor70 = new Floor(70); elevator1 = _controller.ServiceRequest(floor30); elevator1.CureentFloor = 30; elevator1.Direction = 1; elevator1.FloorCount = 2; _controller.StartService(elevator1); elevator2 = _controller.ServiceRequest(floor80); elevator2.CureentFloor = 30; elevator2.Direction = 1; elevator2.FloorCount = 2; _controller.StartService(elevator2); elevator3 = _controller.ServiceRequest(floor100); elevator3.CureentFloor = 30; elevator3.Direction = 1; elevator3.FloorCount = 2; _controller.StartService(elevator3); elevator4 = _controller.ServiceRequest(floor0); elevator4.CureentFloor = 30; elevator4.Direction = 1; elevator4.FloorCount = 2; _controller.StartService(elevator4); //Fifth outstanding request elevator1 = _controller.ServiceRequest(floor70); //total number of outstanding is one int pendReqCount = elevator1.PendingRequests.Count; Assert.AreEqual(1, pendReqCount); }