コード例 #1
0
        //---------------------------------------------------------------------

        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();
            }
        }
コード例 #2
0
        public void MatchName_Whitespace()
        {
            string    varName = "Variable-Name";
            InputLine line    = MakeInputLine(" \t " + varName + " \r\n");

            AssertLineHasValue(line, 1, varName);
            line.MatchName(varName);
            AssertNoMoreLines(line);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        //---------------------------------------------------------------------

        private void TryMatchName(InputLine line,
                                  string name)
        {
            try {
                line.MatchName(name);
            }
            catch (System.Exception e) {
                Data.Output.WriteLine(e.Message);
                throw;
            }
        }
コード例 #6
0
        //---------------------------------------------------------------------

        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();
            }
        }
コード例 #7
0
        //---------------------------------------------------------------------

        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();
            }
        }