public void SampleLiftSystem() { var liftA = new Lift("A", 3, new List <int>() { 0 }); var liftB = new Lift("B", 2); var liftC = new Lift("C", 2, true); var liftD = new Lift("D", 0, new List <int>() { 0 }, false); var liftSystem = new LiftSystem( new List <int>() { 0, 1, 2, 3 }, new List <Lift>() { liftA, liftB, liftC, liftD }, new List <Call>() { new Call(1, Direction.Down) } ); Approvals.Verify(new LiftSystemPrinter().Print(liftSystem)); }
public void IfMoreCallsThanLifts_LastCallsGetProcessedEventually() { var liftA = new Lift("A", 0, new List <int> { }, false); var liftB = new Lift("B", 1, new List <int> { }, false); var callList = new List <Call> { new Call(1, Direction.Down), new Call(3, Direction.Down), new Call(2, Direction.Up), }; var lifts = new LiftSystem(new List <int>() { 0, 1, 2, 3 }, new List <Lift> { liftA, liftB }, callList); lifts.Tick(); lifts.Tick(); Approvals.Verify(new LiftSystemPrinter().Print(lifts)); }
public void NoLifts() { var floors = new List <int>() { 0, 1, 2, 3 }; var lifts = new List <Lift>(); var calls = new List <Call>(); var liftSystem = new LiftSystem(floors, lifts, calls); Approvals.Verify(new LiftSystemPrinter().Print(liftSystem)); }
// TODO: enable this test and finish writing it // [Fact] public void Something() { var liftA = new Lift("A", 0); var lifts = new LiftSystem(new List <int>() { 0, 1 }, new List <Lift> { liftA }, new List <Call>()); lifts.Tick(); }
public void IfNoCallsNoRequest_DoNothing() { var liftA = new Lift("A", 0); var lifts = new LiftSystem(new List <int>() { 0, 1 }, new List <Lift> { liftA }, new List <Call>()); lifts.Tick(); Approvals.Verify(new LiftSystemPrinter().Print(lifts)); }
public void IfNoCallOrRequest_NoChangeToState() { var liftA = new Lift("A", 0); var lifts = new LiftSystem(new List <int>() { 0, 1, 2, 3 }, new List <Lift> { liftA }, new List <Call>()); lifts.Tick(); Approvals.Verify(new LiftSystemPrinter().Print(lifts)); }
public void IfCurrentFloorIsRequestedAndDoorsClosed_OpensDoors() { var liftA = new Lift("A", 0, new List <int> { 0 }, false); var lifts = new LiftSystem(new List <int>() { 0, 1, 2, 3 }, new List <Lift> { liftA }, new List <Call>()); lifts.Tick(); Approvals.Verify(new LiftSystemPrinter().Print(lifts)); }
public void IfAnotherFloorIsRequestedAndDoorsOpen_CloseDoors() { var liftA = new Lift("A", 0, new List <int> { 1 }, true); var lifts = new LiftSystem(new List <int>() { 0, 1, 2, 3 }, new List <Lift> { liftA }, new List <Call>()); lifts.Tick(); Approvals.Verify(new LiftSystemPrinter().Print(lifts)); }
public void LiftSystemAcceptsCalls() { var liftA = new Lift("A", 0, new List <int> { }, false); var lifts = new LiftSystem(new List <int>() { 0, 1, 2, 3 }, new List <Lift> { liftA }, new List <Call>()); lifts.Call(new List <Call> { new Call(3, Direction.Down) }); Approvals.Verify(new LiftSystemPrinter().Print(lifts)); }
public void IfThereIsCallFromAnotherFloorAndDoorsClosed_MoveLift() { var liftA = new Lift("A", 0, new List <int> { }, false); var lifts = new LiftSystem(new List <int>() { 0, 1, 2, 3 }, new List <Lift> { liftA }, new List <Call> { new Call(1, Direction.Up) }); lifts.Tick(); Approvals.Verify(new LiftSystemPrinter().Print(lifts)); }
public void IfTwoRequests_GoToClosestFloor() { var liftA = new Lift("A", 1, new List <int> { 3, 2 }, false); var lifts = new LiftSystem(new List <int>() { 0, 1, 2, 3 }, new List <Lift> { liftA }, new List <Call> { }); lifts.Tick(); Approvals.Verify(new LiftSystemPrinter().Print(lifts)); }
public void IfCurrentFloorHasACallAndDoorsClosed_OpensDoorsAndClearsCall() { var liftA = new Lift("A", 0, new List <int> { }, false); var lifts = new LiftSystem(new List <int>() { 0, 1, 2, 3 }, new List <Lift> { liftA }, new List <Call> { new Call(0, Direction.Up) }); lifts.Tick(); Approvals.Verify(new LiftSystemPrinter().Print(lifts)); }
public void IfCallFromLowerFloor_AndDoorsClosed_MoveDown() { var liftA = new Lift("A", 1); var newCall = new Call(0, Direction.Up); var callList = new List <Call>(); callList.Add(newCall); var lifts = new LiftSystem(new List <int>() { 0, 1 }, new List <Lift> { liftA }, callList); lifts.Tick(); Approvals.Verify(new LiftSystemPrinter().Print(lifts)); }
public void OneLiftNoDoors() { var liftA = new Lift("A", 0, new List <int>() { 2, 3 }); var liftSystem = new LiftSystem( new List <int>() { 0, 1, 2, 3 }, new List <Lift>() { liftA }, new List <Call>()); Approvals.Verify(new LiftSystemPrinter().PrintWithoutDoors(liftSystem)); }
public void TwoLiftsInSystem_IfThereIsCall_MoveTheFirstLiftInTheList() { var liftA = new Lift("A", 3, new List <int> { }, false); var liftB = new Lift("B", 0, new List <int> { }, false); var lifts = new LiftSystem(new List <int>() { 0, 1, 2, 3 }, new List <Lift> { liftA, liftB }, new List <Call> { new Call(1, Direction.Up) }); lifts.Tick(); Approvals.Verify(new LiftSystemPrinter().Print(lifts)); }
public void LargeLiftSystem() { var liftA = new Lift("A", 3, new List <int>() { 3, 5, 7 }, false); var liftB = new Lift("B", 2, true); var liftC = new Lift("C", -2, new List <int>() { -2, 0 }, false); var liftD = new Lift("D", 8, new List <int>() { 0, -1, -2 }, true); var liftSVC = new Lift("SVC", 10, new List <int>() { 0, -1 }, false); var liftF = new Lift("F", 8, false); LiftSystem liftSystem = new LiftSystem( new List <int>() { -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }, new List <Lift>() { liftA, liftB, liftC, liftD, liftSVC, liftF }, new List <Call>() { new Call(1, Direction.Down), new Call(6, Direction.Down), new Call(5, Direction.Up), new Call(5, Direction.Down), new Call(-1, Direction.Up) }); Approvals.Verify(new LiftSystemPrinter().Print(liftSystem)); }
public string Print(LiftSystem liftSystem, LiftPrinter liftPrinter) { var sb = new StringBuilder(); var floorLength = CalculateFloorLength(liftSystem.FloorsInDescendingOrder()); foreach (var floor in liftSystem.FloorsInDescendingOrder()) { // if the floor number doesn't use all the characters, pad with whitespace var floorLabelLength = floor.ToString().Length; var floorPadding = GetWhitespace(floorLength - floorLabelLength); sb.Append(floorPadding); sb.Append(floor); var calls = string.Join("", liftSystem.CallsForFloor(floor).Select(PrintCallDirection)); // if there are less than 2 calls on a floor we add padding to keep everything aligned var callPadding = GetWhitespace(2 - calls.Length); sb.Append(" "); sb.Append(calls); sb.Append(callPadding); sb.Append(" "); var lifts = string.Join(" ", liftSystem.Lifts.Select(l => liftPrinter.PrintLiftForFloor(l, floor)).ToList()); sb.Append(lifts); // put the floor number at both ends of the line to make it more readable when there are lots of lifts, // and to prevent the IDE from doing rstrip on save and messing up the approved files. sb.Append(floorPadding); sb.Append(floor); sb.Append('\n'); } return(sb.ToString()); }
public string Print(LiftSystem liftSystem) { return(Print(liftSystem, new LiftAndDoorPrinter())); }
public string PrintWithoutDoors(LiftSystem liftSystem) { return(Print(liftSystem, new SimpleLiftPrinter())); }