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) { cohorts.Grow((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.Remove(AgeBetween5And30); 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); } }
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) { cohorts.Grow((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.Remove(AgeBetween5And30); 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); } }