Ejemplo n.º 1
0
        public void should_store_bag_in_sequence_given_all_kinds_of_robots_and_lockers()
        {
            var locker  = new Locker(1);
            var lockers = new List <Locker> {
                locker
            };
            var smartRobot = new SmartRobot(new List <Locker> {
                new Locker(1)
            });
            var superRobot = new SuperRobot(new List <Locker> {
                new Locker(1)
            });

            var robots = new List <SmartRobot> {
                smartRobot,
                superRobot
            };

            var manager = new Manager(lockers, robots);
            var bag1    = new Bag();
            var bag2    = new Bag();
            var bag3    = new Bag();
            var ticket1 = manager.Store(bag1);
            var ticket2 = manager.Store(bag2);
            var ticket3 = manager.Store(bag3);

            Assert.Equal(bag1, locker.Pick(ticket1));
            Assert.Equal(bag2, smartRobot.Pick(ticket2));
            Assert.Equal(bag3, superRobot.Pick(ticket3));
        }
        public void should_return_bag_when_pick_if_bag_is_stored_into_super_robot()
        {
            var superRobot = new SuperRobot();

            superRobot.Manage(new List <Locker> {
                new Locker(1)
            });

            var smartRobot = new SmartRobot();

            smartRobot.Manage(new List <Locker> {
                new Locker(1)
            });

            var robot = new Robot();

            robot.Manage(new List <Locker> {
                new Locker(1)
            });

            var locker = new Locker(1);

            var manager = new Manager(locker, robot, smartRobot, superRobot);

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

            var pickedBag = manager.Pick(ticket);

            Assert.AreEqual(pickedBag, storedBag);
        }
        public void should_store_into_super_robot_when_locker_and_robot_and_smart_robot_are_all_full()
        {
            var superRobot = new SuperRobot();

            superRobot.Manage(new List <Locker> {
                new Locker(1)
            });

            var smartRobot = new SmartRobot();

            smartRobot.Manage(new List <Locker> {
                new Locker(1)
            });

            var robot = new Robot();

            robot.Manage(new List <Locker> {
                new Locker(1)
            });

            var locker = new Locker(1);

            var manager = new Manager(locker, robot, smartRobot, superRobot);

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

            Assert.NotNull(ticket);
            Assert.NotNull(superRobot.Pick(ticket));
        }
 public Manager(Locker locker, Robot robot = null, SmartRobot smartRobot = null, SuperRobot superRobot = null)
 {
     this.locker     = locker;
     this.robot      = robot;
     this.smartRobot = smartRobot;
     this.superRobot = superRobot;
 }
        public void should_store_bags_in_order_when_manager_manage_lockers_and_robots()
        {
            var locker  = new Locker(1);
            var lockers = new List <Locker> {
                locker
            };
            var robot = new Robot(new List <Locker> {
                new Locker(1)
            });
            var smartRobot = new SmartRobot(new List <Locker> {
                new Locker(1)
            });
            var superRobot = new SuperRobot(new List <Locker> {
                new Locker(1)
            });
            var baseRobots = new List <BaseRobot> {
                robot, smartRobot, superRobot
            };
            var manager = new Manager(lockers, baseRobots);
            var bag1    = new Bag();
            var bag2    = new Bag();
            var bag3    = new Bag();
            var bag4    = new Bag();
            var ticket1 = manager.Store(bag1);
            var ticket2 = manager.Store(bag2);
            var ticket3 = manager.Store(bag3);
            var ticket4 = manager.Store(bag4);

            Assert.Equal(bag1, locker.Pick(ticket1));
            Assert.Equal(bag2, robot.Pick(ticket2));
            Assert.Equal(bag3, smartRobot.Pick(ticket3));
            Assert.Equal(bag4, superRobot.Pick(ticket4));
        }
        public void should_get_error_message_when_manager_is_full()
        {
            //Given
            var        bagKeepers       = new List <IBagKeeper>();
            IBagKeeper lockerForManager = new Locker(1);

            lockerListForRobot = new List <IBagKeeper>();
            lockerListForRobot.Add(new Locker(1));
            var lockerListForSmartRobot = new List <IBagKeeper>();

            lockerListForSmartRobot.Add(new Locker(1));
            var lockerListForSuperRobot = new List <IBagKeeper>();

            lockerListForSuperRobot.Add(new Locker(1));
            robot = new Robot(lockerListForRobot);
            var smartRobot = new SmartRobot(lockerListForSmartRobot);
            var superRobot = new SuperRobot(lockerListForSuperRobot);

            bagKeepers.Add(smartRobot);
            bagKeepers.Add(superRobot);
            bagKeepers.Add(lockerForManager);
            bagKeepers.Add(robot);
            manager = new Manager(bagKeepers);

            //When
            for (int i = 0; i < 4; i++)
            {
                manager.Store(new Bag());
            }

            //Then
            var ex = Assert.Throws <ArgumentException>(() => manager.Store(new Bag()));

            Assert.That(ex.Message, Is.EqualTo("The manager is full!"));
        }
