public void AStateNotSetMeansDead()
        {
            var aPosition = new Mock<IPosition>();
            var universe = new StateHolder();

            Assert.Equal(new Dead(), universe.GetState(aPosition.Object));
        }
        public void SettingCellStateIsIdempotent()
        {
            var aPosition = new Mock<IPosition>();
            var universe = new StateHolder();

            universe.SetState(aPosition.Object, new Alive());
            Assert.Equal(new Alive(), universe.GetState(aPosition.Object));

            universe.SetState(aPosition.Object, new Alive());
            Assert.Equal(new Alive(), universe.GetState(aPosition.Object));
        }
        public void EmptyCloneCreatesANewEmptyUniverse()
        {
            var universe = new StateHolder();
            var aPosition = new Mock<IPosition>();
            universe.SetState(aPosition.Object, new Alive());

            var newUniverse = universe.EmptyClone();

            Assert.NotSame(newUniverse, universe);
            Assert.Equal(new Dead(), newUniverse.GetState(aPosition.Object));
        }
        public void TheUniverseHoldsCellStates()
        {
            var aPosition = new Mock<IPosition>();
            var anotherPosition = new Mock<IPosition>();
            var universe = new StateHolder();

            universe.SetState(aPosition.Object, new Alive());
            universe.SetState(anotherPosition.Object, new Dead());

            Assert.Equal(new Alive(), universe.GetState(aPosition.Object));
            Assert.Equal(new Dead(), universe.GetState(anotherPosition.Object));
        }
        public void FourAliveCellsStayAlive()
        {
            var p00 = new CartesianPosition(0, 0);
            var p01 = new CartesianPosition(0, 1);
            var p11 = new CartesianPosition(1, 1);
            var p10 = new CartesianPosition(1, 0);

            var stateHolder = new StateHolder();
            stateHolder.SetState(p00, new Alive());
            stateHolder.SetState(p01, new Alive());
            stateHolder.SetState(p11, new Alive());
            stateHolder.SetState(p10, new Alive());

            var engine = new Engine<CartesianPosition>(stateHolder, new CartesianSpaceLimits());
            var secondGeneration = engine.NextGeneration();

            Assert.Equal(new Alive(), stateHolder.GetState(p00));
            Assert.Equal(new Alive(), stateHolder.GetState(p01));
            Assert.Equal(new Alive(), stateHolder.GetState(p11));
            Assert.Equal(new Alive(), stateHolder.GetState(p10));
        }
        public void ThreeAliveCellsRotate()
        {
            var p11 = new CartesianPosition(1, 1);
            var p12 = new CartesianPosition(1, 2);
            var p13 = new CartesianPosition(1, 3);

            var stateHolder = new StateHolder();
            stateHolder.SetState(p11, new Alive());
            stateHolder.SetState(p12, new Alive());
            stateHolder.SetState(p13, new Alive());

            var engine = new Engine<CartesianPosition>(stateHolder, new CartesianSpaceLimits());
            var secondGeneration = engine.NextGeneration();
            Assert.Equal(new Dead(), secondGeneration.GetState(p11));
            Assert.Equal(new Alive(), secondGeneration.GetState(p12));
            Assert.Equal(new Dead(), secondGeneration.GetState(p13));

            var thirdGeneration = engine.NextGeneration();
            Assert.Equal(new Alive(), thirdGeneration.GetState(p11));
            Assert.Equal(new Alive(), thirdGeneration.GetState(p12));
            Assert.Equal(new Alive(), thirdGeneration.GetState(p13));
        }