예제 #1
0
        public void Run_ShouldThrowError_IfRandomFileGiven()
        {
            var fileSystem = new MockFileSystem();
            var filePath   = "randomfilePath";

            var nasa = new Nasa(fileSystem);

            var exception = Assert.Throws <Exception>(() => nasa.Run(filePath));

            Assert.Equal("Instruction file not found!", exception.Message);
        }
예제 #2
0
        public void Run_ShouldThrowError_IfInstructionSetIsInvalid()
        {
            var fileSystem = new MockFileSystem(new Dictionary <string, MockFileData>
            {
                { @"./randomfilePath.txt", new MockFileData("") },
            });
            var filePath = "./randomfilePath.txt";

            var nasa      = new Nasa(fileSystem);
            var exception = Assert.Throws <Exception>(() => nasa.Run(filePath));

            Assert.Equal("Invalid instruction set!", exception.Message);
        }
예제 #3
0
        public void initialposition_33E_message_MMRMMRMRRM_finalposition_51E()
        {
            Plateau.SetUpperCoordinate(5, 5);
            ISpaceCompany company = new Nasa();
            var           rover   = new Rover(new Position(3, 3, Direction.E));

            company.Subscribe(rover);
            var message = new Message("MMRMMRMRRM");

            rover.Move(message);
            var finalPositionOfRover = rover.GetFinalPosition();
            var expectedResult       = "5 1 E";

            Assert.AreEqual(expectedResult, finalPositionOfRover);
        }
예제 #4
0
        public void initialposition_12N_message_LMLMLMLMM_finalposition_13N()
        {
            Plateau.SetUpperCoordinate(5, 5);
            ISpaceCompany company = new Nasa();
            var           rover   = new Rover(new Position(1, 2, Direction.N));

            company.Subscribe(rover);
            var message = new Message("LMLMLMLMM");

            rover.Move(message);
            var finalPositionOfRover = rover.GetFinalPosition();
            var expectedResult       = "1 3 N";

            Assert.AreEqual(expectedResult, finalPositionOfRover);
        }
예제 #5
0
        public void Run_ShouldMoveCorrectly(string input, string expected)
        {
            var fileSystem = new MockFileSystem(new Dictionary <string, MockFileData>
            {
                { @"./randomfilePath.txt", new MockFileData(input) },
            });
            var filePath = "./randomfilePath.txt";

            var nasa   = new Nasa(fileSystem);
            var result = nasa.Run(filePath);

            Assert.Single(result);

            Assert.Equal(expected, result[0].ToString());
        }
예제 #6
0
        public void Run_ShouldReturnOneRover_IfOneRoversInstructionsGiven()
        {
            var fileSystem = new MockFileSystem(new Dictionary <string, MockFileData>
            {
                { @"./randomfilePath.txt", new MockFileData(
                      "5 5" + Environment.NewLine +
                      "1 1 N" + Environment.NewLine +
                      "LRMMM") },
            });
            var filePath = "./randomfilePath.txt";

            var nasa   = new Nasa(fileSystem);
            var result = nasa.Run(filePath);

            Assert.Single(result);
        }
예제 #7
0
        public void Run_ShouldThrowError_IfThereIsAnInvalidInstruction()
        {
            var fileSystem = new MockFileSystem(new Dictionary <string, MockFileData>
            {
                { @"./randomfilePath.txt", new MockFileData(
                      "5 5" + Environment.NewLine +
                      "1 1 N" + Environment.NewLine +
                      "LRXMMM") },
            });
            var filePath = "./randomfilePath.txt";

            var nasa      = new Nasa(fileSystem);
            var exception = Assert.Throws <Exception>(() => nasa.Run(filePath));

            Assert.Equal("Invalid instruction!", exception.Message);
        }
예제 #8
0
        public void Run_ShouldThrowError_IfPlateauCoordinatesIsInvalid()
        {
            var fileSystem = new MockFileSystem(new Dictionary <string, MockFileData>
            {
                { @"./randomfilePath.txt", new MockFileData(
                      "A B" + Environment.NewLine +
                      "1 1 N" + Environment.NewLine +
                      "LRMMMM") },
            });
            var filePath = "./randomfilePath.txt";

            var nasa      = new Nasa(fileSystem);
            var exception = Assert.Throws <Exception>(() => nasa.Run(filePath));

            Assert.Equal("Invalid plateau coordinates!", exception.Message);
        }
예제 #9
0
        public void Run_ShouldRoverBeInTheSamePosition_IfFourLeftInstructionsGiven()
        {
            var fileSystem = new MockFileSystem(new Dictionary <string, MockFileData>
            {
                { @"./randomfilePath.txt", new MockFileData(
                      "5 5" + Environment.NewLine +
                      "1 1 N" + Environment.NewLine +
                      "LLLL") },
            });
            var filePath = "./randomfilePath.txt";

            var nasa   = new Nasa(fileSystem);
            var result = nasa.Run(filePath);

            Assert.Single(result);

            Assert.Equal("1 1 N", result[0].ToString());
        }
예제 #10
0
 public void CreateImage(Nasa parseddata)
 {
     pictureBox1.ImageLocation = parseddata.ToString();
 }