Example #1
0
        public void GivenARobotMove_IfThereIsNOScent_RobotIsLost()
        {
            IEnumerable <Position> scents = null;
            var currentPostion            = new Position {
                PositionX = 2, PositionY = 3, Orientation = Orientation.N
            };
            List <IMoveCommand> movements = MoveCommand_Extensions.ForwardCommands();

            var _sut = new RobotMoveService(movements, scents, _marsGrid);

            var result = _sut.GetFinalPosition(currentPostion);

            Assert.True(result.IsLost &&
                        result.Position.PositionX == 2 &&
                        result.Position.PositionY == 3 &&
                        result.Position.Orientation == Orientation.N);
        }
Example #2
0
        public void GivenACoordinate_WhenMoving_ShowNewOrientation()
        {
            IEnumerable <Position> scents = null;
            var expectedPosition          = new Position {
                Orientation = Orientation.N, PositionX = 3, PositionY = 3
            };
            var position = new Position {
                Orientation = Orientation.N, PositionX = 3, PositionY = 2
            };

            List <IMoveCommand> movements = MoveCommand_Extensions.ExampleCommandsRobotTwo();

            var _sut = new RobotMoveService(movements, scents, _marsGrid);

            var finalPosition = _sut.GetFinalPosition(position);

            Assert.Equal(expectedPosition.Orientation, finalPosition.Position.Orientation);
            Assert.Equal(expectedPosition.PositionX, finalPosition.Position.PositionX);
            Assert.Equal(expectedPosition.PositionY, finalPosition.Position.PositionY);
        }
Example #3
0
        public void GivenARobotMove_IfIsInScentPositionPreventItToFall()
        {
            var scents = new List <Position> {
                new Position {
                    PositionX = 2, PositionY = 3
                }
            };
            var currentPostion = new Position {
                PositionX = 2, PositionY = 2, Orientation = Orientation.N
            };
            List <IMoveCommand> movements = MoveCommand_Extensions.ForwardCommands();

            var _sut = new RobotMoveService(movements, scents, _marsGrid);

            var result = _sut.GetFinalPosition(currentPostion);

            Assert.True(!result.IsLost &&
                        result.Position.PositionX == 2 &&
                        result.Position.PositionY == 3 &&
                        result.Position.Orientation == Orientation.S);
        }
Example #4
0
        public void GivenASetOfRobot_And_Movements_ShowOutput()
        {
            var movements = new List <PositionMove>();

            movements.Add(new PositionMove
            {
                InitialPosition = new Position {
                    PositionX = 1, PositionY = 1, Orientation = Orientation.E
                },
                Movements = MoveCommand_Extensions.ExampleCommandsRobotOne()
            });
            movements.Add(new PositionMove
            {
                InitialPosition = new Position {
                    PositionX = 3, PositionY = 2, Orientation = Orientation.N
                },
                Movements = MoveCommand_Extensions.ExampleCommandsRobotTwo()
            });
            movements.Add(new PositionMove
            {
                InitialPosition = new Position {
                    PositionX = 0, PositionY = 3, Orientation = Orientation.W
                },
                Movements = MoveCommand_Extensions.ExampleCommandsRobotThree()
            });


            var sut = new MarsBoardService();

            var result = sut.GetOutput(_marsGrid, movements);

            Assert.True(result.ToList().Count == 3);
            Assert.Collection(result,
                              item => Assert.True(item.Position.PositionX == 1 && item.Position.PositionY == 1 && item.Position.Orientation == Orientation.E),
                              item => Assert.True(item.IsLost && item.Scent.PositionX == 3 && item.Scent.PositionY == 3),
                              item => Assert.True(item.Position.PositionX == 2 && item.Position.PositionY == 3 && item.Position.Orientation == Orientation.S));
        }