예제 #1
0
        public void ExecuteBatchCommandFailTest(int plateauUpperRightX, int plateauUpperRightY, int roverX, int roverY, char roverD, string command, int expectedRoverX, int expectedRoverY, int expectedRoverD)
        {
            bool isFail = false;

            try {
                Plateau plateau = new Plateau(new Coordinate(plateauUpperRightX, plateauUpperRightY));
                Assert.IsNotNull(plateau);
                Assert.IsNotNull(plateau.Rovers);
                Coordinate coordinate = new Coordinate(roverX, roverY);
                Direction  direction  = DirectionCreator.Create(roverD);
                plateau = plateauOperations.AddNewRover(plateau, coordinate, direction);
                Assert.IsNotNull(plateau);
                Assert.IsNotNull(plateau.SelectedRover);
                Assert.IsNotNull(plateau.SelectedRover.CurrentCoordinate);
                Assert.IsTrue(plateau.SelectedRover.CurrentCoordinate.X >= plateau.MinX && plateau.SelectedRover.CurrentCoordinate.X <= plateau.MaxX);
                Assert.IsTrue(plateau.SelectedRover.CurrentCoordinate.Y >= plateau.MinY && plateau.SelectedRover.CurrentCoordinate.Y <= plateau.MaxY);
                Assert.AreSame(plateau.SelectedRover.CurrentCoordinate, coordinate);
                plateau = roverOperations.ExecuteBatchCommand(plateau.SelectedRover, command);
                Assert.AreEqual(plateau.SelectedRover.CurrentCoordinate.X, expectedRoverX);
                Assert.AreEqual(plateau.SelectedRover.CurrentCoordinate.Y, expectedRoverY);
                Assert.AreEqual(plateau.SelectedRover.Direction, expectedRoverD);
            }
            catch { isFail = true; }
            Assert.IsTrue(isFail);
        }
예제 #2
0
        public ServiceResult <Plateau> AddNewRover(Plateau plateau, int roverX, int roverY, char direction)
        {
            ServiceResult <Plateau> result = new ServiceResult <Plateau>();

            try {
                Coordinate startCoordinate = new Coordinate(roverX, roverY);
                Direction  startDirection  = DirectionCreator.Create(direction);
                if (startDirection == null)
                {
                    result.ErrorMessage = $"Start direction parameter is invalid. Param value:{direction}";
                    result.ResultStatus = ServiceResultStatus.NotValid;
                    logger.ErrorLog(new ServiceException(result.ErrorMessage), result.ErrorMessage);
                }
                else
                {
                    plateau         = plateauOperations.AddNewRover(plateau, startCoordinate, startDirection);
                    result.Response = plateau;
                }
            }
            catch (Exception ex) {
                result.ResultStatus = ServiceResultStatus.Failed;
                result.ErrorMessage = $"AddNewRover function error: Please check your input. x:{roverX}, y:{roverY}, d:{direction}";
                logger.ErrorLog(ex, result.ErrorMessage);
            }
            return(result);
        }
예제 #3
0
        static void Main(string[] args)
        {
            DirectionCreator creator = PrepareDirections();

            foreach (Options option in creator.GetRegisteredDirections())
            {
                Console.WriteLine(creator.Create(option).MoveName);
            }
        }
예제 #4
0
        static DirectionCreator PrepareDirections()
        {
            DirectionCreator dCreator = new DirectionCreator();

            dCreator.RegisterDefaultDirections();

            // Register another direction here
            dCreator.RegisterDirection <MoveCombo>(Options.COMBO);

            return(dCreator);
        }
예제 #5
0
        public void AddNewRoverFailTest(int roverX, int roverY, char roverD)
        {
            Plateau plateau = new Plateau(new Coordinate(50, 50));

            Assert.IsNotNull(plateau);
            Assert.IsNotNull(plateau.Rovers);
            Coordinate coordinate = new Coordinate(roverX, roverY);
            bool       isFail     = false;

            try {
                Direction direction = DirectionCreator.Create(roverD);
                plateau = plateauOperations.AddNewRover(plateau, coordinate, direction);
            }
            catch { isFail = true; }
            Assert.IsTrue(isFail);
        }
예제 #6
0
        public void AddNewRoverSuccessTest(int roverX, int roverY, char roverD)
        {
            Plateau plateau = new Plateau(new Coordinate(50, 50));

            Assert.IsNotNull(plateau);
            Assert.IsNotNull(plateau.Rovers);
            Coordinate coordinate = new Coordinate(roverX, roverY);
            Direction  direction  = DirectionCreator.Create(roverD);

            plateau = plateauOperations.AddNewRover(plateau, coordinate, direction);
            Assert.IsNotNull(plateau);
            Assert.IsNotNull(plateau.SelectedRover);
            Assert.IsNotNull(plateau.SelectedRover.CurrentCoordinate);
            Assert.IsTrue(plateau.SelectedRover.CurrentCoordinate.X >= plateau.MinX && plateau.SelectedRover.CurrentCoordinate.X <= plateau.MaxX);
            Assert.IsTrue(plateau.SelectedRover.CurrentCoordinate.Y >= plateau.MinY && plateau.SelectedRover.CurrentCoordinate.Y <= plateau.MaxY);
            Assert.AreSame(plateau.SelectedRover.CurrentCoordinate, coordinate);
        }