Exemplo n.º 1
0
        static void Main(string[] args)
        {
            RobotCleaner robot = new RobotCleaner();

            robot.NumberOfCommands = Convert.ToInt32(Console.ReadLine());

            string[] coordinate = Console.ReadLine().Split(' ');
            robot.StartingCoordinates = new Coordinate(Convert.ToInt32(coordinate[0]), Convert.ToInt32(coordinate[1]));


            if (robot.NumberOfCommands > 0)
            {
                for (int i = 1; i <= robot.NumberOfCommands; i++)
                {
                    string[] vector = Console.ReadLine().Split(' ');
                    robot.AddVector(new Vector(Convert.ToChar(vector[0]), Convert.ToInt32(vector[1])));
                }
            }

            robot.StartSession();


            Console.WriteLine("=> Cleaned: " + robot.GetNumberOfCleanedPlaces());

            Console.ReadKey();
        }
        public void NumberOfCommands()
        {
            RobotCleaner crc = new RobotCleaner();

            crc.NumberOfCommands = 2;

            Assert.AreEqual(crc.NumberOfCommands, 2);
        }
        public void AddVectors()
        {
            RobotCleaner crc = new RobotCleaner();

            crc.AddVector(new Vector('E', 5));
            crc.AddVector(new Vector('S', 3));

            Assert.AreEqual(crc.GetNumberOfVectors(), 2);
        }
        public void GetNumberOfCleanedPlaces()
        {
            RobotCleaner crc = new RobotCleaner();

            crc.NumberOfCommands    = 0;
            crc.StartingCoordinates = new Coordinate(5, 4);
            crc.StartSession();

            Assert.AreEqual(crc.GetNumberOfCleanedPlaces(), 1);
        }
        public void StartingCoordinates()
        {
            RobotCleaner crc = new RobotCleaner();
            Coordinate   cc  = new Coordinate(2, 3);

            crc.StartingCoordinates = cc;

            Assert.AreEqual(cc.X, 2);
            Assert.AreEqual(cc.Y, 3);
        }
Exemplo n.º 6
0
        public void CleanWestTest()
        {
            var startLocation = new Location(22, 10);
            var command = new RobotCommand(Direction.West, 23);
            var robot = new RobotCleaner(startLocation);
            robot.ExecuteCommand(command);

            var expectedLastLocation = new Location(-1, 10);
            Assert.AreEqual(expectedLastLocation, robot.LastLocation);
        }
        public void GetCurrentCoordinate()
        {
            RobotCleaner crc = new RobotCleaner();

            crc.NumberOfCommands    = 0;
            crc.StartingCoordinates = new Coordinate(5, 4);
            crc.StartSession();

            Assert.AreEqual(crc.GetCurrentCoordinate().X, 5);
            Assert.AreEqual(crc.GetCurrentCoordinate().Y, 4);
        }
        public void GetCurrentCoordinate_WithOneCommand()
        {
            RobotCleaner crc = new RobotCleaner();

            crc.NumberOfCommands    = 1;
            crc.StartingCoordinates = new Coordinate(0, 0);
            crc.AddVector(new Vector('E', 1));
            crc.StartSession();

            Assert.AreEqual(crc.GetCurrentCoordinate().X, 1);
            Assert.AreEqual(crc.GetCurrentCoordinate().Y, 0);
        }
        public void GetNumberOfCleanedPlaces_withTwoCommandsOverlap()
        {
            RobotCleaner crc = new RobotCleaner();

            crc.NumberOfCommands    = 2;
            crc.StartingCoordinates = new Coordinate(5, 4);
            crc.AddVector(new Vector('E', 5));
            crc.AddVector(new Vector('W', 6));
            crc.StartSession();

            Assert.AreEqual(crc.GetNumberOfCleanedPlaces(), 7);
        }
Exemplo n.º 10
0
        public void GetCleanedLocationsTest()
        {
            var startLocation = new Location(22, 10);
            var commands = new List<RobotCommand>
            {
                new RobotCommand(Direction.East, 2),
                new RobotCommand(Direction.North, 1)
            };
            var robot = new RobotCleaner(startLocation);
            robot.ExecuteCommands(commands);

            const int expectedCleanedLocations = 4;
            Assert.AreEqual(expectedCleanedLocations, robot.GetCleanedLocations());
        }
Exemplo n.º 11
0
        public async Task UseValidCoordinates_CalculatesUniqueSteps_Success()
        {
            var sut = new RobotCleaner(new GridNavigator());

            var originPoint = new Point2D(0, 0);
            var fullAtomicOperationsList = new List <NavigationDirections>()
            {
                NavigationDirections.East, NavigationDirections.East, NavigationDirections.North
            };

            var uniqueSteps = await sut.StartWithInput(new CleaningInputCommand(originPoint, fullAtomicOperationsList));

            Assert.IsTrue(uniqueSteps == 4);
        }
