Example #1
0
        public void ShouldReturnCabinetVacancyReate()
        {
            var cabinet = new Cabinet(2);
            cabinet.Store(new Bag());

            Assert.AreEqual(0.5, cabinet.VacancyRate(), 0.001);
        }
Example #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);
 }
Example #3
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());
        }
Example #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);
        }
Example #5
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);
        }
        public void ShouldPickBagSuccessfullyBySuperRobot()
        {
            var cabinet1 = new Cabinet(1);
            var cabinet2 = new Cabinet(2);
            var cabinets = new List<Cabinet> { cabinet1, cabinet2 };
            var superRobot = new Robot(cabinets, new HighestVacancyRateSelector(cabinets));
            var bag = new Bag();
            var ticket = superRobot.Store(bag);

            var pickedBag = superRobot.Pick(ticket);
            Assert.AreSame(bag, pickedBag);
        }
Example #7
0
        public void ShouldStoreBagSuccessfullyInFirstAvailableBox()
        {
            var cabinet1 = new Cabinet(1);
            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, cabinet1.AvailableBoxes());
        }
Example #8
0
        public void ShouldStoreBagByAnyRobot()
        {
            var cabinet = new Cabinet(10);
            var cabinets1 = new List<Cabinet> {cabinet};
            var robot = new Robot(cabinets1, new SequentialSelector(cabinets1));
            var manager = new Manager(new List<IStoreable> {robot});

            var storedBag = new Bag();
            var ticket = manager.Store(storedBag);

            Assert.AreEqual(9, cabinet.AvailableBoxes());
            Assert.AreSame(storedBag, manager.Pick(ticket));
        }
Example #9
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());
        }
Example #10
0
        public void ShouldManagerManageOtherMangers()
        {
            var cabinet1 = new Cabinet(2);
            var manager1 = new Manager(new List<IStoreable> {cabinet1});

            var manager = new Manager(new List<IStoreable> {manager1});

            var storedBag = new Bag();
            var ticket = manager.Store(storedBag);
            Assert.AreEqual(1, cabinet1.AvailableBoxes());

            var pickedBag = manager.Pick(ticket);
            Assert.AreSame(storedBag, pickedBag);
        }
Example #11
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);
        }
        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());
        }
        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()
                                         ));
        }
Example #14
0
        public void ShouldManageMutipleRobots()
        {
            var cabinet1 = new Cabinet(10);
            var cabinets1 = new List<Cabinet> {cabinet1};
            var robot = new Robot(cabinets1, new SequentialSelector(cabinets1));

            var cabinet2 = new Cabinet(5);
            var cabinets2 = new List<Cabinet> {cabinet2};
            var smartRobot = new Robot(cabinets2, new MostAvailableSelector(cabinets2));

            var cabinet3 = new Cabinet(4);
            var cabinets3 = new List<Cabinet> {cabinet3};
            var superRobot = new Robot(cabinets3, new HighestVacancyRateSelector(cabinets3));

            var manager = new Manager(new List<IStoreable> {robot, smartRobot, superRobot});

            manager.Store(new Bag());

            Assert.AreEqual(9, cabinet1.AvailableBoxes());
        }
Example #15
0
        public void ShouldGetFormattedAvailbeBoxesMessagesFromAllManagedCabinets()
        {
            var cabinet1 = new Cabinet(10);
            var cabinets1 = new List<Cabinet> {cabinet1};
            var robot = new Robot(cabinets1, new SequentialSelector(cabinets1));
            var cabinet2 = new Cabinet(2);
            var manager = new Manager(new List<IStoreable> {robot, cabinet2});
            manager.Store(new Bag());

            var message = manager.ReportEmptyBox(new EmptyBoxReporter());

            Assert.AreEqual(string.Format("Manager{0}\n" +
                                                   "  Robot{1}\n" +
                                                   "    Cabinet{2}:{3}\n"+
                                                   "  Cabinet{4}:{5}\n",
                                                   manager.GetHashCode(),
                                                   robot.GetHashCode(),
                                                   cabinet1.GetHashCode(), cabinet1.AvailableBoxes(),
                                                   cabinet2.GetHashCode(), cabinet2.AvailableBoxes()

                                         ), message);
        }
Example #16
0
 public void ShouldTellWhetherCanStoreBag()
 {
     var cabinet = new Cabinet(1);
     var canStore = cabinet.CanStore();
     Assert.IsTrue(canStore);
 }
Example #17
0
 public void ShouldStoreBagSuccessfullyWhenThereIsBoxAvailable()
 {
     var cabinet = new Cabinet(1);
     var ticket =cabinet.Store(new Bag());
     Assert.IsNotNull(ticket);
 }
Example #18
0
 public void ShouldShowErrorMessageWhenNoBoxAvailableToStoreBag()
 {
     var cabinet = new Cabinet(0);
     cabinet.Store(new Bag());
 }
Example #19
0
        public void ShouldTellWhetherCanStoreBox()
        {
            var cabinet = new Cabinet(1);
            var cabinets = new List<Cabinet> {cabinet};
            var robot = new Robot(cabinets, new SequentialSelector(cabinets));

            var canStore = robot.CanStore();
            Assert.IsTrue(canStore);
        }
Example #20
0
 public void ShouldReturnAvailableBoxNumber()
 {
     var cabinet = new Cabinet(1);
     Assert.AreEqual(1, cabinet.AvailableBoxes());
 }
Example #21
0
        public void ShouldStoreBagWithDirectlyByCabinet()
        {
            var cabinet = new Cabinet(10);
            var manager = new Manager(new List<IStoreable> {cabinet});
            var storedBag = new Bag();

            var ticket = manager.Store(storedBag);

            Assert.AreEqual(9, cabinet.AvailableBoxes());

            var pickedBag = manager.Pick(ticket);
            Assert.AreSame(storedBag, pickedBag);
        }