Example #1
0
        /// <summary>
        /// Создать улей, и запустить его, как будто он работал
        /// в течение часа.
        /// </summary>
        /// <param name="state">Состояние улья.</param>
        /// <param name="checkForEveryIteration">Проверка на каждой итерации.</param>
        /// <returns>Улей, отработавший час и остановленный.</returns>
        private MathBeehive CreateBeehiveWorkedForHour(
            IBeehiveState state,
            Action <MathBeehive> checkForEveryIteration = null)
        {
            MathBeehive beehive = new MathBeehive(state);

            for (int i = 0; i < this.GetIterationsInHour(beehive); i++)
            {
                checkForEveryIteration?.Invoke(beehive);
                beehive.SingleIteration();
            }

            beehive.Validate();

            return(beehive);
        }
Example #2
0
        public void MathBeehive_BeesCountStable()
        {
            ServiceLocator.Instance.RegisterService <IApiaryBalance>(new DefaultApiaryBalance());

            int initialBeesCount = 10000;

            IBeehiveState testState = new BeehiveXmlState
            {
                HoneyCount      = 0,
                BeesTotalCount  = initialBeesCount,
                BeesInsideCount = initialBeesCount,
                WorkerBeesCount = initialBeesCount - 1000,
                QueensCount     = 0,
                GuardsCount     = 1000
            };

            MathBeehive beehive = this.CreateBeehiveWorkedForHour(testState);

            Assert.AreEqual(initialBeesCount, beehive.BeesTotalCount);
        }
Example #3
0
        public void MathBeehive_CorrectGuardsLimitation()
        {
            ServiceLocator.Instance.RegisterService <IApiaryBalance>(new DefaultApiaryBalance());

            IBeehiveState testState = new BeehiveXmlState
            {
                HoneyCount      = 0,
                BeesTotalCount  = 10000,
                BeesInsideCount = 10000,
                WorkerBeesCount = 9990,
                QueensCount     = 0,
                GuardsCount     = 10
            };

            MathBeehive beehive = this.CreateBeehiveWorkedForHour(testState);

            int expectedHoney = this.ExpectedChecksPerHourFromOneGuard
                                * testState.GuardsCount;

            Assert.IsTrue(Math.Abs(expectedHoney - beehive.HoneyCount)
                          <= expectedHoney * MathBeehiveTests.Inaccuracy);
        }
Example #4
0
        public void MathBeehive_CorrectBeeProducing()
        {
            ServiceLocator.Instance.RegisterService <IApiaryBalance>(
                new ApiaryBalanceDontProducingQueens(new DefaultApiaryBalance()));

            IBeehiveState testState = new BeehiveXmlState
            {
                HoneyCount      = 0,
                BeesTotalCount  = 100,
                BeesInsideCount = 100,
                WorkerBeesCount = 0,
                QueensCount     = 100,
                GuardsCount     = 0
            };

            MathBeehive beehive = this.CreateBeehiveWorkedForHour(testState);

            int expectedNewBees = this.ExpectedChildrenFromOneQueenPerHour
                                  * testState.QueensCount;

            Assert.IsTrue(Math.Abs(expectedNewBees - beehive.BeesTotalCount)
                          <= expectedNewBees * MathBeehiveTests.Inaccuracy);
        }
Example #5
0
        public void MathBeehive_OutsideWorkersNormalStartTheirWork()
        {
            ServiceLocator.Instance.RegisterService <IApiaryBalance>(new DefaultApiaryBalance());

            IBeehiveState testState = new BeehiveXmlState
            {
                HoneyCount      = 5,
                BeesTotalCount  = 10,
                BeesInsideCount = 1,
                WorkerBeesCount = 9,
                QueensCount     = 0,
                GuardsCount     = 1
            };

            MathBeehive beehive = this.CreateBeehiveWorkedForHour(testState);

            long expectedHoney = this.ExpectedHoneyFromOneBeePerHour
                                 * testState.WorkerBeesCount
                                 + testState.HoneyCount;

            Assert.IsTrue(Math.Abs(expectedHoney - beehive.HoneyCount)
                          <= expectedHoney * MathBeehiveTests.Inaccuracy);
        }
Example #6
0
 /// <summary>
 /// Получить количество итераций, которые необходимо произвести
 /// для имитации работы улья в течение часа.
 /// </summary>
 /// <param name="beehive">Улей.</param>
 /// <returns>Количество итераций.</returns>
 private int GetIterationsInHour(MathBeehive beehive)
 {
     return(1000 / beehive.IntervalMs * 60 * 60);
 }