Exemple #1
0
        public void ApplyRules_CallsApplyOnlyOnes_WhenCalled([NotNull] IRule <ICellInformation> ruleOne,
                                                             [NotNull] IRule <ICellInformation> ruleTwo,
                                                             [NotNull] ICellInformation cell)
        {
            // Arrange
            var cells = new[]
            {
                cell
            };

            ruleOne.Priority.Returns(1);
            ruleTwo.Priority.Returns(2);

            var rules = new[]
            {
                ruleOne,
                ruleTwo
            };

            Engine sut = CreateSut(rules);

            // Act
            sut.ApplyRules(cells);

            // Assert
            ruleOne.Received().Apply(cell);
            ruleTwo.DidNotReceive().Apply(cell);
        }
Exemple #2
0
            public override void Initialize(ICellInformation info)
            {
                Conditions.Add(Substitute.For <ICondition>());
                Conditions.Add(Substitute.For <ICondition>());

                WasCalledInitialize = true;
            }
        public void Apply_CallsApply_WhenCalled()
        {
            // Arrange
            ICellInformation info = CreateCellInformation();
            TestRule         sut  = CreateSut();

            // Act
            sut.Apply(info);

            // Assert
            //sut.WasCalledApply.ShouldBeTrue();
        }
        public void Initialize_CallsInitialize_WhenCalled()
        {
            // Arrange
            ICellInformation info = CreateCellInformation();
            TestRule         sut  = CreateSut();

            // Act
            sut.Initialize(info);

            // Assert
            //sut.WasCalledInitialize.ShouldBeTrue();
        }
        public void Initialize_AddsConditions_WhenCalled()
        {
            // Arrange
            ICellInformation info = CreateCellInformation();
            TestRule         sut  = CreateSut();

            // Act
            sut.Initialize(info);

            // Assert
            //sut.GetConditions().Count().ShouldEqual(2);
        }
        public void Priority_ReturnsInteger_WhenCalled()
        {
            // Arrange
            ICellInformation info = CreateCellInformation();
            TestRule         sut  = CreateSut();

            // Act
            sut.Apply(info);

            // Assert
            Assert.AreEqual(1,
                            sut.Priority);
        }
Exemple #7
0
        private void ApplyRulesToCellInformation(ICellInformation information)
        {
            foreach (IRule <ICellInformation> rule in m_Repository.Rules)
            {
                rule.ClearConditions();
                rule.Initialize(information);

                if (rule.IsValid())
                {
                    rule.Apply(information);
                    break;
                }
            }
        }
Exemple #8
0
        public void ApplyRules_CallsApply_WhenCalled([NotNull] IRule <ICellInformation> rule,
                                                     [NotNull] ICellInformation cell)
        {
            // Arrange
            var cells = new[]
            {
                cell
            };

            Engine sut = CreateSut(rule);

            // Act
            sut.ApplyRules(cells);

            // Assert
            rule.Received().Apply(cell);
        }
        //todo testing, should be in separate class
        public IEnumerable <ICellInformation> Neighbours(Dictionary <int, ICells> rows,
                                                         int rowIndex,
                                                         int columnIndex)
        {
            ICellInformation north = NeighbourNorth(rows,
                                                    rowIndex,
                                                    columnIndex);
            ICellInformation south = NeighbourSouth(rows,
                                                    rowIndex,
                                                    columnIndex);
            ICellInformation east = NeighbourEast(rows,
                                                  rowIndex,
                                                  columnIndex);
            ICellInformation west = NeighbourWest(rows,
                                                  rowIndex,
                                                  columnIndex);

            ICellInformation northEast = NeighbourNorthEast(rows,
                                                            rowIndex,
                                                            columnIndex);
            ICellInformation southEast = NeighbourSouthEast(rows,
                                                            rowIndex,
                                                            columnIndex);
            ICellInformation northWest = NeighbourNorthWest(rows,
                                                            rowIndex,
                                                            columnIndex);
            ICellInformation southWest = NeighbourSouthWest(rows,
                                                            rowIndex,
                                                            columnIndex);

            var neighbours = new[]
            {
                north,
                south,
                east,
                west,
                northEast,
                southEast,
                northWest,
                southWest
            };

            return(neighbours);
        }
Exemple #10
0
        public int CompareTo(ICellInformation other)
        {
            // todo testing
            if (RowIndex.CompareTo(other.RowIndex) == 0 &&
                ColumnIndex.CompareTo(other.ColumnIndex) == 0 &&
                Status.CompareTo(other.Status) == 0 &&
                NeighboursAlive.CompareTo(other.NeighboursAlive) == 0)
            {
                return(0);
            }

            double distanceThis  = DistanceFromOrigin();
            double distanceOther = other.DistanceFromOrigin();

            if (distanceThis < distanceOther)
            {
                return(-1);
            }
            return(1);
        }
 public abstract ICellInformation Apply(ICellInformation info);
 public abstract void Initialize(ICellInformation info);
 public IEnumerable <ICellInformation> Neighbours(ICellInformation cell)
 {
     return(m_LivingCellFinder.Neighbours(m_Rows,
                                          cell.RowIndex,
                                          cell.ColumnIndex));
 }
Exemple #14
0
            public override ICellInformation Apply(ICellInformation info)
            {
                WasCalledApply = true;

                return(info);
            }