Ejemplo n.º 7
0
 public void Store_One_Bag_When_Not_All_Cabinets_Full_Return_Ticket()
 {
     var smartRobot = new SmartRobot(new List<Cabinet> { new Cabinet(0), new Cabinet(1), new Cabinet(0) });
     var bag = new Bag();
     var ticket = smartRobot.Store(bag);
     Assert.IsNotNull(ticket);
 }
Ejemplo n.º 8
0
        public void should_store_failed_when_robot_manange_no_locker()
        {
            var lockers = Enumerable.Range(0, 0).Select(i => new Locker(1)).ToList();
            var robot   = new SmartRobot(lockers);
            var ticket  = robot.Store(new Bag());

            Assert.Null(ticket);
        }
Ejemplo n.º 9
0
 public void Pick_One_Bag_When_Cabinet_Has_My_Bag_And_Give_Valid_Ticket()
 {
     var smartRobot = new SmartRobot(new List<Cabinet> { new Cabinet(0), new Cabinet(1), new Cabinet(0) });
     var bag = new Bag();
     var ticket = smartRobot.Store(bag);
     Bag pickBag = smartRobot.Pick(ticket);
     Assert.AreEqual(bag,pickBag);
 }
Ejemplo n.º 10
0
        public void should_pick_failed_when_given_no_existing_ticket_to_robot()
        {
            var lockers = Enumerable.Range(0, 5).Select(i => new Locker(1)).ToList();
            var robot   = new SmartRobot(lockers);
            var bag     = robot.Pick(new Ticket());

            Assert.Null(bag);
        }
Ejemplo n.º 11
0
        public void Store_One_Bag_When_All_Cabinets_Full_Return_Null_Ticket()
        {
            List<Cabinet> emptyCabinetList = new List<Cabinet> { new Cabinet(0) };
            var robot = new SmartRobot(emptyCabinetList);

            var ticket = robot.Store(new Bag());

            Assert.IsNull(ticket);
        }
Ejemplo n.º 12
0
        public void Should_Give_Correct_Information_When_Invalid_Ticket_Passed_To_Robot()
        {
            List<Cabinet> notEmptyCabinetList = new List<Cabinet> { new Cabinet(1) };
            var robot = new SmartRobot(notEmptyCabinetList);

            var invalidTicket = new Ticket();

            robot.Pick(invalidTicket);
        }
        public void should_get_a_ticket_when_store_a_bag()
        {
            SmartRobot smartRobot = new SmartRobot(oneLocker);
            Bag        bag        = new Bag();

            Ticket ticket = smartRobot.Store(bag);

            Assert.NotNull(ticket);
        }
Ejemplo n.º 14
0
 public void Pick_One_Bag_When_Cabinet_Has_My_Bag_And_Give_InValid_Ticket()
 {
     var smartRobot = new SmartRobot(new List<Cabinet> { new Cabinet(0), new Cabinet(1), new Cabinet(0) });
     var bag = new Bag();
     var ticket = smartRobot.Store(bag);
     smartRobot.Pick(ticket);
     Bag returnBag = smartRobot.Pick(ticket);
     Assert.IsNull(returnBag);
 }
