Example #1
0
 internal void InfectedCellIsConstructedWithCorrectAttributes(
     [Frozen] IGerm germ,
     [Frozen] ushort signals,
     [Frozen] bool isAlive,
     ICellVisitor visitor,
     InfectedCell sut)
 {
     sut.Accept(visitor);
     VerifyCellExposesCorrectParametersToVisitor(signals, isAlive, visitor);
 }
Example #2
0
        public (ConsoleColor, string) GetColorEncodedCell(ICell cell)
        {
            (_colorCode, _currentCellCode) = cell switch
            {
                InfectedCell _ => (ConsoleColor.Red, "I"),
                HealthyCell _ => (ConsoleColor.Green, "C"),
                _ => (ConsoleColor.DarkYellow, string.Empty)
            };

            cell?.Accept(this);

            return(_colorCode, _currentCellCode);
        }
Example #3
0
        public string GetEncodedCell(ICell cell)
        {
            _currentCellCode = cell switch
            {
                InfectedCell _ => "I",
                HealthyCell _ => "C",
                             _ => string.Empty
            };

            cell?.Accept(this);

            return(_currentCellCode);
        }
Example #4
0
        internal void VirusDoesNotInfectAlreadyInfectedCellsOrNullCells(
            InfectedCell infectedCellToInfect,
            NullCell nullCellToInfect,
            LyticVirus sut)
        {
            var result        = new List <ICell>();
            var numberOfTries = (int)Ceiling(InfectionFailureRate * 3 * 10);

            for (int currentTry = 0; currentTry < numberOfTries; currentTry++)
            {
                result.Add(sut.InfectCell(infectedCellToInfect).Clone());
                result.Add(sut.InfectCell(nullCellToInfect).Clone());
            }

            VerifyNoNewlyInfectedCellsArePresent(result, numberOfTries);
        }
Example #5
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));
        }
Example #6
0
 public DeadInfectedCell(ushort selfSignal, ushort alertSignal, IGerm germ)
 {
     _cell = new InfectedCell(false, selfSignal, alertSignal, germ);
 }
Example #7
0
 public LivingInfectedCell(ushort selfSignal, ushort alertSignal, IGerm germ)
 {
     _cell = new InfectedCell(true, selfSignal, alertSignal, germ);
 }