示例#1
0
        public void TestRobotSetPositionValid()
        {
            Robot robot = new Robot(5);

            robot.SetPosition(3, 4);
            robot.SetPosition(1, 2);

            Assert.AreEqual(1, robot.xPos);
            Assert.AreEqual(2, robot.yPos);
        }
示例#2
0
        public void TestRobotSetPositionInvalidY()
        {
            Robot robot = new Robot(5);

            robot.SetPosition(3, 2);    // Valid
            robot.SetPosition(1, 16);   // Invalid

            // Position not changed by invalid
            Assert.AreEqual(3, robot.xPos);
            Assert.AreEqual(2, robot.yPos);
        }
示例#3
0
        public void TestRobotSetPositionValidUpper()
        {
            Robot robot = new Robot(4);

            robot.SetPosition(4, 4);

            Assert.AreEqual(4, robot.xPos);
            Assert.AreEqual(4, robot.yPos);
        }
示例#4
0
        public void TestRobotSetPositionValidLower()
        {
            Robot robot = new Robot(5);

            robot.SetPosition(0, 0);

            Assert.AreEqual(0, robot.xPos);
            Assert.AreEqual(0, robot.yPos);
        }
示例#5
0
        public void TestCommandMoveCanExecuteInvalidBearing()
        {
            Robot robot = new Robot(2);

            robot.SetPosition(1, 2);

            var command = new MoveCommand();

            Assert.IsFalse(command.CanExecute(robot));
        }
示例#6
0
        public void TestRobotSetPositionInvalidX()
        {
            Robot robot = new Robot(5);

            robot.SetPosition(-3, 2);

            // Position not changed by invalid
            Assert.IsNull(robot.xPos);
            Assert.IsNull(robot.yPos);
        }
示例#7
0
        public void TestCommandMoveCanExecuteValid()
        {
            Robot robot = new Robot(2);

            robot.SetPosition(1, 1);
            robot.SetBearing("NORTH");

            var command = new MoveCommand();

            Assert.IsTrue(command.CanExecute(robot));
        }
示例#8
0
        public void TestRobotMoveForwardNoBearing()
        {
            Robot robot = new Robot(5);

            robot.SetPosition(1, 2);

            robot.MoveForward();

            Assert.AreEqual(1, robot.xPos);
            Assert.AreEqual(2, robot.yPos);
            Assert.IsNull(robot.bearing);
        }
示例#9
0
        public void TestRobotMoveForwardLowerY()
        {
            Robot robot = new Robot(3);

            robot.SetPosition(0, 0);
            robot.SetBearing("SOUTH");

            robot.MoveForward();

            Assert.AreEqual(0, robot.xPos);
            Assert.AreEqual(0, robot.yPos);
            Assert.AreEqual("SOUTH", robot.bearing);
        }
示例#10
0
        public void TestRobotMoveForwardUpperY()
        {
            Robot robot = new Robot(3);

            robot.SetPosition(3, 3);
            robot.SetBearing("NORTH");

            robot.MoveForward();

            Assert.AreEqual(3, robot.xPos);
            Assert.AreEqual(3, robot.yPos);
            Assert.AreEqual("NORTH", robot.bearing);
        }
示例#11
0
        public void TestRobotMoveForwardValid()
        {
            Robot robot = new Robot(5);

            robot.SetPosition(1, 2);
            robot.SetBearing("NORTH");

            robot.MoveForward();

            Assert.AreEqual(1, robot.xPos);
            Assert.AreEqual(3, robot.yPos);
            Assert.AreEqual("NORTH", robot.bearing);
        }
示例#12
0
        public void TestCommandMoveExecuteValid()
        {
            Robot robot = new Robot(2);

            robot.SetPosition(1, 1);
            robot.SetBearing("NORTH");

            var command = new MoveCommand();

            command.Execute(robot, "");

            Assert.AreEqual(1, robot.xPos);
            Assert.AreEqual(2, robot.yPos);
            Assert.AreEqual("NORTH", robot.bearing);
        }
示例#13
0
        public void TestCommandTurnExecuteAntiClockwise()
        {
            Robot robot = new Robot(2);

            robot.SetPosition(1, 1);
            robot.SetBearing("NORTH");

            var command = new TurnCommand(false);

            command.Execute(robot, "");

            Assert.AreEqual(1, robot.xPos);
            Assert.AreEqual(1, robot.yPos);
            Assert.AreEqual("WEST", robot.bearing);
        }
示例#14
0
        public void TestCommandReportExecuteValidRobot()
        {
            Robot robot = new Robot(2);

            robot.SetPosition(1, 2);
            robot.SetBearing("SOUTH");

            StringBuilder sb      = new StringBuilder();
            StringWriter  writer  = new StringWriter(sb);
            var           command = new ReportCommand(writer);

            command.Execute(robot, "");

            Assert.AreEqual("1,2,SOUTH\r\n", sb.ToString());
        }