コード例 #1
0
ファイル: LeftRotation_Tests.cs プロジェクト: 4uva/Rover-App
 public void FacingWest()
 {
     Rover rover = new Rover(new Position(1, 1), RoverFacing.West, playGround);
     rover.TurnLeft();
     RoverFacing roverfacing = rover.Facing;
     Assert.AreEqual(RoverFacing.South, roverfacing);
 }
コード例 #2
0
ファイル: LeftRotation_Tests.cs プロジェクト: 4uva/Rover-App
 public void FacingEast()
 {
     Rover rover = new Rover(new Position(2, 0), RoverFacing.East, playGround);
     rover.TurnLeft();
     RoverFacing roverfacing = rover.Facing;
     Assert.AreEqual(RoverFacing.North, roverfacing);
 }
コード例 #3
0
ファイル: LeftRotation_Tests.cs プロジェクト: 4uva/Rover-App
 public void FacingSouth()
 {
     Rover rover = new Rover(new Position(0, 2), RoverFacing.South, playGround);
     rover.TurnLeft();
     RoverFacing roverfacing = rover.Facing;
     Assert.AreEqual(RoverFacing.East, roverfacing);
 }
コード例 #4
0
ファイル: RightRotation_Tests.cs プロジェクト: 4uva/Rover-App
        public void FacingWest()
        {
            Rover rover = new Rover(new Position(0, 0), RoverFacing.West, playGround);

            rover.TurnRight();
            RoverFacing roverfacing = rover.Facing;

            Assert.AreEqual(RoverFacing.North, roverfacing);
        }
コード例 #5
0
 public Rover(Position position, RoverFacing facing, PlayGround playGround)
 {
     Position        = position;
     Facing          = facing;
     this.playGround = playGround;
     if (!IsPositionGood(position))
     {
         throw new ArgumentException("initial position outside border");
     }
 }
コード例 #6
0
ファイル: LeftRotation_Tests.cs プロジェクト: 4uva/Rover-App
 public void FacingNorth()
 {
     // arrange
     Rover rover = new Rover(new Position(1, 1), RoverFacing.North, playGround);
     // act
     rover.TurnLeft();
     // assert
     RoverFacing roverfacing = rover.Facing;
     // (first expected than actual)
     Assert.AreEqual(RoverFacing.West, roverfacing);
 }
コード例 #7
0
ファイル: Rover.cs プロジェクト: ArtMike/GitTest
        public override int GetHashCode()
        {
            var hashCode = 1494645696;

            hashCode = hashCode * -1521134295 + RoverFacing.GetHashCode();
            hashCode = hashCode * -1521134295 + EqualityComparer <Position> .Default.GetHashCode(RoverPosition);

            hashCode = hashCode * -1521134295 + EqualityComparer <Dictionary <string, ICommand> > .Default.GetHashCode(Commands);

            return(hashCode);
        }
コード例 #8
0
        public void Should_change_facing_to_north_rotate_to_right()
        {
            // GIVEN
            var facing = new RoverFacing(FacingTypes.West);

            // WHEN
            facing.MoveToRight();

            // THEN
            Assert.IsNotNull(facing);
            Assert.AreEqual(FacingTypes.North, facing.CurrentFacing);
        }
コード例 #9
0
        public void Should_change_facing_to_west_when_rotate_to_left()
        {
            // GIVEN
            var facing = new RoverFacing(FacingTypes.North);

            // WHEN
            facing.MoveToLeft();

            // THEN
            Assert.IsNotNull(facing);
            Assert.AreEqual(FacingTypes.West, facing.CurrentFacing);
        }
コード例 #10
0
ファイル: ProgramTest.cs プロジェクト: ArtMike/GitTest
        public void Execute_Exit_command(string commands, RoverFacing expectedRoverFacing, int expectedRoverPositionX,
                                         int expectedRroverPositionY)
        {
            var expectedConsoleOut = string.Empty;
            int consoleExitCode;

            using (var consoleOutput = new ConsoleOutput())
            {
                consoleExitCode = StartConsoleApplication(commands);
                Assert.AreEqual(0, consoleExitCode);
                Assert.AreEqual(expectedConsoleOut, consoleOutput.GetOuput().Replace("\r", string.Empty).Replace("\n", string.Empty));
            }
        }
コード例 #11
0
        public void ChangeFacing(bool left)
        {
            if (left)
            {
                roverFacing = roverFacing == RoverFacing.North ? RoverFacing.West : (RoverFacing)((int)roverFacing - 1);
            }
            else
            {
                roverFacing = roverFacing == RoverFacing.West ? RoverFacing.North : (RoverFacing)((int)roverFacing + 1);
            }

            Console.WriteLine($"Rover is now at {roverPositionX}, {roverPositionY} - facing {roverFacing}");
        }
