public void ThenTheSmallestTemperatureSpreadIsOnDay(string expectedDay) { var parsedResults = scenarioContext.Get <IEnumerable <DailyWeatherData> >("ParsedResults"); var actualDay = TemperatureParser.GetDayWithMinTemperatureSpread(parsedResults); actualDay.Should().Be(expectedDay); }
public void ParsingProperlyCleansLine() { var actualResult = TemperatureParser.ParseRow(weatherProfile, data[3]); var expectedResult = makeWeatherData(9, 86, 32); actualResult.Should().BeEquivalentTo(expectedResult); }
public void TestGetThirdLine() { var actualResult = TemperatureParser.ParseRow(weatherProfile, data[4]); var expectedResult = makeWeatherData(12, 88, 73); actualResult.Should().BeEquivalentTo(expectedResult); }
public void FromEmptyWeatherInfo() { var parser = new TemperatureParser(); var weatherlist = new List <string>(); var weatherInfoCollection = parser.GetWeatherInfoCollection("emptyTestList", weatherlist); Assert.AreEqual(weatherInfoCollection.Count, 0); }
public void WhenTheFileIsParsed() { var fileText = scenarioContext.Get <string>("fileText"); var parsingProfile = ParsingProfileFactory.Create(fileText); var results = TemperatureParser.ParseFile(parsingProfile); scenarioContext.Add("ParsedResults", results); }
public void SetUp() { _stream = Substitute.For <Stream>(); SetUpStreamReader(); _streamReaderProvider = Substitute.For <Func <Stream, StreamReader> >(); _streamReaderProvider(_stream).Returns(_streamReader); _sut = new TemperatureParser(_streamReaderProvider); }
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); }
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); }
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); }
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); }
public void TestLastLine() { try { var actualResult = TemperatureParser.ParseRow(weatherProfile, data.Last()); Assert.Fail(); } catch { Assert.Pass(); } }
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); }
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); }
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); }
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); }
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); }
public static ITemperature ToTemperature(this IParameter parameter) { return(TemperatureParser.Parse(parameter.Value)); }
public void ItAcceptsWellFormedTemperatures(string input) { var result = TemperatureParser.IsTemperature(input); Assert.That(result, Is.True); }
public void ItRejectsPoorlyFormedTemperatures(string input) { var result = TemperatureParser.IsTemperature(input); Assert.That(result, Is.False); }
public void ItDoesNotThrowAnExceptionWhenParsingValidTemperatures(string input) { TemperatureParser.Parse(input); }
public void ItThrowsAnExceptionWhenParsingInvalidTemperatures(string input) { TemperatureParser.Parse(input); }
public void ItParsesTheValueProperly(string input, double expected) { var result = TemperatureParser.Parse(input); Assert.That(result.Value, Is.EqualTo(expected)); }
public void ItParsesTheTypeProperly(string input, Type type) { var result = TemperatureParser.Parse(input); Assert.That(result.GetType(), Is.EqualTo(type)); }
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!"); }
public static bool IsTemperature(this IParameter parameter) { return(TemperatureParser.IsTemperature(parameter.Value)); }