Example #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);
        }
Example #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);
        }
Example #3
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());
        }
Example #4
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);
        }
Example #5
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);
        }
Example #6
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);
        }
Example #7
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());
        }