//--------------------------------------------------------------------- private void CheckPercentageTable(string tableName, IPercentageTable table, string nextTableName) { inputLine.MatchName(tableName); bool haveLine = inputLine.GetNext(); while (haveLine && inputLine.VariableName != nextTableName) { StringReader currentLine = new StringReader(inputLine.ToString()); string disturbance = ReadInputValue <string>(currentLine); PlugInType disturbanceType; if (disturbance == "(default)") { disturbanceType = new PlugInType(disturbance); } else { disturbanceType = new PlugInType("disturbance:" + disturbance); } PoolPercentages percentages = table[disturbanceType]; Assert.AreEqual((double)percentages.Woody, (double)ReadInputValue <Percentage>(currentLine)); Assert.AreEqual((double)percentages.NonWoody, (double)ReadInputValue <Percentage>(currentLine)); haveLine = inputLine.GetNext(); } }
public void MatchName_Whitespace() { string varName = "Variable-Name"; InputLine line = MakeInputLine(" \t " + varName + " \r\n"); AssertLineHasValue(line, 1, varName); line.MatchName(varName); AssertNoMoreLines(line); }
public void MatchOptName_Missing() { string varName = "Variable-Name"; InputLine line = MakeInputLine(varName); AssertLineHasValue(line, 1, varName); Assert.IsFalse(line.MatchOptionalName("optional.variable")); line.MatchName(varName); AssertNoMoreLines(line); }
public void MatchName() { string varName = "Variable-Name"; InputLine line = MakeInputLine(varName); AssertLineHasValue(line, 1, varName); Assert.AreEqual(varName, line.ToString()); line.MatchName(varName); AssertNoMoreLines(line); }
//--------------------------------------------------------------------- private void TryMatchName(InputLine line, string name) { try { line.MatchName(name); } catch (System.Exception e) { Data.Output.WriteLine(e.Message); throw; } }
//--------------------------------------------------------------------- private void CheckParameterTable <TParm>(string tableName, Species.AuxParm <Ecoregions.AuxParm <TParm> > parmValues, string nextTableName) { inputLine.MatchName(tableName); bool haveLine = inputLine.GetNext(); List <IEcoregion> ecoregions = ReadEcoregions(); while (haveLine && inputLine.VariableName != nextTableName) { StringReader currentLine = new StringReader(inputLine.ToString()); ISpecies species = ReadSpecies(currentLine); foreach (IEcoregion ecoregion in ecoregions) { Assert.AreEqual(ReadInputValue <TParm>(currentLine), parmValues[species][ecoregion]); } haveLine = inputLine.GetNext(); } }
//--------------------------------------------------------------------- private void ReadAndCheckParameters(string filename) { IParameters parameters; try { reader = OpenFile(filename); parameters = parser.Parse(reader); } finally { reader.Close(); } try { // Now that we know the data file is properly formatted, read // data from it and compare it against parameter object. reader = OpenFile(filename); inputLine = new InputLine(reader); Assert.AreEqual(parser.LandisDataValue, ReadInputVar <string>("LandisData")); Assert.AreEqual(ReadInputVar <int>("Timestep"), parameters.Timestep); Assert.AreEqual(ReadInputVar <SeedingAlgorithms>("SeedingAlgorithm"), parameters.SeedAlgorithm); inputLine.MatchName("MinRelativeBiomass"); inputLine.GetNext(); List <IEcoregion> ecoregions = ReadEcoregions(); for (byte shadeClass = 1; shadeClass <= 5; shadeClass++) { StringReader currentLine = new StringReader(inputLine.ToString()); Assert.AreEqual(shadeClass, ReadInputValue <byte>(currentLine)); foreach (IEcoregion ecoregion in ecoregions) { // TODO: Eventually allow equality testing for Percentage Assert.AreEqual((double)ReadInputValue <Percentage>(currentLine), (double)parameters.MinRelativeBiomass[shadeClass][ecoregion]); } inputLine.GetNext(); } inputLine.MatchName("BiomassParameters"); inputLine.GetNext(); while (inputLine.VariableName != "EstablishProbabilities") { StringReader currentLine = new StringReader(inputLine.ToString()); ISpecies species = ReadSpecies(currentLine); Assert.AreEqual(ReadInputValue <double>(currentLine), parameters.LeafLongevity[species]); Assert.AreEqual(ReadInputValue <double>(currentLine), parameters.WoodyDecayRate[species]); Assert.AreEqual(ReadInputValue <double>(currentLine), parameters.MortCurveShapeParm[species]); inputLine.GetNext(); } CheckParameterTable("EstablishProbabilities", parameters.EstablishProbability, "MaxANPP"); CheckParameterTable("MaxANPP", parameters.MaxANPP, "LeafLitter:DecayRates"); const string AgeOnlyDisturbanceParms = "AgeOnlyDisturbances:BiomassParameters"; CheckParameterTable("LeafLitter:DecayRates", parameters.LeafLitterDecayRate, AgeOnlyDisturbanceParms); if (parameters.AgeOnlyDisturbanceParms != null) { Assert.AreEqual(ReadInputVar <string>(AgeOnlyDisturbanceParms), parameters.AgeOnlyDisturbanceParms); } } finally { inputLine = null; reader.Close(); } }