コード例 #12
0
        public void Execute_command_north_forward(string commands, RoverFacing expectedRoverFacing, int expectedRoverPositionX, int expectedRroverPositionY)
        {
            // Arrange
            var expectedRover = new Rover(expectedRoverFacing, new Position(expectedRoverPositionX, expectedRroverPositionY));
            var rover         = _rover;

            // Act
            foreach (var command in commands.ToCharArray())
            {
                rover.Execute(command.ToString());
            }

            // Assert
            Assert.AreEqual(expectedRover, _rover);
        }
コード例 #13
0
        public void Rotate_left_test(int index, RoverFacing roverFacing)
        {
            // Arrange
            var expectedRoverFacing = roverFacing;
            var rover = _rover;

            // Act
            for (var i = 0; i < index; i++)
            {
                rover.RotateLeft();
            }

            // Assert
            Assert.AreEqual(rover.RoverFacing, expectedRoverFacing);
        }
コード例 #14
0
        public void Rotate_left_command_test(int index, RoverFacing roverFacing)
        {
            // Arrange
            var expectedRoverFacing = roverFacing;
            var rover = _rover;
            var rotateRoverLeftCommand = new RotateRoverLeftCommand(rover);

            // Act
            for (var i = 0; i < index; i++)
            {
                rotateRoverLeftCommand.Execute();
            }

            // Assert
            Assert.AreEqual(rover.RoverFacing, expectedRoverFacing);
        }
コード例 #15
0
        public void Execute_rotate_rover_right_command_test(string commands, RoverFacing expectedRoverFacing, int expectedRoverPositionX, int expectedRroverPositionY)
        {
            // Arrange
            var expectedRover = new Rover(expectedRoverFacing, new Position(expectedRoverPositionX, expectedRroverPositionY));
            var rover         = _rover;

            // Act
            foreach (var command in commands.ToCharArray())
            {
                rover.Execute(command.ToString());
            }

            // Assert
            Assert.AreEqual(expectedRover.RoverPosition, _rover.RoverPosition);
            Assert.AreEqual(expectedRover.RoverFacing, _rover.RoverFacing);
            Assert.IsInstanceOfType(expectedRover.Commands["R"], _rover.Commands["R"].GetType());
            Assert.IsInstanceOfType(expectedRover.Commands["L"], _rover.Commands["L"].GetType());
            Assert.IsInstanceOfType(expectedRover.Commands["F"], _rover.Commands["F"].GetType());
        }
コード例 #16
0
ファイル: Rover.cs プロジェクト: snes20/Rover
 public static void PrintRoverPosition(int roverPositionX, int roverPositionY, RoverFacing roverFacing)
 {
     Console.WriteLine($"Rover is now at {roverPositionX}, {roverPositionY} - facing {roverFacing}\r\n");
 }
コード例 #17
0
ファイル: RoverPosition.cs プロジェクト: snes20/Rover
 private RoverPosition()
 {
     RoverPositionX      = 0;
     RoverPositionY      = 0;
     RoverFacingPosition = RoverFacing.North;
 }
コード例 #18
0
 public void TurnRight()
 {
     Facing = Facing == RoverFacing.West ?
              RoverFacing.North :
              (RoverFacing)((int)Facing + 1);
 }
コード例 #19
0
 public void TurnLeft()
 {
     Facing = Facing == RoverFacing.North ?
              RoverFacing.West :
              (RoverFacing)((int)Facing - 1);
 }
コード例 #20
0
ファイル: RoverStatus.cs プロジェクト: mmsoftpl/sketch
 internal RoverStatus(MapCoordinates position, RoverFacing facing)
 {
     Position = position;
     Facing   = facing;
 }
コード例 #21
0
ファイル: Rover.cs プロジェクト: ArtMike/GitTest
 public Rover(RoverFacing roverFacing, Position roverPosition) : this()
 {
     RoverPosition = roverPosition;
     RoverFacing   = roverFacing;
 }
コード例 #22
0
ファイル: Mars.cs プロジェクト: mmsoftpl/sketch
        public static RoverUnit StartExpedition(Map map, MapCoordinates startLocation, RoverFacing facing)
        {
            if (!map.CheckCoordinates(startLocation))
            {
                throw new RoverCrashLandedException($"Rover crash landed on Mars, start location {startLocation.AsText()} unreachable on {map.AsText()} map");
            }

            return(new RoverUnit(new RoverStatus(map.GetPosition(startLocation), facing), map));
        }