public void Should_Return_Partial_Input_When_Valid_Grid_Setup() { //setup var input = new SpaceDelimitedCharInstructionGridCommandPairInput(); //test var actual = input.ParseSurveyInput("4 6"); Assert.AreEqual(4, actual.TopRightCoordinate.X); Assert.AreEqual(6, actual.TopRightCoordinate.Y); }
public void Should_Return_Empty_Input_When_Invalid_Grid_Setup() { //setup var input = new SpaceDelimitedCharInstructionGridCommandPairInput(); //test var actual = input.ParseSurveyInput("3 t"); //assert Assert.IsNull(actual); }
static void Main(string[] args) { //I would normally use dependancy injection for these, rather than hard coded /*read and parse input*/ string filein = "input.txt"; string fileout = "output.txt"; if (!File.Exists(filein)) { return; } var inputfile = new SpaceDelimitedCharInstructionGridCommandPairInput(); var parsedInput = inputfile.ParseSurveyInput(File.ReadAllText(filein)); /*execute the commands*/ //instantiate the factory, again normally done via config var dictonary = new Dictionary <char, Instruction> { { (char)InstructionIdentifier.Left, new LeftInstruction(parsedInput.TopRightCoordinate, inputfile.BottomLeftCoordinate) }, { (char)InstructionIdentifier.Right, new RightInstruction(parsedInput.TopRightCoordinate, inputfile.BottomLeftCoordinate) }, { (char)InstructionIdentifier.Forward, new ForwardInstruction(1, parsedInput.TopRightCoordinate, inputfile.BottomLeftCoordinate) } }; var factory = new ShipInstructionFactory(dictonary); //I would have also abstracted this out a little more so the inplementation isnt all in client (here) foreach (var command in parsedInput.Commands) { foreach (var instrutionIdentifier in command.Instructions) { var instruction = factory.getInstruction(instrutionIdentifier); //if lost already, dont preceed if (!command.Position.Lost) { instruction.Move(command.Position); } } } /*write file*/ File.WriteAllText(fileout, String.Empty); using (StreamWriter w = File.AppendText(fileout)) { foreach (var command in parsedInput.Commands) { Console.WriteLine(command.Position.ToString()); w.WriteLine(command.Position.ToString()); } } }
public void Should_Return_Full_Input_When_Test_Data_Parsed() { //setup var input = new SpaceDelimitedCharInstructionGridCommandPairInput(); //test var actual = input.ParseSurveyInput(sampleInput); //assert overall no issues Assert.IsNotNull(actual); //assert grid Assert.AreEqual(5, actual.TopRightCoordinate.X); Assert.AreEqual(3, actual.TopRightCoordinate.Y); //assert 3 commands Assert.IsNotNull(actual.Commands); Assert.AreEqual(3, actual.Commands.Count()); //doesnt match sample output :S !!!!! Assert.AreEqual(Orientation.South, actual.Commands[2].Position.Orientation); }