Esempio n. 1
0
        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);
        }
Esempio n. 2
0
 private static void VerifyInputCellsAreCloned(Tissue2D input)
 {
     foreach (var cell in input.Tissue.Values)
     {
         Mock.Get(cell).Verify(c => c.Clone(), Times.Once);
     }
 }
Esempio n. 3
0
 public void PrintTissue_CellPrintIsCalled_ForEachCell(
     [Frozen][MockCellTissueCreation(50)] Tissue2D tissue,
     TissuePrinter sut)
 {
     sut.PrintTissue();
     VerifyCellStringencoderIsCalledForEachCell(tissue);
 }
Esempio n. 4
0
        internal void Advance_DoesNotReturnSameTissue2DInstanceAndCellsAreCloned(
            [MockCellTissueCreation(10)] Tissue2D input,
            RoundBasedGame sut)
        {
            var result = sut.Advance(input);

            VerifyNotSameInstance(input, result);
            VerifyInputCellsAreCloned(input);
        }
Esempio n. 5
0
 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);
 }
Esempio n. 6
0
        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);
        }
Esempio n. 7
0
        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);
        }
Esempio n. 8
0
        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);
        }
Esempio n. 9
0
        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++;
            }
        }
Esempio n. 10
0
        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());
        }
Esempio n. 11
0
        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));
        }
Esempio n. 12
0
 private static void VerifyNotSameInstance(Tissue2D input, Tissue2D result)
 {
     result.Should().NotBe(input);
 }
Esempio n. 13
0
 private static void VerifyCellStringencoderIsCalledForTotalCountTimes(ICell cell, Tissue2D tissue)
 {
     Mock.Get(cell).Verify(c => c.Accept(It.IsAny <CellStringEncoder>())
                           , Times.Exactly(tissue.Tissue.Count()));
 }
Esempio n. 14
0
 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();
 }
Esempio n. 15
0
 public ICell GrowTissue(Tissue2D input, Location location)
 => GetRandomNeighbour(input, location).Clone();
Esempio n. 16
0
 private ICell GrowTissue(Tissue2D input, Location location)
 => _growthMechanism.GrowTissue(input, location);