public void WhenOpenDoorsAndNoDirection_ThenLiftDoorsOpenAndSetDireciton() { var lift = new Lift() { Level = 5, State = LiftState.Stopped, Direction = null }; var passengerGettingOn = new Passenger(0); var summons = new List <Summon>() { new Summon(5, Direction.Down, new List <Passenger>() { passengerGettingOn }) }; LiftService.ExecuteInstruction(Instruction.OpenDoors, lift, summons); Assert.True(lift.State == LiftState.DoorsOpen); // passengers get on Assert.Contains(passengerGettingOn, lift.Passengers); // answered summons are removed Assert.Empty(summons); // direction set Assert.True(lift.Direction == Direction.Down); }
public LiftController(IWordRepository repo, IProjectService projServ, IPermissionService permissionService) { _wordRepo = repo; _projectService = projServ; _liftService = new LiftService(_wordRepo, _projectService); _permissionService = permissionService; }
public void CanOptimiseInstructionsStartingAtGround(List <Summon> summons, List <Instruction> optimalInstructions) { var lift = new Lift { Level = 0 }; // 0 = Ground var instructions = LiftService.CalculateOptimalInstructions(lift, summons); Assert.Equal(instructions, optimalInstructions); }
public IHttpActionResult TravelToNextStop() { var lift = HttpContext.Current.Application["Lift"]; var liftService = new LiftService((Lift)lift); liftService.Travel(); HttpContext.Current.Application["Lift"] = liftService.Lift; return(Ok()); }
public IHttpActionResult RequestStop(StopModel model) { var lift = HttpContext.Current.Application["Lift"]; var liftService = new LiftService((Lift)lift); liftService.RequestStop(model); HttpContext.Current.Application["Lift"] = liftService.Lift; return(Ok()); }
public void WhenStop_ThenLiftStopped() { var lift = new Lift() { State = LiftState.Moving }; var summons = new List <Summon>(); LiftService.ExecuteInstruction(Instruction.Stop, lift, summons); Assert.True(lift.State == LiftState.Stopped); }
public void WhenTravelDown_ThenMoveLiftDown() { var lift = new Lift() { Level = 5, State = LiftState.Stopped }; var summons = new List <Summon>(); LiftService.ExecuteInstruction(Instruction.TravelDown, lift, summons); Assert.True(lift.State == LiftState.Moving); Assert.True(lift.Direction == Direction.Down); Assert.True(lift.Level == 4); }
public void WhenStoppedAndSummonsAtSameLevelWithOppositeDirectionAndSummonsInSameDirection_ThenDontOpen() { var lift = new Lift { Level = 1, State = LiftState.Stopped, Direction = Direction.Up }; var summons = new List <Summon>() { new Summon(1, Direction.Down, new List <Passenger>()), new Summon(2, Direction.Down, new List <Passenger>()) }; var nextInstruction = LiftService.CalculateNextInstruction(lift, summons); Assert.False(nextInstruction == Instruction.OpenDoors); }
public void WhenDoorsOpenAndSummonsAtSameLevelAndDirection_ThenStayOpen() { var lift = new Lift { Level = 1, State = LiftState.DoorsOpen, Direction = Direction.Up }; var summons = new List <Summon>() { new Summon(1, Direction.Up, new List <Passenger>()) }; var nextInstruction = LiftService.CalculateNextInstruction(lift, summons); Assert.True(nextInstruction == Instruction.OpenDoors); }
public void WhenDoorsOpenAndPassengerAtDesiredLevel_ThenStayOpen() { var lift = new Lift { Level = 1, State = LiftState.DoorsOpen, Passengers = new List <Passenger>() { new Passenger(1) } }; var summons = new List <Summon>(); var nextInstruction = LiftService.CalculateNextInstruction(lift, summons); Assert.True(nextInstruction == Instruction.OpenDoors); }
public void WhenStoppedDirectionDownAndSummonsBelow_ThenTravelDown() { var lift = new Lift { Level = 5, State = LiftState.Stopped, Direction = Direction.Down }; var summons = new List <Summon>() { new Summon(2, Direction.Up, new List <Passenger>()) }; var nextInstruction = LiftService.CalculateNextInstruction(lift, summons); Assert.True(nextInstruction == Instruction.TravelDown); }
public void WhenStoppedDirectionUpAndSummonsAbove_ThenTravelUp() { var lift = new Lift { Level = 1, State = LiftState.Stopped, Direction = Direction.Up }; var summons = new List <Summon>() { new Summon(2, Direction.Down, new List <Passenger>()) }; var nextInstruction = LiftService.CalculateNextInstruction(lift, summons); Assert.True(nextInstruction == Instruction.TravelUp); }
public void WhenStoppedAndDirectionDownAndNoPassengersAndNoSummonsBelowAndSummonOnLevel_ThenOpenDoors() { var lift = new Lift { Level = 5, State = LiftState.Stopped, Direction = Direction.Down }; var summons = new List <Summon>() { new Summon(5, Direction.Up, new List <Passenger>()) }; var nextInstruction = LiftService.CalculateNextInstruction(lift, summons); Assert.True(nextInstruction == Instruction.OpenDoors); }
public void WhenMovingAndPassengerAtDesiredLevel_ThenStop() { var lift = new Lift { Level = 1, State = LiftState.Moving, Direction = Direction.Up, Passengers = new List <Passenger>() { new Passenger(1) } }; var summons = new List <Summon>(); var nextInstruction = LiftService.CalculateNextInstruction(lift, summons); Assert.True(nextInstruction == Instruction.Stop); }
public void WhenStoppedAndDirectionDownAndPassengersDesiredLevelBelow_ThenTravelDown() { var lift = new Lift { Level = 5, State = LiftState.Stopped, Direction = Direction.Down, Passengers = new List <Passenger>() { new Passenger(2) } }; var summons = new List <Summon>(); var nextInstruction = LiftService.CalculateNextInstruction(lift, summons); Assert.True(nextInstruction == Instruction.TravelDown); }
public void WhenStoppedDirectionUpAndPassengersDesiredLevelAbove_ThenTravelUp() { var lift = new Lift { Level = 1, State = LiftState.Stopped, Direction = Direction.Up, Passengers = new List <Passenger>() { new Passenger(4) } }; var summons = new List <Summon>(); var nextInstruction = LiftService.CalculateNextInstruction(lift, summons); Assert.True(nextInstruction == Instruction.TravelUp); }
public void WhenMovingAndSummonAtLevelWithOppositeDirectionAndNoOtherSummonsOrPassengers_ThenStop() { var lift = new Lift { Level = 5, State = LiftState.Moving, Direction = Direction.Down, Passengers = new List <Passenger>() }; var summons = new List <Summon>() { new Summon(5, Direction.Up, new List <Passenger>()) }; var nextInstruction = LiftService.CalculateNextInstruction(lift, summons); Assert.True(nextInstruction == Instruction.Stop); }
static void Main(string[] args) { Console.WriteLine("Elevator Company Tests"); Console.WriteLine("-----------------------------------------"); var lift = new Lift(); var testA = new List <Summon> { new Summon(0, Direction.Up, new List <Passenger>() { new Passenger(5) }) }; var instructions = LiftService.CalculateOptimalInstructions(lift, testA); Console.WriteLine("Test A"); PrintInstructions(instructions); lift = new Lift(); var testB = new List <Summon> { new Summon(6, Direction.Down, new List <Passenger> { new Passenger(1) }), new Summon(4, Direction.Down, new List <Passenger> { new Passenger(1) }), }; instructions = LiftService.CalculateOptimalInstructions(lift, testB); Console.WriteLine("Test B"); PrintInstructions(instructions); lift = new Lift(); var testC = new List <Summon> { new Summon(2, Direction.Up, new List <Passenger> { new Passenger(6) }), new Summon(4, Direction.Down, new List <Passenger> { new Passenger(0) }), }; instructions = LiftService.CalculateOptimalInstructions(lift, testC); Console.WriteLine("Test C"); PrintInstructions(instructions); lift = new Lift(); var testD = new List <Summon> { new Summon(0, Direction.Up, new List <Passenger> { new Passenger(5) }), new Summon(4, Direction.Down, new List <Passenger> { new Passenger(0) }), new Summon(10, Direction.Down, new List <Passenger> { new Passenger(0) }) }; instructions = LiftService.CalculateOptimalInstructions(lift, testD); Console.WriteLine("Test D"); PrintInstructions(instructions); Console.ReadLine(); }
public LiftsController(LiftService service) { _liftservice = service; }
public void Setup() { var lift = new Lift(11); _liftService = new LiftService(lift); }