Exemplo n.º 1
0
        static void Main(string[] args)
        {
            // Read the count of the commands that will follow.
            int commandCount = int.Parse(Console.ReadLine());
            
            // Get the start position of the robot.
            Vector2 startPosition = Vector2.PositionFromString(Console.ReadLine());

            // Create the robot and the tracker.
            Robot robot = new Robot(startPosition);
            PositionTracker tracker = new PositionTracker(robot);

            // Loop until we have read all commands.
            for (int i = 0; i < commandCount; i++)
            {
                // Read the line and create a movement vector.
                var line = Console.ReadLine();
                Vector2 movement = Vector2.MoveDirectionFromString(line);

                // Move the robot.
                robot.Move(movement);
            }

            // Calculate and display the unique positions visited by the robot.
            Console.WriteLine($"=> Cleaned: {tracker.CalculatePositionsVisited()}");
        }
 public void TestPositionTrackerCreation()
 {
     Robot robot = new Robot(new Vector2(10, 10));
     PositionTracker tracker = new PositionTracker(robot);
     
     Assert.AreEqual(1, tracker.CalculatePositionsVisited());
 }
        public void TestRetraceSteps()
        {
            Robot robot = new Robot(new Vector2(-10, -10));
            PositionTracker tracker = new PositionTracker(robot);

            robot.Move(new Vector2(10, 0));
            robot.Move(new Vector2(-11, 0));

            Assert.AreEqual(12, tracker.CalculatePositionsVisited());
        }
        public void TestPositionTrackerCalculationNegativeStart()
        {
            Robot robot = new Robot(new Vector2(-10, -10));
            PositionTracker tracker = new PositionTracker(robot);

            robot.Move(new Vector2(2, 0));
            robot.Move(new Vector2(0, 2));
            robot.Move(new Vector2(-2, 0));
            robot.Move(new Vector2(0, -2));

            Assert.AreEqual(8, tracker.CalculatePositionsVisited());
        }