/// <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; } }
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); }
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); }
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); }
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); }
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); }
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()); }
public void MoveUp(DirectionPointer directionPointer) { this.y += (directionPointer.ValueOfPointer * -1); }
public void MoveRight(DirectionPointer directionPointer) { this.x += directionPointer.ValueOfPointer; }
public void MoveLeft(DirectionPointer directionPointer) { this.x += (directionPointer.ValueOfPointer * -1); }
public void MoveDown(DirectionPointer directionPointer) { this.y += directionPointer.ValueOfPointer; }
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()); }
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); }