public void FindMonthWithColdestMaxTemperature()
        {
            var expected = new MonthlyStationData(1948, 2, 7.9, 2.2, null, 26.0, null, null, false);
            var actual = sampleMonthlyData.MonthWithColdestMaxTemperature;

            Expect(actual, Is.EqualTo(expected));
        }
        public void FindHottestMaxTemperature()
        {
            var expected = new MonthlyStationData(2005, 7, 23.3, 14.1, 0, 45.8, 202.5, true, false);
            var actual = sampleMonthlyData.HottestMonth;

            Expect(actual, Is.EqualTo(expected));
        }
        public void FindColdestMinTemperatureAvoidNulls()
        {
            sampleMonthlyData.Add(new MonthlyStationData(1947, 2, 7.9, null, null, 26.0, null, null, false));

            var expected = new MonthlyStationData(1948, 2, 7.9, 2.2, null, 26.0, null, null, false);
            var actual = sampleMonthlyData.ColdestMonth;

            Expect(actual, Is.EqualTo(expected));
        }
        public static bool ParseDataLine(string line, ref MonthlyStationData monthlyStationData)
        {
            if (String.IsNullOrWhiteSpace(line))
            {
                return false;
            }

            char[] delimiters = { ' ' };

            var parts = line.Trim().Split(delimiters, StringSplitOptions.RemoveEmptyEntries);

            var i = 0;
            var yearPart = parts.Length > i ? parts[i++] : "";
            var monthPart = parts.Length > i ? parts[i++] : "";
            var maxTemperaturePart = parts.Length > i ? parts[i++] : "";
            var minTemperaturePart = parts.Length > i ? parts[i++] : "";
            var airFrostPart = parts.Length > i ? parts[i++] : "";
            var rainPart = parts.Length > i ? parts[i++] : "";
            var sunshinePart = parts.Length > i ? parts[i++] : "";
            var provisionalPart = parts.Length > i ? parts[i++] : "";

            int year, month;
            if (int.TryParse(yearPart, out year) && int.TryParse(monthPart, out month))
            {
                double? maxTemperature = PartToNullableDouble(maxTemperaturePart);
                double? minTemperature = PartToNullableDouble(minTemperaturePart);

                int? airFrost = null;
                if (!DatumIsMissing(airFrostPart))
                {
                    int airFrostValue;
                    if (int.TryParse(airFrostPart, out airFrostValue))
                    {
                        airFrost = airFrostValue;
                    }
                }

                double? rain = PartToNullableDouble(rainPart);

                double? sunshine = null;
                bool? campbellStokes = null;
                if (!DatumIsMissing(sunshinePart))
                {
                    if (sunshinePart.EndsWith("#"))
                    {
                        campbellStokes = false;
                        sunshinePart = sunshinePart.Remove(sunshinePart.IndexOf('#'));
                    }
                    else
                    {
                        campbellStokes = true;
                    }

                    sunshine = PartToNullableDouble(sunshinePart);
                }

                var provisional = provisionalPart == "Provisional";

                monthlyStationData = new MonthlyStationData(year, month, maxTemperature, minTemperature,
                    airFrost, rain, sunshine, campbellStokes, provisional);

                return true;
            }

            return false;
        }
        public void ParseDataLineWithProvisional()
        {
            var expected = new MonthlyStationData(2013, 5, 16.4, 7.7, 0, 41.8, 163.3, false, true);
            var line = "   2013   5   16.4     7.7       0    41.8   163.3#  Provisional";

            MonthlyStationData actual = null;
            if (StationDataFile.ParseDataLine(line, ref actual))
            {
                Expect(actual, Is.EqualTo(expected));
            }
        }
        public void ParseDataLineWithNulls()
        {
            var expected = new MonthlyStationData(1948, 2, 7.9, 2.2, null, 26.0, null, null, false);
            var line = "   1948   2    7.9     2.2    ---     26.0    ---";

            MonthlyStationData actual = null;
            if (StationDataFile.ParseDataLine(line, ref actual))
            {
                Expect(actual, Is.EqualTo(expected));
            }
        }
        public void ParseDataLineWithKippAndZonen()
        {
            var line = "   2012  12    9.0     2.6      10    95.8    58.0#";
            var expected = new MonthlyStationData(2012, 12, 9.0, 2.6, 10, 95.8, 58.0, false, false);

            MonthlyStationData actual = null;
            if (StationDataFile.ParseDataLine(line, ref actual))
            {
                Expect(actual, Is.EqualTo(expected));
            }
        }
        public void ParseDataLine()
        {
            var expected = new MonthlyStationData(2005, 7, 23.3, 14.1, 0, 45.8, 202.5, true, false);
            var line = "   2005   7   23.3    14.1       0    45.8   202.5";

            MonthlyStationData actual = null;
            if (StationDataFile.ParseDataLine(line, ref actual))
            {
                Expect(actual, Is.EqualTo(expected));
            }
        }
        public void FindMonthWithHottestMinTemperatureAvoidNulls()
        {
            sampleMonthlyData.Add(new MonthlyStationData(1947, 7, 23.3, null, 0, 45.8, 202.5, true, false));

            var expected = new MonthlyStationData(2005, 7, 23.3, 14.1, 0, 45.8, 202.5, true, false);
            var actual = sampleMonthlyData.MonthWithHottestMinTemperature;

            Expect(actual, Is.EqualTo(expected));
        }