Ejemplo n.º 15
0
 public void StoreBag_In_MostEmpty_Cabinet()
 {
     var smartRobot = new SmartRobot(new List<Cabinet> { new Cabinet(2), new Cabinet(2), new Cabinet(2) });
     var bag = new Bag();
     smartRobot.Store(new Bag());
     smartRobot.Store(new Bag());
     Assert.AreEqual(1, smartRobot.GetCabinet(0).RemainingEmptyBoxCount);
     Assert.AreEqual(1, smartRobot.GetCabinet(1).RemainingEmptyBoxCount);
 }
        public void SetUp()
        {
            locker1 = new Locker(1);
            locker2 = new Locker(2);
            lockers = new List <Locker> {
                locker1, locker2
            };

            smartRobot = new SmartRobot();
        }
Ejemplo n.º 17
0
        public void should_return_ticket_after_store_a_bag_by_robot()
        {
            var bag     = new Bag();
            var lockers = Enumerable.Range(0, 1).Select(i => new Locker(1)).ToList();
            var robot   = new SmartRobot(lockers);


            Ticket ticket = robot.Store(bag);

            Assert.NotNull(ticket);
        }
Ejemplo n.º 18
0
        public void should_get_a_ticket_when_smartrobot_store_a_bag_in_locker()
        {
            smartRobot = new SmartRobot(new List <Locker>()
            {
                new Locker(1)
            });
            var    bag    = new Bag();
            Ticket ticket = smartRobot.Store(bag);

            Assert.NotNull(ticket);
        }
        public void should_return_error_message_when_robot_without_lockers()
        {
            List <IBagKeeper> emptyLockers = new List <IBagKeeper>();
            var bag1 = new Bag();

            var smartRobot = new SmartRobot(emptyLockers);

            var ex = Assert.Throws <ArgumentException>(() => smartRobot.Store(bag1));

            Assert.That(ex.Message, Is.EqualTo("No locker is available"));
        }
Ejemplo n.º 20
0
        public void should_store_bag_in_locker_which_has_more_capacity()
        {
            var locker1 = new Locker(1);
            var locker2 = new Locker(2);

            smartRobot = new SmartRobot(new List <Locker>()
            {
                locker1, locker2
            });
            smartRobot.Store(new Bag());
            Assert.Equal(1, locker2.AvailableCount);
        }
Ejemplo n.º 21
0
        public void Return_Ticket_When_Seats_Available()
        {
            var oneseatcabinet = new Cabinet(1);
            var twoseatscabinet = new Cabinet(2);
            List<Cabinet> cabinets = new List<Cabinet> { oneseatcabinet, twoseatscabinet };
            var robot = new SmartRobot(cabinets);

            var ticket = robot.Store(new Bag());

            Assert.IsNotNull(ticket);
            Assert.IsFalse(oneseatcabinet.IsFull());
        }
Ejemplo n.º 22
0
        public void should_return_bag_when_pick_bag_from_robot_with_ticket()
        {
            var expectedBag = new Bag();
            var lockers     = Enumerable.Range(0, 1).Select(i => new Locker(1)).ToList();
            var robot       = new SmartRobot(lockers);

            var ticket = robot.Store(expectedBag);

            var bag = robot.Pick(ticket);

            Assert.Equal(expectedBag, bag);
        }
Ejemplo n.º 23
0
        public void should_pick_failed_when_given_used_ticket_to_robot()
        {
            var lockers    = Enumerable.Range(0, 5).Select(i => new Locker(1)).ToList();
            var robot      = new SmartRobot(lockers);
            var usedTicket = robot.Store(new Bag());

            robot.Store(new Bag());
            robot.Pick(usedTicket);

            var bagNoExisting = robot.Pick(usedTicket);

            Assert.Null(bagNoExisting);
        }
