public void OutputGenerator_ShouldGenerateListOfStrings_WhenPassedWordCountAndPrimes() { //Arrange var outputGenerator = new OutputGenerator(); var wordCountResults = new Dictionary <string, int> { { "compare", 22 }, { "the", 13 }, { "market", 10 }, { "codeTest", 7 } }; var listOfPrimes = new Dictionary <int, bool> { { 13, true }, { 7, true }, { 5, true } }; var expectedOutput = new List <string> { "compare, 22, False", "the, 13, True", "market, 10, False", "codeTest, 7, True" }; //Act var actualOutput = outputGenerator.GenerateOutput(wordCountResults, listOfPrimes); //Assert CollectionAssert.AreEquivalent(expectedOutput, actualOutput); }
public void GeneratesOutputForAllRovers([Frozen] Mock <IEnumerable <IRover> > rovers, [Frozen] Mock <IRover> rover, OutputGenerator sut) { sut.GenerateOutput(rovers.Object); rover.VerifyGet(p => p.Location, Times.Exactly(rovers.Object.Count())); rover.VerifyGet(p => p.Direction, Times.Exactly(rovers.Object.Count())); }
public void Test_example_outputs(byte xpos, byte ypos, Direction dir, string expected) { IOutputGenerator outputGenerator = new OutputGenerator(); string actual = outputGenerator.GenerateOutput(new Piece(byte.MaxValue, xpos, ypos, dir)); Assert.Equal(expected, actual); }
public void GeneratesOutputInExpectedFormat(int xCoordinate, int yCoordinate, Direction direction, bool isLanded, string expectedOutput, [Frozen] Mock <IRover> rover, OutputGenerator sut) { rover.Setup(p => p.Location).Returns(new Location(xCoordinate, yCoordinate)); rover.Setup(p => p.Direction).Returns(direction); rover.Setup(p => p.IsLanded()).Returns(isLanded); var actual = sut.GenerateOutput(new List <IRover>() { rover.Object }.AsEnumerable()); actual.Should().Be(expectedOutput); }
public int Compile() { events.AddEvent(new ComplilationStartedEvent()); CompilerArgumentsValidator.Validate(events, arguments); if (events.HasFatalError()) { events.AddEvent(new CompilationFinishedEvent(false)); return(1); } // Parse all the config files OutputGroupRepository outputGroups = new OutputGroupRepository(); ConfigInclusionRules config; try { events.AddEvent(new CompilationMessage("Loading config files")); config = ConfigFileLoaderFactory.Make().LoadConfigFiles(arguments.ConfigFiles, arguments); } catch (ConfigFileInvalidException e) { events.AddEvent(new CompilationMessage(e.Message)); events.AddEvent(new CompilationFinishedEvent(false)); return(1); } // Parse all the input files and create elements SectorElementCollection sectorElements = new SectorElementCollection(); DataParserFactory parserFactory = new DataParserFactory(sectorElements, events); InputFileList fileList; try { events.AddEvent(new CompilationMessage("Building input file list")); fileList = InputFileListFactory.CreateFromInclusionRules( new SectorDataFileFactory(new InputFileStreamFactory()), config, outputGroups ); } catch (System.Exception exception) { events.AddEvent(new CompilationMessage(exception.Message)); events.AddEvent(new CompilationFinishedEvent(false)); return(1); } events.AddEvent(new CompilationMessage("Injecting pre-parse static data")); RunwayCentrelineInjector.InjectRunwayCentrelineData(sectorElements); events.AddEvent(new CompilationMessage("Parsing input files")); foreach (AbstractSectorDataFile dataFile in fileList) { parserFactory.GetParserForFile(dataFile).ParseData(dataFile); } if (events.HasFatalError()) { events.AddEvent(new CompilationFinishedEvent(false)); return(1); } // There's some static data we need to inject to the collection for adjacent airports... events.AddEvent(new CompilationMessage("Injecting post-parse static data")); AdjacentAirportsInjector.InjectAdjacentAirportsData(sectorElements); // Now all the data is loaded, validate that there are no broken references etc. if (arguments.ValidateOutput) { events.AddEvent(new CompilationMessage("Validating data")); OutputValidator.Validate(sectorElements, arguments, events); if (events.HasFatalError()) { events.AddEvent(new CompilationFinishedEvent(false)); return(1); } } else { events.AddEvent(new CompilationMessage("Skipping output validation")); } // Generate the output OutputGenerator generator = new OutputGenerator( sectorElements, outputGroups, new CompilableElementCollectorFactory(sectorElements, outputGroups) ); foreach (AbstractOutputFile output in arguments.OutputFiles) { events.AddEvent(new CompilationMessage($"Generating {output.GetFileDescriptor()} output")); generator.GenerateOutput(output); } events.AddEvent(new CompilationFinishedEvent(true)); return(0); }