コード例 #1
0
 /// <summary>
 /// Calls the respective methods depending on the direction
 /// </summary>
 /// <param name="direction">Char current direction symbol</param>
 /// <param name="point">Current point object to be moved</param>
 /// <param name="pointer">Direction pointer position modifier</param>
 public static void HandleDirection(char direction, Point point, DirectionPointer pointer)
 {
     switch (direction)
     {
         case '>': point.MoveRight(pointer); break;
         case '<': point.MoveLeft(pointer); break;
         case '^': point.MoveUp(pointer); break;
         case 'v': point.MoveDown(pointer); break;
         case '~': pointer.ReverseDirectionPointer(); break;
     }
 }
コード例 #2
0
        public void CheckIfPointMoveCorrectlyDownWithDirectionPointerOfOne()
        {
            string directions = "v";
            Point point = new Point(0, 0);
            DirectionPointer pointer = new DirectionPointer(1);

            foreach (var direction in directions)
            {
                DirectionParser.HandleDirection(direction, point, pointer);
            }

            Assert.AreEqual(new Point(0, 1), point);
        }
コード例 #3
0
        public void CheckIfDirectionPointerReverseWithValueGreaterThanZero()
        {
            string directions = "~";
            Point point = new Point(0, 0);
            DirectionPointer pointer = new DirectionPointer(1);

            foreach (var direction in directions)
            {
                DirectionParser.HandleDirection(direction, point, pointer);
            }

            Assert.AreEqual(-1, pointer.ValueOfPointer);
        }
コード例 #4
0
        public void CheckIfPointCoordinatesDontChangeAfterEmptyPathInput()
        {
            string directions = "  ";
            Point point = new Point(0, 0);
            DirectionPointer pointer = new DirectionPointer(1);

            foreach (var direction in directions)
            {
                DirectionParser.HandleDirection(direction, point, pointer);
            }

            Assert.AreEqual(new Point(0, 0), point);
        }
コード例 #5
0
        public void CheckIfDirectionPointerDoentChangeIfHasZeroValue()
        {
            string directions = "~~~";
            Point point = new Point(0, 0);
            DirectionPointer pointer = new DirectionPointer(0);

            foreach (var direction in directions)
            {
                DirectionParser.HandleDirection(direction, point, pointer);
            }

            Assert.AreEqual(0, pointer.ValueOfPointer);
        }
コード例 #6
0
        public void CheckIfDirectionPointerSetsCorrectValue()
        {
            string directions = " ";
            Point point = new Point(0, 0);
            DirectionPointer pointer = new DirectionPointer(1);
            pointer.ValueOfPointer = 2;

            foreach (var direction in directions)
            {
                DirectionParser.HandleDirection(direction, point, pointer);
            }

            Assert.AreEqual(2, pointer.ValueOfPointer);
        }
コード例 #7
0
        public static void Main(string[] args)
        {
            ///can input directions from the console
            //string directions = Console.ReadLine();
            string directions = ">>><<<~>>>~^^^";
            Point point = new Point(0, 0);
            DirectionPointer pointer = new DirectionPointer(1);

            foreach (var direction in directions)
            {
                DirectionParser.HandleDirection(direction, point, pointer);
            }

            Console.WriteLine(point.ToString());
        }
コード例 #8
0
 public void MoveUp(DirectionPointer directionPointer)
 {
     this.y += (directionPointer.ValueOfPointer * -1);
 }
コード例 #9
0
 public void MoveRight(DirectionPointer directionPointer)
 {
     this.x += directionPointer.ValueOfPointer;
 }
コード例 #10
0
 public void MoveLeft(DirectionPointer directionPointer)
 {
     this.x += (directionPointer.ValueOfPointer * -1);
 }
コード例 #11
0
 public void MoveDown(DirectionPointer directionPointer)
 {
     this.y += directionPointer.ValueOfPointer;
 }
コード例 #12
0
        public void CheckIfPointToStringProducesCorrectMessage()
        {
            string directions = " ";
            Point point = new Point(0, 0);
            DirectionPointer pointer = new DirectionPointer(1);

            foreach (var direction in directions)
            {
                DirectionParser.HandleDirection(direction, point, pointer);
            }

            Assert.AreEqual("X = 0; Y = 0;", point.ToString());
        }
コード例 #13
0
        public void CheckIfPointSetsCorrectYValueWhenEdited()
        {
            string directions = " ";
            Point point = new Point(0, 0);
            point.Y = 1;
            DirectionPointer pointer = new DirectionPointer(1);

            foreach (var direction in directions)
            {
                DirectionParser.HandleDirection(direction, point, pointer);
            }

            Assert.AreEqual(1, point.Y);
        }