Exemplo n.º 1
0
        static void Main(string[] args)
        {
            Assembler.Errors.SetResource(Properties.Resources.errors);

            bool debug = false;
            string filename = "";
            if (args.Length == 1)
            {
                filename = args[0];
            }
            else if (args.Length == 2 && args[0] == "-d")
            {
                debug = true;
                filename = args[1];
            }
            else
            {
                Usage();
                System.Environment.Exit(1);
            }

            var parser = new Parser();
            bool success = parser.ParseFile(filename);

            if (success)
            {
                Runtime.Debug = debug;
                Runtime.GetInstance().Run();
            }
        }
Exemplo n.º 2
0
        public void TestValidPlaceCommandDirection(string data)
        {
            var o       = new Simulator.Parser(Substitute.For <IRobot>());
            var command = "PLACE 1,1," + data;

            o.Parse(command);

            Assert.AreEqual(data, o.DResult.ToString());
        }
Exemplo n.º 3
0
        public void TestPlaceCommandWithInvalidFacing()
        {
            var o        = new Simulator.Parser(Substitute.For <IRobot>());
            var command  = "PLACE 0,0,INVALID";
            var expected = Simulator.CommandType.NOP;

            var actual = o.Parse(command);

            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 4
0
        public void TestPlaceCommandWithWrongOrderParameters()
        {
            var o        = new Simulator.Parser(Substitute.For <IRobot>());
            var command  = "PLACE 0,NORTH,0";
            var expected = Simulator.CommandType.NOP;

            var actual = o.Parse(command);

            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 5
0
        public void TestInvalidCommand()
        {
            var o        = new Simulator.Parser(Substitute.For <IRobot>());
            var command  = "INVALID";
            var expected = Simulator.CommandType.NOP;

            var actual = o.Parse(command);

            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 6
0
        public void TestReportCommandBeforePlaceCommand()
        {
            var o        = new Simulator.Parser(Substitute.For <IRobot>());
            var command  = "REPORT";
            var expected = Simulator.CommandType.NOP;

            var actual = o.Parse(command);

            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 7
0
        public void TestEmptyParse()
        {
            var o        = new Simulator.Parser(Substitute.For <IRobot>());
            var command  = string.Empty;
            var expected = Simulator.CommandType.NOP;

            var actual = o.Parse(command);

            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 8
0
        public void TestPlaceCommandCorrectCoordinates(int x, int y)
        {
            var o       = new Simulator.Parser(Substitute.For <IRobot>());
            var command = string.Format("PLACE {0},{1},NORTH", x, y);

            o.Parse(command);

            Assert.AreEqual(x, o.XResult);
            Assert.AreEqual(y, o.YResult);
        }
Exemplo n.º 9
0
        public void TestValidPlaceCommand(string data)
        {
            var o        = new Simulator.Parser(Substitute.For <IRobot>());
            var command  = "PLACE " + data;
            var expected = Simulator.CommandType.PLACE;

            var actual = o.Parse(command);

            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 10
0
        public void TestPlaceCommandWithIncorrectCoordinates(int x, int y)
        {
            var o        = new Simulator.Parser(Substitute.For <IRobot>());
            var command  = string.Format("PLACE {0},{1},NORTH", x, y);
            var expected = Simulator.CommandType.NOP;

            var actual = o.Parse(command);

            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 11
0
        public void TestReportCommandOnPlacedRobot()
        {
            var robot = Substitute.For <IRobot>();

            robot.X.Returns(2);
            robot.Y.Returns(2);
            robot.FacingDirection.Returns(Direction.EAST);
            var o        = new Simulator.Parser(robot);
            var command  = "Report";
            var expected = Simulator.CommandType.REPORT;

            var actual = o.Parse(command);

            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 12
0
        public void TestMoveCommandToMakeRobotFall(int x, int y, Direction d)
        {
            var robot = Substitute.For <IRobot>();

            robot.X.Returns(x);
            robot.Y.Returns(y);
            robot.FacingDirection.Returns(d);
            var o        = new Simulator.Parser(robot);
            var command  = "MOVE";
            var expected = Simulator.CommandType.NOP;

            var actual = o.Parse(command);

            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 13
0
        public void TestCreate()
        {
            var o = new Simulator.Parser(Substitute.For <IRobot>());

            Assert.IsNotNull(o);
        }