示例#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;
        }
        public void Constructor_WhenGivenDimensions_PreparesRandomPatternCorrectly()
        {
            // arrange
            int rows = 13;
            int cols = 44;

            // act
            var randomPattern = new RandomPattern(rows, cols);

            // assert
            Assert.AreEqual(
                expected: rows,
                actual: randomPattern.GetPattern().Length,
                message: "The number of rows were wrong.");

            Assert.IsTrue(
                randomPattern.GetPattern().All(x => x.Length == cols),
                message: "The number of columns were wrong somehow.");

            Assert.IsFalse(
                randomPattern.IsStable,
                message: "The pattern reports it's stable, which we can never know.");
        }