private static void AssertOsscillatorRepeatsInTwoGenerations(HashSet <Cell> initialState, IGenerationStrategy strategyUnderTest) { var gen1 = strategyUnderTest.AdvanceGeneration(initialState); gen1.Should().NotBeEquivalentTo(initialState); var gen2 = strategyUnderTest.AdvanceGeneration(gen1); gen2.Should().BeEquivalentTo(initialState); }
public void AdvanceGenerationDeadCellWithFourLiveNeighborsShouldRemainDead(IGenerationStrategy strategyUnderTest) { var nextGen = strategyUnderTest.AdvanceGeneration( GenerateLivingTestNeighborhood(this.testCell, coreCellLives: false, liveNeighborCount: 4)); nextGen.Should().NotContain(this.testCell); }
public void AdvanceGenerationDeadCellWithThreeLiveNeighborsShouldBecomeAlive(IGenerationStrategy strategyUnderTest) { var nextGen = strategyUnderTest.AdvanceGeneration( GenerateLivingTestNeighborhood(this.testCell, coreCellLives: false, liveNeighborCount: 3)); nextGen.Should().Contain(this.testCell); }
public void AdvanceGenerationLiveCellWithTwoLiveNeighborsShouldSurvive(IGenerationStrategy strategyUnderTest) { var nextGen = strategyUnderTest.AdvanceGeneration( GenerateLivingTestNeighborhood(this.testCell, coreCellLives: true, liveNeighborCount: 2)); nextGen.Should().Contain(this.testCell); }
internal static async Task Main(string[] args) { IGameInputSource gameInputSource = null; Parser.Default.ParseArguments <CommandLineOptions>(args) .WithParsed( (options) => { if (options.InputFile != null) { gameInputSource = new FileGameInputSource(options.InputFile, CellParser); } else { gameInputSource = new ConsoleGameInputSource(CellParser); } }) .WithNotParsed(errors => Environment.Exit(0)); try { var liveCells = await gameInputSource.GetInitialGameState(); if (liveCells.Count == 0) { System.Console.WriteLine("No input found! Exiting simulation."); PauseBeforeExit(); } var generation = 1; while (true) { System.Console.WriteLine($"Generation: {generation++}"); foreach (var cell in liveCells) { System.Console.WriteLine(cell); } System.Console.WriteLine( "Hit ENTER to simulate the next generation (or " + $"\"{InputConstants.InputEnd}\" to exit)."); var input = System.Console.ReadLine().Trim().ToLowerInvariant(); if (input == InputConstants.InputEnd) { break; } liveCells = GenerationStrategy.AdvanceGeneration(liveCells); } } catch (Exception ex) { System.Console.WriteLine(ex); PauseBeforeExit(); } }
public void AdvanceGenerationBlockStillLifeShouldRemainUnchanged(IGenerationStrategy strategyUnderTest) { var block = new HashSet <Cell> { new Cell(0, 0), new Cell(0, 1), new Cell(1, 0), new Cell(1, 1) }; var nextGen = strategyUnderTest.AdvanceGeneration(block); nextGen.Should().BeEquivalentTo(block); }
public void AdvanceGenerationTubStillLifeShouldRemainUnchanged(IGenerationStrategy strategyUnderTest) { var tub = new HashSet <Cell> { new Cell(0, 1), new Cell(1, 0), new Cell(1, 2), new Cell(2, 1) }; var nextGen = strategyUnderTest.AdvanceGeneration(tub); nextGen.Should().BeEquivalentTo(tub); }
public void AdvanceGenerationFromTwoLiveCellsWithOverlappingNeighborhoodsShouldIncludeAllNeighborsWithoutDuplicates(IGenerationStrategy strategyUnderTest) { MockGameRules.Setup(x => x.ShouldCellLive(It.IsAny <bool>(), It.IsAny <int>())).Returns(true); // Neighbors in column 2 overlap var cell1 = new Cell(1, 1); var cell2 = new Cell(1, 3); var nextGen = strategyUnderTest.AdvanceGeneration(new HashSet <Cell> { cell1, cell2 }); nextGen.Should().BeEquivalentTo(cell1.FindValidNeighbors().Union(cell2.FindValidNeighbors())); }
public void AdvanceGenerationFromTwoLiveCellsWithDisparateNeighborhoodsShouldIncludeAllNeighbors(IGenerationStrategy strategyUnderTest) { MockGameRules.Setup(x => x.ShouldCellLive(It.IsAny <bool>(), It.IsAny <int>())).Returns(true); // Not adjacent var cell1 = new Cell(10, 20); var cell2 = new Cell(50, 70); var nextGen = strategyUnderTest.AdvanceGeneration(new HashSet <Cell> { cell1, cell2 }); nextGen.Should().BeEquivalentTo(new HashSet <Cell>(cell1.FindValidNeighbors().Union(cell2.FindValidNeighbors()))); }
public void AdvanceGenerationBeehiveStillLifeShouldRemainUnchanged(IGenerationStrategy strategyUnderTest) { var beehive = new HashSet <Cell> { new Cell(0, 1), new Cell(0, 2), new Cell(1, 0), new Cell(1, 3), new Cell(2, 1), new Cell(2, 2) }; var nextGen = strategyUnderTest.AdvanceGeneration(beehive); nextGen.Should().BeEquivalentTo(beehive); }
public void AdvanceGenerationFromSingleLivingCellShouldResultInNoLivingCellsWhenNoneShouldLive(IGenerationStrategy strategyUnderTest) { var nextGen = strategyUnderTest.AdvanceGeneration(new HashSet <Cell> { new Cell(0, 0) }).Should().BeEmpty(); }
public void AdvanceGenerationFromNoLivingCellsShouldResultInNoLivingCells(IGenerationStrategy strategyUnderTest) { strategyUnderTest.AdvanceGeneration(new HashSet <Cell>()).Should().BeEmpty(); }