Пример #1
0
        /// <summary>
        /// Builds a new life form.
        /// </summary>
        /// <param name="lifeFormType">The life form type to build.</param>
        /// <returns>A newly instantiated life form object.</returns>
        public static LifeFormBase Build(LifeForm lifeFormType)
        {
            LifeFormBase lifeForm = null;
            switch (lifeFormType)
            {
                case LifeForm.Empty:
                    lifeForm = new Empty();
                    break;

                case LifeForm.Acorn:
                    lifeForm = new Acorn();
                    break;

                case LifeForm.AircraftCarrier:
                    lifeForm = new AircraftCarrier();
                    break;

                case LifeForm.FivePoint:
                    lifeForm = new FivePoint();
                    break;

                default:
                    lifeForm = new RandomPattern(
                        rows: RANDOMPATTERNHEIGHT,
                        cols: RANDOMPATTERNWIDTH);
                    break;
            }

            return lifeForm;
        }
Пример #2
0
        public void Constructor_WhenInvoked_PreparesAcornCorrectly()
        {
            // act
            var acorn = new Acorn();

            int oneSide = acorn.GetPattern().Length;
            int otherSide = acorn.GetPattern().Max(x => x.Length);

            // assert
            Assert.IsTrue(
                oneSide == 8 && oneSide == otherSide,
                message: "The acorn pattern was not of size 8x8.");

            Assert.IsTrue(
                acorn.IsStable,
                message: "The acorn pattern was not stable.");

            Assert.AreEqual(
                expected: 5206,
                actual: acorn.StabilizesAt,
                message: "The acorn pattern stabilizes at the wrong time.");

            Assert.AreEqual(
                expected: 633,
                actual: acorn.StablePopulation,
                message: "The acorn pattern has wrong number of cells in the stable population.");
        }