Exemplo n.º 1
0
        public void ThenTheSmallestTemperatureSpreadIsOnDay(string expectedDay)
        {
            var parsedResults = scenarioContext.Get <IEnumerable <DailyWeatherData> >("ParsedResults");
            var actualDay     = TemperatureParser.GetDayWithMinTemperatureSpread(parsedResults);

            actualDay.Should().Be(expectedDay);
        }
Exemplo n.º 2
0
        public void ParsingProperlyCleansLine()
        {
            var actualResult   = TemperatureParser.ParseRow(weatherProfile, data[3]);
            var expectedResult = makeWeatherData(9, 86, 32);

            actualResult.Should().BeEquivalentTo(expectedResult);
        }
Exemplo n.º 3
0
        public void TestGetThirdLine()
        {
            var actualResult   = TemperatureParser.ParseRow(weatherProfile, data[4]);
            var expectedResult = makeWeatherData(12, 88, 73);

            actualResult.Should().BeEquivalentTo(expectedResult);
        }
Exemplo n.º 4
0
        public void FromEmptyWeatherInfo()
        {
            var parser                = new TemperatureParser();
            var weatherlist           = new List <string>();
            var weatherInfoCollection = parser.GetWeatherInfoCollection("emptyTestList", weatherlist);

            Assert.AreEqual(weatherInfoCollection.Count, 0);
        }
Exemplo n.º 5
0
        public void WhenTheFileIsParsed()
        {
            var fileText       = scenarioContext.Get <string>("fileText");
            var parsingProfile = ParsingProfileFactory.Create(fileText);
            var results        = TemperatureParser.ParseFile(parsingProfile);

            scenarioContext.Add("ParsedResults", results);
        }
Exemplo n.º 6
0
        public void SetUp()
        {
            _stream = Substitute.For <Stream>();
            SetUpStreamReader();

            _streamReaderProvider = Substitute.For <Func <Stream, StreamReader> >();
            _streamReaderProvider(_stream).Returns(_streamReader);

            _sut = new TemperatureParser(_streamReaderProvider);
        }
Exemplo n.º 7
0
        public string Get()
        {
            var fileName       = @"C:\Users\jallen\Downloads\football.dat";
            var contents       = System.IO.File.ReadAllText(fileName);
            var parsingProfile = ParsingProfileFactory.Create(contents);
            var parsedRows     = TemperatureParser.ParseFile(parsingProfile);
            var day            = TemperatureParser.GetDayWithMinTemperatureSpread(parsedRows);

            return(day);
        }
Exemplo n.º 8
0
        public void FromManyWeatherInfoMixedPrecipitationContainingDuplicates()
        {
            var parser      = new TemperatureParser();
            var weatherlist = new List <string>()
            {
                "12/25/2017,200,-200", "12/25/2017,200,-200", "12/25/2017,200,-200,1.1"
            };
            var weatherInfoCollection = parser.GetWeatherInfoCollection("manyDuplicateTestList", weatherlist);

            Assert.AreEqual(weatherInfoCollection.Count, 3);
        }
Exemplo n.º 9
0
        public void FromSingleWeatherInfoNoPrecipitationCorruptLowTemp()
        {
            var parser      = new TemperatureParser();
            var weatherlist = new List <string>()
            {
                "12/25/2017,200,-2{corrupt}00"
            };
            var weatherInfoCollection = parser.GetWeatherInfoCollection("singleTestList", weatherlist);

            Assert.AreEqual(weatherInfoCollection.Count, 0);
        }
Exemplo n.º 10
0
        public void FromSingleWeatherInfoWithPrecipitation()
        {
            var parser      = new TemperatureParser();
            var weatherlist = new List <string>()
            {
                "12/25/2017,200,-200,1.1"
            };
            var weatherInfoCollection = parser.GetWeatherInfoCollection("singleTestList", weatherlist);

            Assert.AreEqual(weatherInfoCollection.Count, 1);
        }
Exemplo n.º 11
0
 public void TestLastLine()
 {
     try
     {
         var actualResult = TemperatureParser.ParseRow(weatherProfile, data.Last());
         Assert.Fail();
     }
     catch
     {
         Assert.Pass();
     }
 }
