public void DefaultCtor() { Percentage percentage = new Percentage(); Assert.AreEqual(0.0, percentage.Value); Assert.AreEqual(0.0, (double) percentage); Assert.AreEqual("0%", percentage.ToString()); }
public void DoubleCtor() { Percentage percentage = new Percentage(0.567); Assert.AreEqual(0.567, percentage.Value); Assert.AreEqual(0.567, (double) percentage); Assert.AreEqual("56.7%", percentage.ToString()); }
//--------------------------------------------------------------------- public static void AgeOrRangeWasRead(AgeRange ageRange, Percentage percentage) { ageOrRangeWasRead = true; // Have we started reading ages and ranges for another species? // If so, then first clear the old values from the previous // species. if (ageSelectors[HarvestSpeciesDataset.MostRecentlyFetchedSpecies.Index] == null) { ages.Clear(); ranges.Clear(); percentages.Clear(); } if (ageRange.Start == ageRange.End) ages.Add(ageRange.Start); else ranges.Add(ageRange); if (percentage != null) percentages[ageRange.Start] = percentage; if (HarvestSpeciesDataset.MostRecentlyFetchedSpecies != null) ageSelectors[HarvestSpeciesDataset.MostRecentlyFetchedSpecies.Index] = new SpecificAgesCohortSelector(ages, ranges, percentages); currentSpecies = HarvestSpeciesDataset.MostRecentlyFetchedSpecies; }
//--------------------------------------------------------------------- public static void AgeOrRangeWasRead(AgeRange ageRange, Percentage percentage) { ageOrRangeWasRead = true; // Have we started reading ages and ranges for another species? // If so, then first clear the old values from the previous // species. bool clearOldValues = (HarvestSpeciesDataset.MostRecentlyFetchedSpecies != null) && (ageSelectors[HarvestSpeciesDataset.MostRecentlyFetchedSpecies.Index] == null); if (clearOldValues) { ages.Clear(); ranges.Clear(); percentages.Clear(); } if (ageRange.Start == ageRange.End) ages.Add(ageRange.Start); else ranges.Add(ageRange); if (percentage != null) percentages[ageRange.Start] = percentage; if (Landis.Extension.BaseHarvest.InputParametersParser.AllSpeciesNameWasRead) ageSelectorForAllSpecies = new SpecificAgesCohortSelector(ages, ranges, percentages); if (HarvestSpeciesDataset.MostRecentlyFetchedSpecies != null) ageSelectors[HarvestSpeciesDataset.MostRecentlyFetchedSpecies.Index] = new SpecificAgesCohortSelector(ages, ranges, percentages); currentSpecies = HarvestSpeciesDataset.MostRecentlyFetchedSpecies; }
//--------------------------------------------------------------------- static Percentage() { Util.Type.SetDescription<Percentage>("percentage"); InputValues.Register<Percentage>(Percentage.Parse); MinValue = new Percentage(MinValueAsDouble); MaxValue = new Percentage(MaxValueAsDouble); }
//--------------------------------------------------------------------- public void AgeOrRangeWasRead(AgeRange ageRange, Percentage percentage) { Assert.AreEqual(expectedRange, ageRange); if (expectedPercentage == null) Assert.IsNull(percentage); else Assert.AreEqual((double) expectedPercentage, (double) percentage); eventHandlerCalled = true; }
//--------------------------------------------------------------------- static InputParametersParser() { // FIXME: Hack to ensure that Percentage is registered with InputValues Edu.Wisc.Forest.Flel.Util.Percentage p = new Edu.Wisc.Forest.Flel.Util.Percentage(); // Register the local method for parsing a cohort age or age range. InputValues.Register <AgeRange>(ParseAgeOrRange); Type.SetDescription <AgeRange>("cohort age or age range"); uShortParse = InputValues.GetParseMethod <ushort>(); }
//--------------------------------------------------------------------- private static float ReduceInput(float poolInput, Percentage reductionPercentage, ActiveSite site) { float reduction = (poolInput * (float) reductionPercentage); SiteVars.SourceSink[site].Carbon += (double) reduction * 0.47; //SiteVars.FireEfflux[site] += (double) reduction * 0.47; return (poolInput - reduction); }
public void ReadAgeOrRange_RangePercentage() { StringReader reader = new StringReader("30-75(10%)"); int index; eventHandlerCalled = false; expectedRange = new AgeRange(30, 75); expectedPercentage = Percentage.Parse("10%"); InputValue<AgeRange> ageRange = PartialThinning.ReadAgeOrRange(reader, out index); Assert.IsTrue(eventHandlerCalled); Assert.AreEqual(0, index); Assert.AreEqual(-1, reader.Peek()); }
public void ReadAgeOrRange_AgeWhitespacePercentage() { StringReader reader = new StringReader("66 ( 50% )\t"); int index; eventHandlerCalled = false; expectedRange = new AgeRange(66, 66); expectedPercentage = Percentage.Parse("50%"); InputValue<AgeRange> ageRange = PartialThinning.ReadAgeOrRange(reader, out index); Assert.IsTrue(eventHandlerCalled); Assert.AreEqual(0, index); Assert.AreEqual('\t', reader.Peek()); }
public void ReadAgeOrRange_RangeWhitespacePercentage() { StringReader reader = new StringReader(" 1-100 (22.2%)Hi"); int index; eventHandlerCalled = false; expectedRange = new AgeRange(1, 100); expectedPercentage = Percentage.Parse("22.2%"); InputValue<AgeRange> ageRange = PartialThinning.ReadAgeOrRange(reader, out index); Assert.IsTrue(eventHandlerCalled); Assert.AreEqual(1, index); Assert.AreEqual('H', reader.Peek()); }
//--------------------------------------------------------------------- /// <summary> /// Selects which cohorts are harvested. /// </summary> /// <returns> /// true if the given cohort is to be harvested. The cohort's biomass /// should be reduced by the percentage returned in the second /// parameter. /// </returns> public bool Selects(ICohort cohort, out Percentage percentage) { ushort ageToLookUp = 0; AgeRange? containingRange; if (agesAndRanges.Contains(cohort.Age, out containingRange)) { if (! containingRange.HasValue) ageToLookUp = cohort.Age; else { ageToLookUp = containingRange.Value.Start; } if (! percentages.TryGetValue(ageToLookUp, out percentage)) percentage = defaultPercentage; return true; } percentage = null; return false; }
//--------------------------------------------------------------------- public AppliedPrescription(Prescription prescription, Percentage percentageToHarvest, int beginTime, int endTime) { //set prescription this.prescription = prescription; //set stand ranking method this.standSpreadSiteSelector = prescription.SiteSelectionMethod as StandSpreading; //set harvest percentage this.percentageToHarvest = percentageToHarvest; //set begin time and end time this.beginTime = beginTime; this.endTime = endTime; }
//--------------------------------------------------------------------- public AppliedRepeatHarvest(RepeatHarvest repeatHarvest, Percentage percentageToHarvest, int beginTime, int endTime) : base(repeatHarvest, percentageToHarvest, beginTime, endTime) { this.repeatHarvest = repeatHarvest; if (repeatHarvest is SingleRepeatHarvest) { isMultipleRepeatHarvest = false; setAside = SetAsideForSingleHarvest; } else { isMultipleRepeatHarvest = true; setAside = SetAsideForMultipleHarvests; } this.reservedStands = new Queue<ReservedStand>(); }
public void ReadAgeOrRange_Multiple() { StringReader reader = new StringReader(" 1-40 (50%) 50(65%)\t 65-70 71-107 ( 15% ) 109"); int index; //0123456789_123456789_^123456789_123456789_12345678 eventHandlerCalled = false; expectedRange = new AgeRange(1, 40); expectedPercentage = Percentage.Parse("50%"); InputValue<AgeRange> ageRange = PartialThinning.ReadAgeOrRange(reader, out index); Assert.IsTrue(eventHandlerCalled); Assert.AreEqual(1, index); Assert.AreEqual(' ', reader.Peek()); eventHandlerCalled = false; expectedRange = new AgeRange(50, 50); expectedPercentage = Percentage.Parse("65%"); ageRange = PartialThinning.ReadAgeOrRange(reader, out index); Assert.IsTrue(eventHandlerCalled); Assert.AreEqual(13, index); Assert.AreEqual('\t', reader.Peek()); eventHandlerCalled = false; expectedRange = new AgeRange(65, 70); expectedPercentage = null; ageRange = PartialThinning.ReadAgeOrRange(reader, out index); Assert.IsTrue(eventHandlerCalled); Assert.AreEqual(22, index); Assert.AreEqual('7', reader.Peek()); eventHandlerCalled = false; expectedRange = new AgeRange(71, 107); expectedPercentage = Percentage.Parse("15%"); ageRange = PartialThinning.ReadAgeOrRange(reader, out index); Assert.IsTrue(eventHandlerCalled); Assert.AreEqual(29, index); Assert.AreEqual(' ', reader.Peek()); eventHandlerCalled = false; expectedRange = new AgeRange(109, 109); expectedPercentage = null; ageRange = PartialThinning.ReadAgeOrRange(reader, out index); Assert.IsTrue(eventHandlerCalled); Assert.AreEqual(45, index); Assert.AreEqual(-1, reader.Peek()); }
//--------------------------------------------------------------------- private static ushort ReduceInput(ushort poolInput, Percentage reductionPercentage) { ushort reduction = (ushort) (poolInput * reductionPercentage); return (ushort) (poolInput - reduction); }
//--------------------------------------------------------------------- private void ValidatePercentage(Percentage percentage) { if (percentage < 0.0 || percentage > 1.0) throw new InputValueException(percentage.ToString(), "Value must be between 0% and 100%"); }
//--------------------------------------------------------------------- private static int ReduceInput(int poolInput, Percentage reductionPercentage) { int reduction = (int) (poolInput * reductionPercentage); return (int) (poolInput - reduction); }
//--------------------------------------------------------------------- private void Check50Percent(Percentage percentage) { Assert.AreEqual(0.50, percentage.Value); Assert.AreEqual("50%", percentage.ToString()); Assert.AreEqual("50%", string.Format("{0}", percentage)); Assert.AreEqual("50%", string.Format("{0:%}", percentage)); Assert.AreEqual("50.0%", string.Format("{0:#.0%}", percentage)); Assert.AreEqual(".500", string.Format("{0:#.##0}", percentage)); Assert.AreEqual(".5", string.Format("{0:#.###}", percentage)); Assert.AreEqual("0.50", string.Format("{0:0.#0}", percentage)); }
static InputParameterParser() { Edu.Wisc.Forest.Flel.Util.Percentage p = new Edu.Wisc.Forest.Flel.Util.Percentage(); RegisterForInputValues(); }
public void CtorArg_TooBig() { Percentage percentage = new Percentage(double.MaxValue); }
//--------------------------------------------------------------------- /// <summary> /// Initializes a new instance. /// </summary> public PoolPercentages(Percentage woody, Percentage nonWoody) { this.woody = woody; this.nonWoody = nonWoody; }
//--------------------------------------------------------------------- public AppliedPrescription(Prescription prescription, ManagementArea managementArea, Percentage percentageToHarvest, int beginTime, int endTime) { this.prescription = prescription; this.standSpreadSiteSelector = prescription.SiteSelectionMethod as StandSpreading; this.percentageToHarvest = percentageToHarvest; this.areaToHarvest = managementArea.Area * percentageToHarvest; this.beginTime = beginTime; this.endTime = endTime; }
public void Init() { // Need to reference the class so its static ctor is called before // any tests run; otherwise, they'll fail because a parse or read // method hasn't been registered with InputValues class. Percentage p = new Percentage(); percentVar = new InputVar<Percentage>("Percentage Var"); }
//--------------------------------------------------------------------- /// <summary> /// Adds a prescription to be applied to the management area. /// </summary> public void ApplyPrescription(Prescription prescription, Percentage percentageToHarvest, int startTime, int endTime) { prescriptions.Add(new AppliedPrescription(prescription, percentageToHarvest, startTime, endTime)); }
//--------------------------------------------------------------------- static SpecificAgesCohortSelector() { defaultPercentage = Percentage.Parse("100%"); }
public void CtorArg_TooSmall() { Percentage percentage = new Percentage(double.MinValue); }
//--------------------------------------------------------------------- private static double ReduceInput(double poolInput, Percentage reductionPercentage) { double reduction = poolInput * reductionPercentage; return (poolInput - reduction); }
public InputParameterParser() { // FIXME: Hack to ensure that Percentage is registered with InputValues Edu.Wisc.Forest.Flel.Util.Percentage p = new Edu.Wisc.Forest.Flel.Util.Percentage(); }
//--------------------------------------------------------------------- /// <summary> /// Adds a prescription to be applied to the management area. /// </summary> public void ApplyPrescription(Prescription prescription, Percentage percentageToHarvest, int startTime, int endTime) { // tjs - 2008.12.17 - reversing if and else if so that it checks for // SingleRepeatHarvest. This is done because SingleRepeatHarvest // is a descendent of RepeatHarvest, so the RepeatHarvest condition // is true if prescription is SingleRepeatHarvest if(prescription is SingleRepeatHarvest) { AppliedRepeatHarvest appy = new AppliedRepeatHarvest((SingleRepeatHarvest) prescription, percentageToHarvest, startTime, endTime); prescriptions.Add(appy); } else if (prescription is RepeatHarvest) { AppliedRepeatHarvest appy = new AppliedRepeatHarvest((RepeatHarvest)prescription, percentageToHarvest, startTime, endTime); prescriptions.Add(appy); } else prescriptions.Add(new AppliedPrescription(prescription, percentageToHarvest, startTime, endTime)); }
public void PercentageMin() { Percentage percentage = new Percentage(Percentage.MinValueAsDouble); Assert.AreEqual(string.Format("{0}%", double.MinValue), percentage.ToString()); }