Ejemplo n.º 24
0
        public void should_return_the_bag_stored_in_smartrobot_by_the_ticket()
        {
            var lockers = new List <Locker>();
            var locker  = new Locker(1);

            lockers.Add(locker);

            var robot  = new SmartRobot(lockers);
            var bag    = new Bag();
            var ticket = robot.Store(bag);

            Assert.AreSame(robot.Pick(ticket), bag);
        }
Ejemplo n.º 25
0
        public void should_throw_exception_when_store_a_bag_if_all_lockers_are_full()
        {
            smartRobot = new SmartRobot(new List <Locker>()
            {
                new Locker(1), new Locker(2)
            });
            for (var i = 0; i < 3; i++)
            {
                smartRobot.Store(new Bag());
            }

            Assert.Throws <InvalidOperationException>(() => smartRobot.Store(new Bag()));
        }
Ejemplo n.º 26
0
        public void CreateSmartRobotTest()
        {
            //Arrange
            var expected = new SmartRobot(null)
            {
                DecodingProbability = 100, Carrying = 10
            };
            var robotCreator = new SmartRobotCreator();

            //Act
            var result = robotCreator.CreateRobot(null);

            //Assert
            expected.Should().BeEquivalentTo(result);
        }
Ejemplo n.º 27
0
        public void should_select_the_locker_with_most_boxes_when_store_a_bag()
        {
            var locker1 = new Locker(2);
            var locker2 = new Locker(2);
            var lockers = new List <Locker> {
                locker1, locker2
            };

            var robot = new SmartRobot(lockers);

            robot.Store(new Bag());
            var ticket = robot.Store(new Bag());

            Assert.NotNull(locker2.Pick(ticket));
        }
Ejemplo n.º 28
0
        public void should_return_specific_bag_when_store_bag_to_robot_for_multiple_times()
        {
            var expectedBag1 = new Bag();
            var expectedBag2 = new Bag();

            var lockers = Enumerable.Range(0, 3).Select(i => new Locker(2)).ToList();
            var robot   = new SmartRobot(lockers);
            var ticket1 = robot.Store(expectedBag1);

            robot.Store(expectedBag2);

            var bag1 = robot.Pick(ticket1);

            Assert.Equal(expectedBag1, bag1);
        }
Ejemplo n.º 29
0
        public void shoud_store_bag_in_the_locker_which_has_lagest_capacity()
        {
            var lockers = new List <Locker>();
            var locker  = new Locker(2);

            locker.Store(new Bag());
            lockers.Add(locker);
            var secondLocker = new Locker(2);

            lockers.Add(secondLocker);

            var robot  = new SmartRobot(lockers);
            var bag    = new Bag();
            var ticket = robot.Store(bag);

            Assert.AreSame(bag, secondLocker.Pick(ticket));
        }
Ejemplo n.º 30
0
        public void should_pick_bag_given_existing_ticket()
        {
            var locker = new Locker(1);
            var lockers = new List<Locker> { locker };
            var smartRobot = new SmartRobot(new List<Locker> {new Locker(1)});
            var superRobot = new SuperRobot(new List<Locker> {new Locker(1)});

            var robots = new List<SmartRobot> {
                smartRobot,
                superRobot
            };
            var manager = new Manager(lockers, robots);
            var expectedBag = new Bag();
            var ticket = manager.Store(expectedBag);
            var actualBag = manager.Pick(ticket);

            Assert.Equal(expectedBag, actualBag);
        }
        public void should_store_bag_in_the_locker_which_has_largest_number_of_empty_boxes()
        {
            var bag1 = new Bag();
            var bag2 = new Bag();
            var bag3 = new Bag();
            var bag4 = new Bag();

            lockers[0].Store(bag1);
            lockers[1].Store(bag2);
            lockers[3].Store(bag3);
            var smartRobot = new SmartRobot(lockers);
            var ticket4    = smartRobot.Store(bag4);

            Assert.Null(lockers[0].Pick(ticket4));
            Assert.Null(lockers[1].Pick(ticket4));
            Assert.Null(lockers[3].Pick(ticket4));
            Assert.AreSame(bag4, lockers[2].Pick(ticket4));
        }