Exemplo n.º 12
0
        public void FromManyWeatherInfoWithPrecipitationMultiCorrupt()
        {
            var parser      = new TemperatureParser();
            var weatherlist = new List <string>()
            {
                "12/{corrupt}25/2017,200,-200,1.1", "12/26/2017,20{corrupt}0,-200,1.1", "12/27/2017,200,-2{corrupt}00,1.1", "12/27/2017,200,-200,1.{corrupt}1"
            }
            ;
            var weatherInfoCollection = parser.GetWeatherInfoCollection("manyWeatherMultiCorruptionTestList", weatherlist);

            Assert.AreEqual(weatherInfoCollection.Count, 0);
        }
Exemplo n.º 13
0
        public void FromManyWeatherInfoSinglePrecipitationLast()
        {
            var parser      = new TemperatureParser();
            var weatherlist = new List <string>()
            {
                "12/25/2017,200,-200", "12/26/2017,200,-200", "12/27/2017,200,-200,1.1"
            }
            ;
            var weatherInfoCollection = parser.GetWeatherInfoCollection("manyTestList", weatherlist);

            Assert.AreEqual(weatherInfoCollection.Count, 3);
        }
Exemplo n.º 14
0
        public void FromManyWeatherInfoWithoutPrecipitationSingleCorrupt()
        {
            var parser      = new TemperatureParser();
            var weatherlist = new List <string>()
            {
                "12/25/2017,20{corrupt}0,-200", "12/26/2017,200,-200", "12/27/2017,200,-200"
            }
            ;
            var weatherInfoCollection = parser.GetWeatherInfoCollection("manyWeatherSingleCorruptionTestList", weatherlist);

            Assert.AreEqual(weatherInfoCollection.Count, 2);
        }
        private async Task <WeatherInfoCollection> getData()
        {
            if (this.ImportDialog.File.FileType == "xml")
            {
                this.NewWeatherInfoCollection = await XMLSerializer.ReadWeatherCollection(this.ImportDialog.File);
            }
            else
            {
                var fileReader = new FileLineGenerator();

                var lines = await fileReader.GetFileLines(this.ImportDialog.File);

                var weatherDataParser = new TemperatureParser();
                this.NewWeatherInfoCollection =
                    weatherDataParser.GetWeatherInfoCollection(this.ImportDialog.CollectionName, lines);
                this.ErrorMessageList = weatherDataParser.ErrorMessages.ToList();
            }
            return(this.NewWeatherInfoCollection);
        }
Exemplo n.º 16
0
        public static TMeasurement Parse <TMeasurement>(double value, string type)
            where TMeasurement : IMeasurement
        {
            var runtimeType = typeof(TMeasurement);

            if (runtimeType == typeof(IEnergy))
            {
                return((TMeasurement)EnergyParser.Parse(value, type));
            }

            if (runtimeType == typeof(IPower))
            {
                return((TMeasurement)PowerParser.Parse(value, type));
            }

            if (runtimeType == typeof(IRatio))
            {
                return((TMeasurement)RatioParser.Parse(value, type));
            }

            if (runtimeType == typeof(ITemperature))
            {
                return((TMeasurement)TemperatureParser.Parse(value, type));
            }

            if (runtimeType == typeof(IHumidity))
            {
                return((TMeasurement)HumidityParser.Parse(value, type));
            }

            if (runtimeType == typeof(IIlluminance))
            {
                return((TMeasurement)IlluminanceParser.Parse(value, type));
            }

            if (runtimeType == typeof(IMeasurement))
            {
                return((TMeasurement)(IMeasurement) new ReadOnlyMeasurement(value, type));
            }

            throw new Exception("Could not determine type " + runtimeType.Name);
        }
Exemplo n.º 17
0
        public override ITemperature GetValue()
        {
            var dataEntry = GetDataEntry();

            if (dataEntry == null)
            {
                return(null);
            }

            var number = dataEntry.DecimalValue ?? 0;
            var units  = dataEntry.Units;

            if (number == 0 && units == string.Empty)
            {
                return(null);
            }

            var result = TemperatureParser.Parse((double)number, units);

            return(result);
        }
Exemplo n.º 18
0
 public static ITemperature ToTemperature(this IParameter parameter)
 {
     return(TemperatureParser.Parse(parameter.Value));
 }
Exemplo n.º 19
0
        public void ItAcceptsWellFormedTemperatures(string input)
        {
            var result = TemperatureParser.IsTemperature(input);

            Assert.That(result, Is.True);
        }
Exemplo n.º 20
0
        public void ItRejectsPoorlyFormedTemperatures(string input)
        {
            var result = TemperatureParser.IsTemperature(input);

            Assert.That(result, Is.False);
        }
