コード例 #1
0
        public void GenerateExplorationReportTest_TwoExplorersCollide_ExpectedOutput()
        {
            var deploymentZone = new Plateau {
                Size = new Size(5, 5)
            };

            var team   = new ExplorationTeam(deploymentZone);
            var rover1 = new Rover(team);
            var rover2 = new Rover(team);

            rover1.Launch(new Position(5, 5), Heading.North);
            team.Add(rover1);
            rover1.Move(new List <Movement>());
            rover2.Launch(new Position(5, 4), Heading.North);
            team.Add(rover2);
            rover2.Move(new List <Movement> {
                // MMRMMRMRRM
                Movement.Forward,
                Movement.Forward,
                Movement.Forward
            });

            var expectedReport = new StringBuilder();

            expectedReport.Append("5 5 N");
            expectedReport.AppendLine();
            expectedReport.Append("5 4 N");
            expectedReport.AppendLine();
            Assert.AreEqual(expectedReport.ToString(), team.GenerateExplorationReport());
        }
コード例 #2
0
 /// <summary>
 /// Create the mission control center (MCC) that is responsible for the provided deployment zone.
 /// </summary>
 /// <param name="deploymentZone">The zone that this MCC is responsible for exploring with its exploration crew.</param>
 /// <exception cref="ArgumentNullException">Thrown if provided deployment zone is null.</exception>
 public MissionControlCenter(IDeploymentZoneChart deploymentZone)
 {
     DeploymentDestination = deploymentZone ??
                             throw new ArgumentNullException(nameof(deploymentZone),
                                                             "Deployment zone cannot be null.");
     Explorers = new ExplorationTeam(deploymentZone);
     _setCommandChainExecutors = new Dictionary <CommandChainType, Action <IExplorerCommand> > {
         {
             CommandChainType.InitializeDeploymentZone, command => {
                 var deploymentZoneChartCommand = (DeploymentZoneChartCommand)command;
                 deploymentZoneChartCommand.SetDeploymentZoneChart(DeploymentDestination);
             }
         }, {
             CommandChainType.DeployExplorer, command => {
                 var deployExplorerCommand = (DeployExplorerCommand)command;
                 var rover = new Rover(Explorers);
                 deployExplorerCommand.SetExplorer(rover);
                 Explorers.Add(rover);
             }
         }, {
             CommandChainType.Explore, command => {
                 var exploreCommand = (ExploreCommand)command;
                 exploreCommand.SetExplorer(Explorers.Last());
             }
         }
     };
 }
コード例 #3
0
        public void GenerateExplorationReportTest_HitWall_ExpectedOutput()
        {
            var deploymentZone = new Plateau {
                Size = new Size(5, 5)
            };

            var team  = new ExplorationTeam(deploymentZone);
            var rover = new Rover(team);

            rover.Launch(new Position(5, 5), Heading.North);
            team.Add(rover);
            rover.Move(new List <Movement> {
                Movement.Forward,
                Movement.Forward,
                Movement.Forward,
                Movement.Forward,
                Movement.Forward,
                Movement.Forward,
                Movement.Forward,
                Movement.Forward,
                Movement.Forward,
                Movement.Forward,
                Movement.Forward
            });

            var expectedReport = new StringBuilder();

            expectedReport.Append("5 5 N");
            expectedReport.AppendLine();
            Assert.AreEqual(expectedReport.ToString(), team.GenerateExplorationReport());
        }
コード例 #4
0
        public void GenerateExplorationReportTest_ExplorerNotLaunched_ExpectedOutput()
        {
            var team = new ExplorationTeam(new Plateau());

            team.Add(new Rover(team));
            var expectedReport = new StringBuilder();

            expectedReport.Append("Explorer not launched.");
            expectedReport.AppendLine();
            Assert.AreEqual(expectedReport.ToString(), team.GenerateExplorationReport());
        }
コード例 #5
0
ファイル: RoverTests.cs プロジェクト: pengii23/MarsRover
        public void MoveTest()
        {
            var deploymentZone = new Plateau {
                Size = new Size(5, 5)
            };

            var team   = new ExplorationTeam(deploymentZone);
            var rover1 = new Rover(team);
            var rover2 = new Rover(team);

            rover1.Launch(new Position(1, 2), Heading.North);
            team.Add(rover1);
            rover1.Move(new List <Movement> {
                // LMLMLMLMM
                Movement.Left,
                Movement.Forward,
                Movement.Left,
                Movement.Forward,
                Movement.Left,
                Movement.Forward,
                Movement.Left,
                Movement.Forward,
                Movement.Forward
            });
            rover2.Launch(new Position(3, 3), Heading.East);
            team.Add(rover2);
            rover2.Move(new List <Movement> {
                // MMRMMRMRRM
                Movement.Forward,
                Movement.Forward,
                Movement.Right,
                Movement.Forward,
                Movement.Forward,
                Movement.Right,
                Movement.Forward,
                Movement.Right,
                Movement.Right,
                Movement.Forward
            });
        }
コード例 #6
0
        public void IsPositionAvailableTest_PassIsValidAndnoExplorerAtPosition()
        {
            var team = new ExplorationTeam(new Plateau {
                Size = new Size(5, 5)
            });
            var rover1 = new Rover(team);

            rover1.Launch(new Position(5, 5), Heading.North);
            team.Add(rover1);
            var rover2 = new Rover(team);

            Assert.IsTrue(rover2.IsPositionAvailable(new Position(4, 5)));
        }
コード例 #7
0
        public void IsPositionAvailableTest_ExplorerExistsAtPositionFails()
        {
            var team = new ExplorationTeam(new Plateau {
                Size = new Size(5, 5)
            });
            var rover1 = new Rover(team);

            rover1.Launch(new Position(5, 5), Heading.North);
            team.Add(rover1);
            var rover2 = new Rover(team);

            Assert.IsFalse(rover2.IsPositionAvailable(new Position(5, 5)));
        }
コード例 #8
0
        public void GenerateExplorationReportTest_OneExplorerLaunched_ExpectedOutput()
        {
            var deploymentZone = new Plateau {
                Size = new Size(5, 5)
            };

            var team  = new ExplorationTeam(deploymentZone);
            var rover = new Rover(team);

            rover.Launch(new Position(1, 2), Heading.North);
            team.Add(rover);
            var expectedReport = new StringBuilder();

            expectedReport.Append("1 2 N");
            expectedReport.AppendLine();
            Assert.AreEqual(expectedReport.ToString(), team.GenerateExplorationReport());
        }