Beispiel #1
0
        static void Main(string[] args)
        {
            //Get run parameters from Console
            var numberOfCommands = Convert.ToInt32(Console.ReadLine());
            var startingPostion  = Console.ReadLine();
            var startingX        = Convert.ToInt32(startingPostion.Split(' ')[0]);
            var startingY        = Convert.ToInt32(startingPostion.Split(' ')[1]);
            var directions       = new List <KeyValuePair <char, int> >();


            for (var i = 0; i < numberOfCommands; i++)
            {
                var direction_string = Console.ReadLine();
                var direction        = Convert.ToChar(direction_string.Split(' ')[0]);
                var steps            = Convert.ToInt32(direction_string.Split(' ')[1]);
                directions.Add(new KeyValuePair <char, int>(direction, steps));
            }

            //Call Processor method
            var cleanResult = RobotProcessor.Clean(startingX, startingY, directions);

            //Write Result
            Console.WriteLine($"=> Cleaned: {cleanResult}");
            Console.ReadKey();
        }
        public void Clean_When1Direction_ReturnsPlus1(
            [Values(1, 2, 3, 4, 5)] int steps)
        {
            var directions = new List <KeyValuePair <char, int> >();

            directions.Add(new KeyValuePair <char, int>('E', steps));

            int output = RobotProcessor.Clean(10, 22, directions);

            Assert.AreEqual(steps + 1, output);
        }
        public void Clean_When4Directions_SkipsCommonPlaces()
        {
            var directions = new List <KeyValuePair <char, int> >();

            directions.Add(new KeyValuePair <char, int>('E', 4));
            directions.Add(new KeyValuePair <char, int>('N', 4));
            directions.Add(new KeyValuePair <char, int>('W', 4));
            directions.Add(new KeyValuePair <char, int>('S', 4));

            int output = RobotProcessor.Clean(10, 22, directions);

            Assert.AreEqual(16, output);
        }
        public void Clean_When2OppositeDirections_SkipsCommonPlaces(
            [Values(1, 2, 3, 4)] int stepsDir1,
            [Values(2, 2, 3)] int stepsDir2)
        {
            var directions = new List <KeyValuePair <char, int> >();

            directions.Add(new KeyValuePair <char, int>('E', stepsDir1));
            directions.Add(new KeyValuePair <char, int>('W', stepsDir2));

            int output = RobotProcessor.Clean(10, 22, directions);

            Assert.AreEqual(Math.Max(stepsDir1, stepsDir2) + 1, output);
        }
        public void Clean_When2DifferentDirections_ReturnsSumPlus1(
            [Values(2)] int stepsDir1,
            [Values(2)] int stepsDir2)
        {
            var directions = new List <KeyValuePair <char, int> >();

            directions.Add(new KeyValuePair <char, int>('E', stepsDir1));
            directions.Add(new KeyValuePair <char, int>('N', stepsDir2));

            int output = RobotProcessor.Clean(10, 22, directions);

            Assert.AreEqual(stepsDir1 + stepsDir2 + 1, output);
        }
        public void CheckAlreadyExists_WhenNotExists_AddsPosition()
        {
            List <KeyValuePair <int, int> > currentUniquePositions = new List <KeyValuePair <int, int> >();

            currentUniquePositions.Add(new KeyValuePair <int, int>(10, 22));
            currentUniquePositions.Add(new KeyValuePair <int, int>(11, 22));
            currentUniquePositions.Add(new KeyValuePair <int, int>(12, 22));
            currentUniquePositions.Add(new KeyValuePair <int, int>(13, 22));

            var output = RobotProcessor.CheckUniqueAndAddPosition(10, 222, currentUniquePositions);

            Assert.AreEqual(5, output.Count);
        }