Ejemplo n.º 32
0
        public void should_store_failed_when_lockers_robot_managed_has_been_all_full()
        {
            var bag1 = new Bag();
            var bag2 = new Bag();
            var bag3 = new Bag();
            var bag4 = new Bag();
            var bag5 = new Bag();

            var lockers = Enumerable.Range(0, 2).Select(i => new Locker(2)).ToList();
            var robot   = new SmartRobot(lockers);

            robot.Store(bag1);
            robot.Store(bag2);
            robot.Store(bag3);
            robot.Store(bag4);
            var ticket = robot.Store(bag5);

            Assert.Null(ticket);
        }
Ejemplo n.º 33
0
        static void Main(string[] args)
        {
            var n         = int.Parse(Console.ReadLine());
            var originRaw = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList();
            var origin    = new Point(originRaw.First(), originRaw.Last());

            var robot = new SmartRobot(origin);

            for (var i = 0; i < n; i++)
            {
                var moveRaw   = Console.ReadLine().Split(' ').ToList();
                var direction = Enum.Parse <RobotMoveDirection>(moveRaw.First());
                var steps     = int.Parse(moveRaw.Last());

                robot.Move(new RobotMove(direction, steps));
            }

            Console.WriteLine($"=> Cleaned: {robot.CleanedSpaces}");
        }
        public void should_pick_bag_given_existing_ticket()
        {
            var lockers = new List <Locker> {
                new Locker(1)
            };
            var robot = new Robot(new List <Locker> {
                new Locker(1)
            });
            var smartRobot = new SmartRobot(new List <Locker> {
                new Locker(1)
            });
            var superRobot = new SuperRobot(new List <Locker> {
                new Locker(1)
            });
            var baseRobots = new List <BaseRobot> {
                robot, smartRobot, superRobot
            };
            var manager     = new Manager(lockers, baseRobots);
            var expectedBag = new Bag();
            var ticket      = manager.Store(expectedBag);
            var actualBag   = manager.Pick(ticket);

            Assert.Equal(expectedBag, actualBag);
        }
Ejemplo n.º 35
0
        public void should_store_bag_in_sequence_given_all_kinds_of_robots_and_lockers()
        {
            var locker = new Locker(1);
            var lockers = new List<Locker> { locker };
            var smartRobot = new SmartRobot(new List<Locker> {new Locker(1)});
            var superRobot = new SuperRobot(new List<Locker> {new Locker(1)});

            var robots = new List<SmartRobot> {
                smartRobot,
                superRobot
            };

            var manager = new Manager(lockers, robots);
            var bag1 = new Bag();
            var bag2 = new Bag();
            var bag3 = new Bag();
            var ticket1 = manager.Store(bag1);
            var ticket2 = manager.Store(bag2);
            var ticket3 = manager.Store(bag3);

            Assert.Equal(bag1, locker.Pick(ticket1));
            Assert.Equal(bag2, smartRobot.Pick(ticket2));
            Assert.Equal(bag3, superRobot.Pick(ticket3));
        }
Ejemplo n.º 36
0
        public void CrossTest()
        {
            var runs  = 100;
            var moves = 1000;


            for (var t = 0; t < runs; t++)
            {
                var randomizer = new Random();
                var origin     = new Point(randomizer.Next(-1000, 1000), randomizer.Next(-1000, 1000));
                var naiveRobot = new NaiveRobot(origin);
                var smartRobot = new SmartRobot(origin);

                for (var i = 0; i < moves; i++)
                {
                    var move = GetRandomMove(randomizer);

                    naiveRobot.Move(move);
                    smartRobot.Move(move);

                    Assert.Equal(naiveRobot.CleanedSpaces, smartRobot.CleanedSpaces);
                }
            }
        }