コード例 #1
0
        public void Handle(string input, ParkingLotManager parkingLotManager)
        {
            var tokens = input.Split(' ');

            if (tokens.Length == 2 && int.TryParse(tokens[1], out var slot))
            {
                parkingLotManager.LeaveParking(slot);
                Console.WriteLine($"Slot number {slot} is free");
            }
        }
コード例 #2
0
        public void LeaveParking_Adjusts_Parking_Lot()
        {
            var parkingLotManager = new ParkingLotManager();

            parkingLotManager.SetEmptyLots(1);
            parkingLotManager.GetNextEmptyLot();
            Assert.Equal(0, parkingLotManager.GetNextEmptyLot());

            parkingLotManager.LeaveParking(1);
            Assert.Equal(1, parkingLotManager.GetNextEmptyLot());
        }
コード例 #3
0
        public void GetNextEmptyLot_Returns_Closest_Empty_Lot_After_Adjusting_Car_Leaving()
        {
            var parkingLotManager = new ParkingLotManager();

            parkingLotManager.SetEmptyLots(3);

            parkingLotManager.ParkCar(new Car {
                RegistrationNumber = "Test-Registration-Number1", Color = "Test-Color1"
            }, parkingLotManager.GetNextEmptyLot());
            parkingLotManager.ParkCar(new Car {
                RegistrationNumber = "Test-Registration-Number2", Color = "Test-Color2"
            }, parkingLotManager.GetNextEmptyLot());
            parkingLotManager.ParkCar(new Car {
                RegistrationNumber = "Test-Registration-Number3", Color = "Test-Color3"
            }, parkingLotManager.GetNextEmptyLot());

            parkingLotManager.LeaveParking(2);
            parkingLotManager.LeaveParking(3);

            Assert.Equal(2, parkingLotManager.GetNextEmptyLot());
        }
コード例 #4
0
        public void GetRegistrationNumbersByCarColor_Returns_Empty_Registration_After_Leaving_Parking()
        {
            var parkingLotManager = new ParkingLotManager();

            parkingLotManager.SetEmptyLots(3);
            var car1 = new Car {
                RegistrationNumber = "Test-Registration-Number1", Color = "Test-Color"
            };

            parkingLotManager.ParkCar(car1, 1);
            parkingLotManager.LeaveParking(1);

            Assert.Empty(parkingLotManager.GetRegistrationNumbersByCarColor("Test-Color"));
        }