示例#1
0
        public void GOI_Evolve_EvolvesAllTheCells()
        {
            int callcount         = 0;
            var mockevolutionrule = new Mock <IEvolutionRule>();

            mockevolutionrule.Setup(rule => rule.EvolveCell(It.IsAny <Cell>())).Returns((Cell cell) => cell).Callback(() => callcount++);

            var mockneighbourrule = new Mock <INeighbourRule>();

            var mockneighbourrulefactory = new Mock <INeighbourRuleFactory>();

            mockneighbourrulefactory.Setup(nf => nf.Create(It.IsAny <ICellContainer>())).Returns(() => mockneighbourrule.Object);

            var mockevolutionrulefactory = new Mock <IEvolutionRuleFactory>();

            mockevolutionrulefactory.Setup(e => e.CreateEvolutionRule(It.IsAny <INeighbourRule>())).Returns(() => mockevolutionrule.Object);

            Grid grid = GridInitializationHelper.Get4By4gridWithAllDeadCells();

            BasicGameOfLife gameoflife = new BasicGameOfLife(grid, mockevolutionrulefactory.Object, mockneighbourrulefactory.Object);

            gameoflife.Evolve();

            Assert.AreEqual(16, callcount);
            Assert.AreEqual(2, gameoflife.GenerationNumber);
        }
示例#2
0
        private static IGameOfLife GetGameOfLifeController(Grid grid)
        {
            // Create the neighbourhood rule
            INeighbourRuleFactory neighbourrulefactory = new NeighbourRuleFactory();

            // Create the evolution rule
            IEvolutionRuleFactory evolutionruefactory = new EvolutionRuleFactory();

            IGameOfLife gameoflife = new BasicGameOfLife(grid, evolutionruefactory, neighbourrulefactory);

            return(gameoflife);
        }
示例#3
0
        public void GOI_Evolve_EvolvesAllTheCells()
        {
            int callcount = 0;
            var mockevolutionrule = new Mock<IEvolutionRule>();
            mockevolutionrule.Setup(rule => rule.EvolveCell(It.IsAny<Cell>())).Returns((Cell cell) => cell).Callback(() => callcount++);

            var mockneighbourrule = new Mock<INeighbourRule>();

            var mockneighbourrulefactory = new Mock<INeighbourRuleFactory>();
            mockneighbourrulefactory.Setup(nf => nf.Create(It.IsAny<ICellContainer>())).Returns(() => mockneighbourrule.Object);

            var mockevolutionrulefactory = new Mock<IEvolutionRuleFactory>();
            mockevolutionrulefactory.Setup(e => e.CreateEvolutionRule(It.IsAny<INeighbourRule>())).Returns(() => mockevolutionrule.Object);

            Grid grid = GridInitializationHelper.Get4By4gridWithAllDeadCells();

            BasicGameOfLife gameoflife = new BasicGameOfLife(grid, mockevolutionrulefactory.Object, mockneighbourrulefactory.Object);
            gameoflife.Evolve();

            Assert.AreEqual(16, callcount);
            Assert.AreEqual(2, gameoflife.GenerationNumber);
        }