Пример #1
0
        public void ShouldReturnCabinetVacancyReate()
        {
            var cabinet = new Cabinet(2);
            cabinet.Store(new Bag());

            Assert.AreEqual(0.5, cabinet.VacancyRate(), 0.001);
        }
Пример #2
0
 public void ShouldGetBagSuccessfullyGivenUnusedTicked()
 {
     var cabinet = new Cabinet(1);
     var bag = new Bag();
     var ticket = cabinet.Store(bag);
     var actualBag = cabinet.Pick(ticket);
     Assert.AreSame(bag, actualBag);
 }
Пример #3
0
        public void ShouldStoreBagToCabinetWithHighestVacancyRate()
        {
            var cabinet1 = new Cabinet(2);
            cabinet1.Store(new Bag());

            var cabinet2 = new Cabinet(5);
            cabinet2.Store(new Bag());
            cabinet2.Store(new Bag());
            cabinet2.Store(new Bag());

            var cabinets = new List<Cabinet> { cabinet1, cabinet2 };
            var superRobot = new Robot(cabinets, new HighestVacancyRateSelector(cabinets));
            superRobot.Store(new Bag());

            Assert.AreEqual(0, cabinet1.AvailableBoxes());
            Assert.AreEqual(2, cabinet2.AvailableBoxes());
        }
Пример #4
0
        public void ShouldGetFormattedMessageOfAvaialbeBoxes()
        {
            var cabinet = new Cabinet(2);
            var bag = new Bag();
            cabinet.Store(bag);
            var message = cabinet.ReportEmptyBox(new EmptyBoxReporter());

            Assert.AreEqual(message, string.Format("Cabinet{0}:{1}\n", cabinet.GetHashCode(), cabinet.AvailableBoxes()));
            Console.Out.WriteLine(message);
        }
Пример #5
0
        public void ShouldShowErrorMessageWhenNoBoxAvailableInAnyCabinet()
        {
            var cabinet = new Cabinet(1);
            var cabinets = new List<Cabinet> {cabinet};
            cabinet.Store(new Bag());

            var robot = new Robot(cabinets, new SequentialSelector(cabinets));

            robot.Store(new Bag());
        }
Пример #6
0
        public void ShouldNotGetBagGivenUsedTicked()
        {
            var cabinet = new Cabinet(1);
            var bag = new Bag();
            var ticket = cabinet.Store(bag);
            var actualBag = cabinet.Pick(ticket);
            Assert.AreEqual(bag, actualBag);

            var secondBag = cabinet.Pick(ticket);
            Assert.IsNull(secondBag);
        }
Пример #7
0
        public void ShouldStoreBagInTheSecondAvailableCabinetIfFirstIsFull()
        {
            var cabinet1 = new Cabinet(1);
            cabinet1.Store(new Bag());
            var cabinet2 = new Cabinet(1);
            var cabinets = new List<Cabinet> {cabinet1, cabinet2};

            var robot = new Robot(cabinets, new SequentialSelector(cabinets));
            var ticket = robot.Store(new Bag());

            Assert.IsNotNull(ticket);
            Assert.AreEqual(0, cabinet2.AvailableBoxes());
        }
Пример #8
0
        public void ShouldPickBagSuccessfullyByRobot()
        {
            var cabinet1 = new Cabinet(1);
            cabinet1.Store(new Bag());
            var cabinet2 = new Cabinet(1);
            var cabinets = new List<Cabinet> {cabinet1, cabinet2};

            var robot = new Robot(cabinets, new SequentialSelector(cabinets));
            var bag = new Bag();
            var ticket = robot.Store(bag);

            var pickedBag = robot.Pick(ticket);
            Assert.AreSame(bag, pickedBag);
        }
Пример #9
0
        public void ShouldGetFormattedAvailbeBoxesMessagesForAllCabinets()
        {
            var cabinet1 = new Cabinet(1);
            cabinet1.Store(new Bag());
            var cabinet2 = new Cabinet(1);
            var cabinets = new List<Cabinet> { cabinet1, cabinet2 };

            var robot = new Robot(cabinets, new HighestVacancyRateSelector(cabinets));
            robot.Store(new Bag());
            var message = robot.ReportEmptyBox(new EmptyBoxReporter());

            Assert.AreEqual(message, string.Format("SuperRobot{0}\n  Cabinet{1}:{2}\n  Cabinet{3}:{4}\n",
                                                   robot.GetHashCode(),
                                                   cabinet1.GetHashCode(), cabinet1.AvailableBoxes(),
                                                   cabinet2.GetHashCode(), cabinet2.AvailableBoxes()
                                         ));
        }
Пример #10
0
 public void ShouldStoreBagSuccessfullyWhenThereIsBoxAvailable()
 {
     var cabinet = new Cabinet(1);
     var ticket =cabinet.Store(new Bag());
     Assert.IsNotNull(ticket);
 }
Пример #11
0
 public void ShouldShowErrorMessageWhenNoBoxAvailableToStoreBag()
 {
     var cabinet = new Cabinet(0);
     cabinet.Store(new Bag());
 }