Exemplo n.º 12
0
        public void CleanRoomTests(params object[] input)
        {
            int            numOfCommands   = (int)input[0];
            Coordinates    initialPosition = new Coordinates((int)input[1], (int)input[2]);
            List <Command> commands        = new List <Command>();

            for (int i = 0; i < numOfCommands; i++)
            {
                commands.Add(new Command((string)input[i * 2 + 3], (int)input[i * 2 + 3 + 1]));
            }

            var robot       = new RobotCleaner();
            int numOfPlaces = robot.CleanRoom(numOfCommands, initialPosition, commands);

            Assert.Equal(input[input.Length - 1], numOfPlaces);
        }
        public void GetOneVector()
        {
            RobotCleaner crc = new RobotCleaner();

            crc.AddVector(new Vector('E', 5));
            crc.AddVector(new Vector('S', 3));
            crc.AddVector(new Vector('W', 2));

            Assert.AreEqual(crc.GetOneVector(0).Directon, 'E');
            Assert.AreEqual(crc.GetOneVector(0).Steps, 5);

            Assert.AreEqual(crc.GetOneVector(1).Directon, 'S');
            Assert.AreEqual(crc.GetOneVector(1).Steps, 3);

            Assert.AreEqual(crc.GetOneVector(2).Directon, 'W');
            Assert.AreEqual(crc.GetOneVector(2).Steps, 2);
        }
Exemplo n.º 14
0
        public async Task Robot_RunsInCircles_FewUniquePoints()
        {
            var sut = new RobotCleaner(new GridNavigator());

            var originPoint = new Point2D(10, 22);
            var fullAtomicOperationsList = new List <NavigationDirections>
            {
                NavigationDirections.East,
                NavigationDirections.East,
                NavigationDirections.North,
                NavigationDirections.North,
                NavigationDirections.West,
                NavigationDirections.West,
                NavigationDirections.South,
                NavigationDirections.South,
                NavigationDirections.East,
                NavigationDirections.East,
                NavigationDirections.North,
                NavigationDirections.North,
                NavigationDirections.West,
                NavigationDirections.West,
                NavigationDirections.South,
                NavigationDirections.South,
                NavigationDirections.East,
                NavigationDirections.East,
                NavigationDirections.North,
                NavigationDirections.North,
                NavigationDirections.West,
                NavigationDirections.West,
                NavigationDirections.South,
                NavigationDirections.South,
                NavigationDirections.East,
                NavigationDirections.East,
                NavigationDirections.North,
                NavigationDirections.North,
                NavigationDirections.West,
                NavigationDirections.West,
                NavigationDirections.South,
                NavigationDirections.South
            };

            var uniqueSteps = await sut.StartWithInput(new CleaningInputCommand(originPoint, fullAtomicOperationsList));

            Assert.IsTrue(uniqueSteps == 8);
        }
Exemplo n.º 15
0
        public async Task UseInvalidCoordinates_RobotNeverGoesOutside_Stops_RightAway()
        {
            var sut = new RobotCleaner(new GridNavigator());

            var originPoint = new Point2D(-100000, 22);
            var fullAtomicOperationsList = new List <NavigationDirections>
            {
                NavigationDirections.East,
                NavigationDirections.East,
                NavigationDirections.North,
                NavigationDirections.West,
                NavigationDirections.West,
                NavigationDirections.West,
                NavigationDirections.North
            };

            var uniqueSteps = await sut.StartWithInput(new CleaningInputCommand(originPoint, fullAtomicOperationsList));

            Assert.IsTrue(uniqueSteps == 6);
            Assert.IsTrue(uniqueSteps <= fullAtomicOperationsList.Count);
        }
Exemplo n.º 16
0
        static void Main(string[] args)
        {
            var totalNumberOfCommands = InputResolver.ResolveNumberOfCommands(System.Console.ReadLine());
            var startLocation         = InputResolver.ResolveLocation(System.Console.ReadLine());

            var commands = new List <ICommand>();

            while (totalNumberOfCommands != 0)
            {
                var command = InputResolver.ResolveCommand(System.Console.ReadLine());
                commands.Add(command);
                totalNumberOfCommands--;
            }

            var robotCleaner = new RobotCleaner(startLocation, commands);

            robotCleaner.Start();

            System.Console.WriteLine(robotCleaner.DisplayResults());

            System.Console.ReadKey();
        }