Exemplo n.º 21
0
 public void ItDoesNotThrowAnExceptionWhenParsingValidTemperatures(string input)
 {
     TemperatureParser.Parse(input);
 }
Exemplo n.º 22
0
 public void ItThrowsAnExceptionWhenParsingInvalidTemperatures(string input)
 {
     TemperatureParser.Parse(input);
 }
Exemplo n.º 23
0
        public void ItParsesTheValueProperly(string input, double expected)
        {
            var result = TemperatureParser.Parse(input);

            Assert.That(result.Value, Is.EqualTo(expected));
        }
Exemplo n.º 24
0
        public void ItParsesTheTypeProperly(string input, Type type)
        {
            var result = TemperatureParser.Parse(input);

            Assert.That(result.GetType(), Is.EqualTo(type));
        }
Exemplo n.º 25
0
        public override void Execute()
        {
            bool   calculateWindChill = false;
            double windSpeed          = 0.0;

            //Tell the user which options are available.
            Output.Add("--------------------------------------------------------------");
            Output.Add("Temperatuur types: F (Farhenheit), C (Celsius), K (Kelvin).");
            Output.Add("Zet de letter achter het nummer, hoofdletters maakt niet uit.");
            Output.Add("--------------------------------------------------------------");

            //Ask the user which value he wants to use for the conversion
            AssignmentHelper.RequestInput(
                this,
                "Voer de temperatuur in die je wilt gebruiken. (bijv. 20.0C of 25.6F)",
                out string inputString
                );

            bool parsed = TemperatureParser.Parse(inputString, out TemperatureUnit inputUnit, out double inputValue);

            if (!parsed)
            {
                Error = $"Kan waarde `{inputString}` niet conventeren naar een double.";
                return;
            }

            if (inputUnit == TemperatureUnit.Unknown)
            {
                Error = $"Onbekende temperatuur type!";
                return;
            }

            // Ask the user which type he wants to convert to.
            bool targetUnitSuccess = AssignmentHelper.RequestInput(
                this,
                "Naar welk temperatuur type wil je het conveteren (F/C/K)?",
                out char targeUnitResult
                );

            if (!targetUnitSuccess)
            {
                Error = "Kan input niet converteren naar goede type.";
                return;
            }

            TemperatureUnit targetUnit = (TemperatureUnit)targeUnitResult;

            if (inputUnit.Equals(targetUnit))
            {
                Error = $"De conversie is het zelfde (van {inputUnit} naar {targetUnit})";
                return;
            }

            ConsoleKey key = AssignmentHelper.RequestKey(
                "Wil je ook het gevoelstemperatuur berekenen?",
                new[] { ConsoleKey.Y, ConsoleKey.N }
                );

            if (key == ConsoleKey.Y)
            {
                AssignmentHelper.RequestInput <double>(
                    this,
                    "Wat is de wind snelheid in kilometer per seconde?",
                    out windSpeed
                    );

                calculateWindChill = true;
            }
            else if (key == ConsoleKey.N)
            {
                calculateWindChill = false;
            }
            else
            {
                Error = "De ingevoerde toets is incorrect.";
                return;
            }

            //Lookup conversion, print result
            double result        = TemperatureConverter.Convert(inputValue, inputUnit, targetUnit);
            double resultRounded = Math.Round(result, 2);

            StringBuilder builder = new StringBuilder();

            builder.AppendLine("");
            builder.AppendLine($"Het gegeven temperatuur was {inputValue} {inputUnit}, omgezet is het resultaat: {result} {targetUnit}");
            builder.AppendLine("");

            //Append the results of the wind chill calculations.
            if (calculateWindChill)
            {
                double resultWindChill        = TemperatureConverter.ConvertInclWindChill(inputValue, windSpeed, inputUnit, targetUnit);
                double resultWindChillRounded = Math.Round(resultWindChill, 2);

                builder.AppendLine($"Het gevoelstemperatuur met een windsnelheid van {windSpeed} km/h is {resultWindChillRounded} {targetUnit} \n");
            }

            //Write out the entire result.
            Output.Add(builder.ToString());
            Output.Add("Oant moan!");
        }
Exemplo n.º 26
0
 public static bool IsTemperature(this IParameter parameter)
 {
     return(TemperatureParser.IsTemperature(parameter.Value));
 }