private void VerifyLessNullCellsPresent(Tissue2D input, Tissue2D result) { var resultNullCells = result.Tissue.Values.Count(c => c is NullCell); var inputNullCells = input.Tissue.Values.Count(c => c is NullCell); resultNullCells.Should().BeLessThan(inputNullCells); }
private static void VerifyInputCellsAreCloned(Tissue2D input) { foreach (var cell in input.Tissue.Values) { Mock.Get(cell).Verify(c => c.Clone(), Times.Once); } }
public void PrintTissue_CellPrintIsCalled_ForEachCell( [Frozen][MockCellTissueCreation(50)] Tissue2D tissue, TissuePrinter sut) { sut.PrintTissue(); VerifyCellStringencoderIsCalledForEachCell(tissue); }
internal void Advance_DoesNotReturnSameTissue2DInstanceAndCellsAreCloned( [MockCellTissueCreation(10)] Tissue2D input, RoundBasedGame sut) { var result = sut.Advance(input); VerifyNotSameInstance(input, result); VerifyInputCellsAreCloned(input); }
public void PrintTissue_CellPrintIsCalled_CorrectNumberOfTimes2( [Frozen] ICell cell, //be sure to freeze it, otherwise a new tissue is created for parameters and stuff [Frozen][MockCellTissueCreation] Tissue2D tissue, TissuePrinter sut) { sut.PrintTissue(); VerifyCellStringencoderIsCalledForTotalCountTimes(cell, tissue); }
public void Create_Tissue2D_WithCorrectLocationOrigin(int x, int y, [FloatAsRatio] float living, [Frozen(Matching.ImplementedInterfaces)] ReverseTestShuffler shuffler, //we need to make sure max Location is in but do not want to use a complex shuffler Tissue2DFactory sut) { Tissue2D result = sut.Create(x, y, living, 1 - living); VerifyLocationBounds(x, y, result); }
public void Create_Tissue2D_WithCorrectNumberOfCells(int x, int y, [FloatAsRatio] float living, [Frozen(Matching.ImplementedInterfaces)] NullShuffle shuffler, Tissue2DFactory sut) { Tissue2D result = sut.Create(x, y, living, 1 - living); result.Tissue.Count.Should().Be(x * y); }
internal void Advance_TissueGrows_NullCellsGetReduced( [TissueCreationFromFactory(10)] Tissue2D input, [Frozen(Matching.ImplementedInterfaces)] TissueGrowthMechanism growth, RoundBasedGame sut) { var result = sut.Advance(input); VerifyNotSameInstance(input, result); VerifyLessNullCellsPresent(input, result); }
private void VerifyCellStringencoderIsCalledForEachCell(Tissue2D tissue) { var cells = tissue.Tissue.Values; var currentCount = 0; foreach (var cell in cells) { Mock.Get(cell) .Verify(c => c.Accept(It.IsAny <CellStringEncoder>()), Times.Once, $"because invocation must not happen only for the first {currentCount} times but for all {cells.Count()}"); currentCount++; } }
private ICell GetRandomNeighbour(Tissue2D input, Location currentLocation) { var maxTries = 10; for (int i = 0; i < maxTries; i++) { int rndY = ConvertToOffset(_rnd.Next(0, 2)); int rndX = ConvertToOffset(_rnd.Next(0, 2)); var pickLocation = new Location(currentLocation.X - rndX, currentLocation.Y - rndY); if (input.Tissue.TryGetValue(pickLocation, out ICell neigbour)) { return(neigbour); } } return(new NullCell()); }
public Tissue2D Advance(Tissue2D input) { var result = ImmutableDictionary <Location, ICell> .Empty; foreach ((Location location, ICell cell) in input.Tissue) { result = cell switch { NullCell _ => result.Add(location, GrowTissue(input, location)), InfectedCell currentCell => result.Add(location, PropagateInfection(location, currentCell)), HealthyCell currentCell => result.Add(location, PropagateInfection(location, currentCell)), _ => result.Add(location, cell.Clone()) } } ; return(new Tissue2D(result)); }
private static void VerifyNotSameInstance(Tissue2D input, Tissue2D result) { result.Should().NotBe(input); }
private static void VerifyCellStringencoderIsCalledForTotalCountTimes(ICell cell, Tissue2D tissue) { Mock.Get(cell).Verify(c => c.Accept(It.IsAny <CellStringEncoder>()) , Times.Exactly(tissue.Tissue.Count())); }
private static void VerifyLocationBounds(int x, int y, Tissue2D result) { result.Tissue.TryGetValue(new Location(0, 0), out _).Should().BeTrue(); result.Tissue.TryGetValue(new Location(x - 1, y - 1), out _).Should().BeTrue(); result.Tissue.TryGetValue(new Location(x, y), out _).Should().BeFalse(); }
public ICell GrowTissue(Tissue2D input, Location location) => GetRandomNeighbour(input, location).Clone();
private ICell GrowTissue(Tissue2D input, Location location) => _growthMechanism.GrowTissue(input, location);