Ejemplo n.º 1
0
        public void BeforeEachTest()
        {
            _roverMock = new Mock <IRover>();
            _random    = new Random();

            _roverCommander = new RoverCommander();
        }
Ejemplo n.º 2
0
        public void SendCommand_WrongCommand_ExceptionThrown(char command)
        {
            IRover          mockedRover = Substitute.For <IRover>();
            IRoverCommander commander   = new RoverCommander(mockedRover);

            Assert.Throws <ArgumentException>(() => commander.SendCommand(command));
        }
        public void BeforeEachTest()
        {
            _roverMock = new Mock<IRover>();
            _random = new Random();

            _roverCommander = new RoverCommander();
        }
Ejemplo n.º 4
0
        public void SendCommand_M_Move()
        {
            IRover          mockedRover = Substitute.For <IRover>();
            IRoverCommander commander   = new RoverCommander(mockedRover);

            commander.SendCommand('M');

            mockedRover.Received(1).Move();
        }
Ejemplo n.º 5
0
        public void SendCommand_R_RotateRoverCW()
        {
            IRover          mockedRover = Substitute.For <IRover>();
            IRoverCommander commander   = new RoverCommander(mockedRover);

            commander.SendCommand('R');

            mockedRover.Received(1).RotateCW();
        }
Ejemplo n.º 6
0
        public void SendLongCommand_ExpectedCalls()
        {
            IRover          mockedRover = Substitute.For <IRover>();
            IRoverCommander commander   = new RoverCommander(mockedRover);

            commander.SendCommands("MRLLRRMMMLL");

            mockedRover.Received(4).Move();
            mockedRover.Received(3).RotateCW();
            mockedRover.Received(4).RotateCCW();
        }
Ejemplo n.º 7
0
        public void send_instructions()
        {
            var instructions = @"5 5
            1 2 N
            LMLMLMLMM
            3 3 E
            MMRMMRMRRM";
            var roverCommander = new RoverCommander();
            roverCommander.SendInstructions(instructions);

            var robots = roverCommander.GetRovers();

            Assert.AreEqual("1 3 N", robots[0].ToString());
            Assert.AreEqual("5 1 E", robots[1].ToString());
        }
Ejemplo n.º 8
0
        static void Main()
        {
            var plateauWidth  = ReadInteger("Enter plateau width: ");
            var plateauLength = ReadInteger("Enter plateau length: ");

            List <IRover> rovers = new List <IRover>();

            while (true)
            {
                var name = ReadString("Enter the name of the rover (type . to stop): ");

                if (name == ".")
                {
                    break;
                }

                ReadRoverStartPosition($"Enter the rover {name} start position x, y, direction: ", out var startX,
                                       out var startY, out var direction);

                var command = ReadString($"Enter the command to send to rover {name}: ");

                IPlateau plateau = new Plateau(plateauWidth, plateauLength);
                IRover   rover   = new Rover(name, plateau);
                rovers.Add(rover);

                rover.SetCurrentPosition(startX, startY, direction);

                IRoverCommander commander = new RoverCommander(rover);
                try
                {
                    commander.SendCommands(command);
                    Console.WriteLine($"Rover {name} succesfully moved.");
                }
                catch (Exception exception)
                {
                    Console.WriteLine($"Something went wrong: {exception.Message}");
                }
            }
            PrintRoverPositions(rovers);

            Console.WriteLine("Press a key to exit");
            Console.Read();
        }
Ejemplo n.º 9
0
        static void Main(string[] args)
        {
            string[] cmds = new string[]{
                            "5 5",
                            "1 2 N",
                            "LMLMLMLMM",
                            "3 3 E",
                            "MMRMMRMRRM"
                };

            MarsRover r = new MarsRover();
            string[] plXY = cmds[0].Split(' ');
            RoverCommander rc = new RoverCommander(r, int.Parse(plXY[0]), int.Parse(plXY[1]));

            for (int i = 1; i < cmds.Length;)
            {
                rc.SendCmd(cmds[i++], cmds[i++]);
                Console.WriteLine(rc.GetRoverPosition());
            }
        }
Ejemplo n.º 10
0
        public RoverCommandResponse PostCommand(Guid id, RoverCommandRequest request)
        {
            RoverCommandResponse response = new RoverCommandResponse();

            response.Rover = DataContext.Rovers.Where(p => p.Id == id).FirstOrDefault();
            if (response.Rover != null && response.Rover.State == RoverState.Active)
            {
                try
                {
                    RoverCommander commander = new RoverCommander(response.Rover.Id);
                    response.Rover            = commander.Execute(request.Commands);
                    response.FinalCoordinates = $"{response.Rover.Location.X}, {response.Rover.Location.Y}, {response.Rover.Direction.ToString().ElementAt(0)}";
                    return((RoverCommandResponse)response.ReturnWithSuccess());
                }

                catch (Exception ex) {
                    response.FinalCoordinates = $"{response.Rover.Location.X}, {response.Rover.Location.Y}, {response.Rover.Direction.ToString().ElementAt(0)}";
                    return((RoverCommandResponse)response.ReturnWithErrors(ex.Message));
                }
            }
            return(response);
        }