예제 #1
0
        public void ClearCut()
        {
            disturbance.Damage = disturbance.ClearCut;
            siteCohorts.DamageBy(disturbance);

            CheckCohorts(siteCohorts[abiebals]);
            CheckCohorts(siteCohorts[betualle]);

            CheckDeadCohorts(abiebals, 30, 40, 50, 150, 170);
            CheckDeadCohorts(betualle, 100, 120, 280, 300);
        }
        //---------------------------------------------------------------------

        private void CohortsRemoved(object disturbance)
        {
            SiteCohorts cohorts = new SiteCohorts();
            const ushort initialBiomass = 40;

            mockCalculator.CountCalled = 0;
            mockCalculator.Change = 1;

            int timeOfLastSucc = 0;
            for (int time = 1; time <= 50; time++) {
                //  Simulate the site being disturbed every 8 years which
                //  results in a new cohort being added.
                bool siteDisturbed = (time % 8 == 0);

                bool isSuccTimestep = (time % successionTimestep == 0);

                if (siteDisturbed || isSuccTimestep) {
                    Util.Grow(cohorts, (ushort) (time - timeOfLastSucc),
                              activeSite, isSuccTimestep);
                    timeOfLastSucc = time;
                }

                if (siteDisturbed)
                    cohorts.AddNewCohort(poputrem, initialBiomass);
            }

            //  Expected sequence of cohort changes:
            //
            //        Time  Grow_________
            //        Last         Cohorts               New
            //  Time  Succ  years  afterwards            Cohort
            //  ----  ----  -----  ---------------       ------
            //    8     0     8                           1(40)
            //   16     8     8    9(48)                  1(40)
            //   20    16     4    20(95*)                       * = 48+3 + 40+3 + 1
            //   24    20     4    24(99)                 1(40)
            //   32    24     8    32(107),9(48)          1(40)
            //   40    32     8    40(115),20(103*)       1(40)  * = 48+7 + 40+7 + 1
            //   48    40     8    48(123),28(111),9(48)  1(40)

            expectedCohorts.Clear();
            expectedCohorts[poputrem] = new ushort[] {
                //  age  biomass
                    48,    123,
                    28,    111,
                     9,     48,
                     1,     40
            };
            Util.CheckCohorts(expectedCohorts, cohorts);

            //  Remove cohorts whose ages are between 10 and 30
            expectedSender = cohorts[poputrem];
            deadCohorts.Clear();
            if (disturbance is IDisturbance)
                cohorts.DamageBy((IDisturbance) disturbance);
            else if (disturbance is AgeCohort.IDisturbance)
                ((AgeCohort.ISiteCohorts) cohorts).DamageBy((AgeCohort.IDisturbance) disturbance);

            expectedCohorts.Clear();
            expectedCohorts[poputrem] = new ushort[] {
                //  age  biomass
                    48,    123,
                     1,     40
            };
            Util.CheckCohorts(expectedCohorts, cohorts);
            
            CheckDeadCohorts(deadCohorts);
        }
        public void CohortsRemoved()
        {
            SiteCohorts  cohorts        = new SiteCohorts();
            const ushort initialBiomass = 40;

            mockCalculator.CountCalled = 0;
            mockCalculator.Change      = 1;

            int timeOfLastSucc = 0;

            for (int time = 1; time <= 50; time++)
            {
                //  Simulate the site being disturbed every 8 years which
                //  results in a new cohort being added.
                bool siteDisturbed = (time % 8 == 0);

                bool isSuccTimestep = (time % successionTimestep == 0);

                if (siteDisturbed || isSuccTimestep)
                {
                    Util.Grow(cohorts, (ushort)(time - timeOfLastSucc),
                              activeSite, isSuccTimestep);
                    timeOfLastSucc = time;
                }

                if (siteDisturbed)
                {
                    cohorts.AddNewCohort(poputrem, initialBiomass);
                }
            }

            //  Expected sequence of cohort changes:
            //
            //        Time  Grow_________
            //        Last         Cohorts               New
            //  Time  Succ  years  afterwards            Cohort
            //  ----  ----  -----  ---------------       ------
            //    8     0     8                           1(40)
            //   16     8     8    9(48)                  1(40)
            //   20    16     4    20(95*)                       * = 48+3 + 40+3 + 1
            //   24    20     4    24(99)                 1(40)
            //   32    24     8    32(107),9(48)          1(40)
            //   40    32     8    40(115),20(103*)       1(40)  * = 48+7 + 40+7 + 1
            //   48    40     8    48(123),28(111),9(48)  1(40)

            expectedCohorts.Clear();
            expectedCohorts[poputrem] = new ushort[] {
                //  age  biomass
                48, 123,
                28, 111,
                9, 48,
                1, 40
            };
            Util.CheckCohorts(expectedCohorts, cohorts);

            //  Remove cohorts whose ages are between 10 and 30
            expectedSite = null;
            deadCohorts.Clear();
            cohorts.DamageBy(new RemoveAgeBetween5And30(expectedSite));

            expectedCohorts.Clear();
            expectedCohorts[poputrem] = new ushort[] {
                //  age  biomass
                48, 123,
                1, 40
            };
            Util.CheckCohorts(expectedCohorts, cohorts);

            Assert.AreEqual(2, deadCohorts.Count);
            ushort[] cohortData = new ushort[] {
                //  age  biomass (in young to old order because Remove goes
                //                from back to front)
                9, 48,
                28, 111
            };
            for (int i = 0; i < deadCohorts.Count; i++)
            {
                ICohort deadCohort = deadCohorts[i];
                Assert.AreEqual(poputrem, deadCohort.Species);
                Assert.AreEqual(cohortData[i * 2], deadCohort.Age);
                Assert.AreEqual(cohortData[i * 2 + 1], deadCohort.Biomass);
            }
        }
        //---------------------------------------------------------------------

        private void CohortsRemoved(object disturbance)
        {
            SiteCohorts  cohorts        = new SiteCohorts();
            const ushort initialBiomass = 40;

            mockCalculator.CountCalled = 0;
            mockCalculator.Change      = 1;

            int timeOfLastSucc = 0;

            for (int time = 1; time <= 50; time++)
            {
                //  Simulate the site being disturbed every 8 years which
                //  results in a new cohort being added.
                bool siteDisturbed = (time % 8 == 0);

                bool isSuccTimestep = (time % successionTimestep == 0);

                if (siteDisturbed || isSuccTimestep)
                {
                    Util.Grow(cohorts, (ushort)(time - timeOfLastSucc),
                              activeSite, isSuccTimestep);
                    timeOfLastSucc = time;
                }

                if (siteDisturbed)
                {
                    cohorts.AddNewCohort(poputrem, initialBiomass);
                }
            }

            //  Expected sequence of cohort changes:
            //
            //        Time  Grow_________
            //        Last         Cohorts               New
            //  Time  Succ  years  afterwards            Cohort
            //  ----  ----  -----  ---------------       ------
            //    8     0     8                           1(40)
            //   16     8     8    9(48)                  1(40)
            //   20    16     4    20(95*)                       * = 48+3 + 40+3 + 1
            //   24    20     4    24(99)                 1(40)
            //   32    24     8    32(107),9(48)          1(40)
            //   40    32     8    40(115),20(103*)       1(40)  * = 48+7 + 40+7 + 1
            //   48    40     8    48(123),28(111),9(48)  1(40)

            expectedCohorts.Clear();
            expectedCohorts[poputrem] = new ushort[] {
                //  age  biomass
                48, 123,
                28, 111,
                9, 48,
                1, 40
            };
            Util.CheckCohorts(expectedCohorts, cohorts);

            //  Remove cohorts whose ages are between 10 and 30
            expectedSender = cohorts[poputrem];
            deadCohorts.Clear();
            if (disturbance is IDisturbance)
            {
                cohorts.DamageBy((IDisturbance)disturbance);
            }
            else if (disturbance is AgeCohort.ICohortDisturbance)
            {
                ((AgeCohort.ISiteCohorts)cohorts).DamageBy((AgeCohort.ICohortDisturbance)disturbance);
            }

            expectedCohorts.Clear();
            expectedCohorts[poputrem] = new ushort[] {
                //  age  biomass
                48, 123,
                1, 40
            };
            Util.CheckCohorts(expectedCohorts, cohorts);

            CheckDeadCohorts(deadCohorts);
        }
        public void CohortsRemoved()
        {
            SiteCohorts cohorts = new SiteCohorts();
            const ushort initialBiomass = 40;

            mockCalculator.CountCalled = 0;
            mockCalculator.Change = 1;

            int timeOfLastSucc = 0;
            for (int time = 1; time <= 50; time++) {
                //  Simulate the site being disturbed every 8 years which
                //  results in a new cohort being added.
                bool siteDisturbed = (time % 8 == 0);

                bool isSuccTimestep = (time % successionTimestep == 0);

                if (siteDisturbed || isSuccTimestep) {
                    Util.Grow(cohorts, (ushort) (time - timeOfLastSucc),
                              activeSite, isSuccTimestep);
                    timeOfLastSucc = time;
                }

                if (siteDisturbed)
                    cohorts.AddNewCohort(poputrem, initialBiomass);
            }

            //  Expected sequence of cohort changes:
            //
            //        Time  Grow_________
            //        Last         Cohorts               New
            //  Time  Succ  years  afterwards            Cohort
            //  ----  ----  -----  ---------------       ------
            //    8     0     8                           1(40)
            //   16     8     8    9(48)                  1(40)
            //   20    16     4    20(95*)                       * = 48+3 + 40+3 + 1
            //   24    20     4    24(99)                 1(40)
            //   32    24     8    32(107),9(48)          1(40)
            //   40    32     8    40(115),20(103*)       1(40)  * = 48+7 + 40+7 + 1
            //   48    40     8    48(123),28(111),9(48)  1(40)

            expectedCohorts.Clear();
            expectedCohorts[poputrem] = new ushort[] {
                //  age  biomass
                    48,    123,
                    28,    111,
                     9,     48,
                     1,     40
            };
            Util.CheckCohorts(expectedCohorts, cohorts);

            //  Remove cohorts whose ages are between 10 and 30
            expectedSite = null;
            deadCohorts.Clear();
            cohorts.DamageBy(new RemoveAgeBetween5And30(expectedSite));

            expectedCohorts.Clear();
            expectedCohorts[poputrem] = new ushort[] {
                //  age  biomass
                    48,    123,
                     1,     40
            };
            Util.CheckCohorts(expectedCohorts, cohorts);

            Assert.AreEqual(2, deadCohorts.Count);
            ushort[] cohortData = new ushort[] {
                //  age  biomass (in young to old order because Remove goes
                //                from back to front)
                     9,     48,
                    28,    111
            };
            for (int i = 0; i < deadCohorts.Count; i++) {
                ICohort deadCohort = deadCohorts[i];
                Assert.AreEqual(poputrem, deadCohort.Species);
                Assert.AreEqual(cohortData[i*2], deadCohort.Age);
                Assert.AreEqual(cohortData[i*2+1], deadCohort.Biomass);
            }
        }