Beispiel #1
0
        //---------------------------------------------------------------------

        private void CompareDatasetAndFile(IDataset dataset,
                                           string filename)
        {
            FileLineReader file      = OpenFile(filename);
            InputLine      inputLine = new InputLine(file);

            InputVar <string> LandisData = new InputVar <string>(Landis.Data.InputVarName);

            inputLine.ReadVar(LandisData);

            int expectedIndex = 0;

            foreach (IEcoregion ecoregion in dataset)
            {
                Assert.AreEqual(expectedIndex, ecoregion.Index);
                expectedIndex++;

                Assert.IsTrue(inputLine.GetNext());
                currentLine = new StringReader(inputLine.ToString());

                Assert.AreEqual(ReadValue <bool>(), ecoregion.Active);
                Assert.AreEqual(ReadValue <byte>(), ecoregion.MapCode);
                Assert.AreEqual(ReadValue <string>(), ecoregion.Name);
                Assert.AreEqual(ReadValue <string>(), ecoregion.Description);
            }
            Assert.IsFalse(inputLine.GetNext());
            file.Close();
        }
Beispiel #2
0
        //---------------------------------------------------------------------

        private void CompareDatasetAndFile(ISpeciesDataset dataset,
                                           string filename)
        {
            FileLineReader file      = OpenFile(filename);
            InputLine      inputLine = new InputLine(file);

            InputVar <string> LandisData = new InputVar <string>(Landis.Data.InputVarName);

            inputLine.ReadVar(LandisData);

            int expectedIndex = 0;

            foreach (ISpecies species in dataset)
            {
                Assert.AreEqual(expectedIndex, species.Index);
                expectedIndex++;

                Assert.IsTrue(inputLine.GetNext());
                currentLine = new StringReader(inputLine.ToString());

                Assert.AreEqual(ReadValue <string>(), species.Name);
                Assert.AreEqual(ReadValue <int>(), species.Longevity);
                Assert.AreEqual(ReadValue <int>(), species.Maturity);
                Assert.AreEqual(ReadValue <byte>(), species.ShadeTolerance);
                Assert.AreEqual(ReadValue <byte>(), species.FireTolerance);
                Assert.AreEqual(ReadEffectiveSeedDist(), species.EffectiveSeedDist);
                Assert.AreEqual(ReadValue <int>(), species.MaxSeedDist);
                Assert.AreEqual(ReadValue <float>(), species.VegReprodProb);
                Assert.AreEqual(ReadValue <int>(), species.MinSproutAge);
                Assert.AreEqual(ReadValue <int>(), species.MaxSproutAge);
                Assert.AreEqual(ReadValue <PostFireRegeneration>(), species.PostFireRegeneration);
            }
            Assert.IsFalse(inputLine.GetNext());
            file.Close();
        }
Beispiel #3
0
        //---------------------------------------------------------------------

        private TValue ReadInputVar <TValue>(string name)
        {
            InputVar <TValue> var = new InputVar <TValue>(name);

            inputLine.ReadVar(var);
            inputLine.GetNext();
            return(var.Value.Actual);
        }
        public void ReadStrVar_Word()
        {
            string    valueAsStr = "a.word_E=mc^2";
            InputLine line       = MakeInputLine(strVar.Name + " " + valueAsStr);

            line.ReadVar(strVar);
            Assert.AreEqual(valueAsStr, strVar.Value.Actual);
            Assert.AreEqual(valueAsStr, strVar.Value.String);
            AssertNoMoreLines(line);
        }
        public void ReadIntVar_Whitespace()
        {
            string    valueAsStr = "345";
            InputLine line       = MakeInputLine(" \t " + intVar.Name + " " + valueAsStr + "\r \n");

            line.ReadVar(intVar);
            Assert.AreEqual(345, intVar.Value.Actual);
            Assert.AreEqual(valueAsStr, intVar.Value.String);
            AssertNoMoreLines(line);
        }
        public void ReadIntVar_Comma()
        {
            string    valueAsStr = "12,345,678";
            InputLine line       = MakeInputLine(intVar.Name + " " + valueAsStr);

            line.ReadVar(intVar);
            Assert.AreEqual(12345678, intVar.Value.Actual);
            Assert.AreEqual(valueAsStr, intVar.Value.String);
            AssertNoMoreLines(line);
        }
        //---------------------------------------------------------------------

        private void TryReadVar(InputLine line,
                                InputVariable var)
        {
            try {
                line.ReadVar(var);
            }
            catch (System.Exception e) {
                Data.Output.WriteLine(e.Message);
                throw;
            }
        }
        public void ReadOptVar_Missing()
        {
            string    valueAsStr = "345";
            InputLine line       = MakeInputLine(intVar.Name + " " + valueAsStr);

            Assert.IsFalse(line.ReadOptionalVar(strVar));

            line.ReadVar(intVar);
            Assert.AreEqual(345, intVar.Value.Actual);
            Assert.AreEqual(valueAsStr, intVar.Value.String);
            AssertNoMoreLines(line);
        }
        //---------------------------------------------------------------------

        private void ReadStrVar_Quoted(string valueAsStr,
                                       string quotedValue)
        {
            string    lineAsStr = strVar.Name + " " + quotedValue;
            InputLine line      = MakeInputLine(lineAsStr);

            Assert.AreEqual(lineAsStr, line.ToString());

            line.ReadVar(strVar);
            Assert.AreEqual(valueAsStr, strVar.Value.Actual);
            Assert.AreEqual(quotedValue, strVar.Value.String);
            AssertNoMoreLines(line);
        }