public void Discard_Right_command_when_the_robot_was_not_placed_on_the_table() { var toyRobot = new ToyRobot(); toyRobot.Right(); toyRobot.X.Should().Be(null); toyRobot.Y.Should().Be(null); toyRobot.Facing.Should().Be(null); }
public void Rotate_robot_right_90_degrees(string before, string after) { var toyRobot = new ToyRobot(); toyRobot.Place(1, 1, before); toyRobot.Right(); toyRobot.Facing.Should().Be(after); }
public void TestRightWhenCorrectlyPlaced() { // Create an instance to test: ToyRobot robot = new ToyRobot(); // Define a test input and output value: int x = 0; int y = 0; Facing facing = Facing.North; robot.Place(x, y, facing); // Run the method under test and verify result robot.Right(); Assert.AreEqual(robot.Facing, Facing.East); robot.Right(); Assert.AreEqual(robot.Facing, Facing.South); robot.Right(); Assert.AreEqual(robot.Facing, Facing.West); robot.Right(); Assert.AreEqual(robot.Facing, Facing.North); }
public void Right_FromNorth_ToEast() { //Arrange var currentPosition = new Position(0, 0); var facingManagerMock = new Mock <ICardinalDirectionManager>(); facingManagerMock.Setup(facingManager => facingManager.TurnRight()).Returns(new EastManager()); var toyRobotManager = new ToyRobot(currentPosition, facingManagerMock.Object, new ReportManager()); //Act CardinalDirection finalFacing = toyRobotManager.Right(); //Assert Assert.AreEqual(CardinalDirection.EAST, finalFacing); }
public void TestRightNoValidPlaceCommandExecutedException() { // Create an instance to test: ToyRobot robot = new ToyRobot(); // Run the method under test: try { robot.Right(); Assert.Fail("A valid Place command needs to be executed first"); } catch (Exception ex) { Assert.AreEqual(typeof(NoValidPlaceCommandExecutedException), ex.GetType(), ex.Message); } }
private void Window_KeyReleased(object sender, KeyEventArgs e) { if (e.Code == Keyboard.Key.Right) { toyRobot.Right(); } if (e.Code == Keyboard.Key.Left) { toyRobot.Left(); } if (e.Code == Keyboard.Key.Up) { toyRobot.Move(); } }
public void XmlTestCases() { // read data from row in data.xml string description = (string)TestContext.DataRow["Description"]; string expectedOutput = (string)TestContext.DataRow["Expected"]; string allCommands = (string)TestContext.DataRow["Commands"]; // interpret user input - this avoids duplicating the XML // test data in a more explicit form foreach (string cmd in allCommands.Split(LineEnds, StringSplitOptions.RemoveEmptyEntries)) { if (!String.IsNullOrWhiteSpace(cmd)) { string normalisedCmd = cmd.Trim().ToUpperInvariant(); if (normalisedCmd.StartsWith("PLACE")) { string args = normalisedCmd.Substring(5).Trim(); string[] tokens = args.Split(CommaOrSpace, StringSplitOptions.RemoveEmptyEntries); if (tokens != null && tokens.Length == 3) { if (Int32.TryParse(tokens[0], out int x) && Int32.TryParse(tokens[1], out int y) && Enum.TryParse <Direction>(tokens[2].ToUpperInvariant(), out Direction facing)) { robot.Place(x, y, facing, tableTop); } } } else if (normalisedCmd.StartsWith("LEFT")) { robot.Left(); } else if (normalisedCmd.StartsWith("RIGHT")) { robot.Right(); } else if (normalisedCmd.StartsWith("MOVE")) { robot.Move(); } } } // check output Assert.AreEqual(expectedOutput, robot.Report(), description); }