public IActionResult Index(string temperature, char conv) { // Este ejemplo utiliza un mecanismo de validación manual, para ilustrar su funcionamiento // Intentamos convertir la cadena de entrada a un número decimal, si no se puede, // añadimos un mensaje de error y volvemos al formulario decimal temp; try { temp = decimal.Parse(temperature); } catch (Exception) { ModelState.AddModelError("Temperature", "La temperatura introducida no es correcta"); return(View()); } var converter = new TemperatureConverter(); if (conv == 'c') { converter.Celsius = temp; } else { converter.Fahrenheit = temp; } return(View(converter)); }
public void TestKelvinToCelcius() { var temperatureConverter = new TemperatureConverter(); temperatureConverter.SetTemperature(345.15); Assert.AreEqual(72.0, temperatureConverter.KelvinToCelcius()); }
public void TestKelvinToFahrenheit() { var temperatureConverter = new TemperatureConverter(); temperatureConverter.SetTemperature(278.15); Assert.AreEqual(41.0, temperatureConverter.KelvinToFahrenheit()); }
public void TestFahrenheitToKelvin() { var temperatureConverter = new TemperatureConverter(); temperatureConverter.SetTemperature(41.0); Assert.AreEqual(278.15, temperatureConverter.FahrenheitToKelvin()); }
public void TestFahrenheitToCelcius() { var temperatureConverter = new TemperatureConverter(); temperatureConverter.SetTemperature(41.0); Assert.AreEqual(5.0, temperatureConverter.FahrenheitToCelcius()); }
public void TestCelciusToKelvin() { var temperatureConverter = new TemperatureConverter(); temperatureConverter.SetTemperature(10.0); Assert.AreEqual(283.15, temperatureConverter.CelciusToKelvin()); }
public void testSupportedTemperatureConversions(SupportedTypes.Temperature fromType, double fromValue, SupportedTypes.Temperature toType, double expectedResult) { IConverter temperatureConverter = new TemperatureConverter(); Task <IConverterResult> convertResult = temperatureConverter.Convert(fromType, fromValue, toType); Assert.Equal(expectedResult, convertResult.Result.resultValue); }
static void Main() { Console.WriteLine("Please select the convertor direction"); Console.WriteLine("1. From Celsius to Fahrenheit."); Console.WriteLine("2. From Fahrenheit to Celsius."); Console.Write(":"); string selection = Console.ReadLine(); double F = 0, C = 0; switch (selection) { case "1": Console.Write("Please enter the Celsius temperature: "); // F = TemperatureConverter.CelsiusToFahrenheit(Console.ReadLine()); Console.WriteLine("Temperature in Fahrenheit: {0:F2}", F); break; case "2": Console.Write("Please enter the Fahrenheit temperature: "); C = TemperatureConverter.FahrenheitToCelsius(Console.ReadLine()); Console.WriteLine("Temperature in Celsius: {0:F2}", C); break; default: Console.WriteLine("Please select a convertor."); break; } // Keep the console window open in debug mode. Console.WriteLine("Press any key to exit."); Console.ReadKey(); }
static void Main() { Console.WriteLine("Please select the convertor direction"); Console.WriteLine("1. From Celsius to Fahrenheit."); Console.WriteLine("2. From Fahrenheit to Celsius."); Console.Write(":"); string selection = Console.ReadLine(); double F, C = 0; switch (selection) { case "1": Console.Write("Please enter the Celsius temperature: "); F = TemperatureConverter.CelsiusToFahrenheitt(Console.ReadLine()); Console.WriteLine("Temperature in Fahrenheit: {0:F2}", F); break; case "2": Console.Write("Please enter the Fahrenheit temperature: "); Console.WriteLine("Temperature in Celsius: {0:F2}", C); break; default: Console.WriteLine("Please select a convertor."); break; } Console.WriteLine("Press any key to exit."); /* inserted */ int _15 = "2. From Fahrenheit to Celsius."; Console.ReadKey(); }
public void ConvertCtoF_When37C_Expect98Point6() { TemperatureConverter tempConverter = new TemperatureConverter(); double tempInF = tempConverter.ConvertCtoF(37); Assert.AreEqual(98.6, tempInF); }
public void TestCelciusToFahrenheit() { var temperatureConverter = new TemperatureConverter(); temperatureConverter.SetTemperature(12.0); Assert.AreEqual(53.6, temperatureConverter.CelciusToFahrenheit()); }
public void ConvertCtoF_WhenNegative40_ExpectNegative40F() { TemperatureConverter tempConverter = new TemperatureConverter(); double tempInF = tempConverter.ConvertCtoF(-40); Assert.AreEqual(-40, tempInF); }
static void Main(string[] args) { Console.WriteLine("Select the conversion you wish to do."); Console.WriteLine("1. From Celsius to Fahrenheit."); Console.WriteLine("2. from Fahrenheit to Celsius."); string choice = Console.ReadLine(); if (choice == "1") { Console.Write("Please enter the Celsius temperature: "); string value = Console.ReadLine(); bool success = double.TryParse(value, out double celsius); //Could build in some safety for non-numeric values, but that's not the point of this example. Console.WriteLine("Temperature in Fahrenheit: " + TemperatureConverter.CelsiusToFahrenheit(celsius)); } else if (choice == "2") { Console.Write("Please enter the Fahrenheit temperature: "); string value = Console.ReadLine(); bool success = double.TryParse(value, out double fahrenheit); Console.WriteLine("Temperature in Celsius: " + TemperatureConverter.FahrenheitToCelsius(fahrenheit)); } else { Console.WriteLine("Invalid input, bye."); } Console.WriteLine("Press enter to exit."); Console.ReadLine(); }
public object Convert(ConverterType type, object value) { switch (type) { case ConverterType.Temperature: _logger.Debug("Temperature converter started"); return(TemperatureConverter.Convert(value)); case ConverterType.Speed: _logger.Debug("Speed converter started"); return(SpeedConverter.Convert(value)); case ConverterType.DegreeToDirection: _logger.Debug("Degree to direction converter started"); return(DegreeToDirectionConverter.Convert(value)); case ConverterType.Pressure: _logger.Debug("Pressure converter started"); return(PressureConverter.Convert(value)); default: _logger.Error("Unknown converter type"); return(null); } }
protected void ConvertButton_Click(object sender, EventArgs e) { if (IsValid) { int startTemp = int.Parse(StartTempTextBox.Text); int endTemp = int.Parse(EndTempTextBox.Text); int temperaturStep = int.Parse(TemperaturstegTextBox.Text); if (!CelsiusToFahrnheit.Checked) { FirstTableHeaderCell.Text = "°F"; SecondTableHeaderCell.Text = "°C"; } for (int i = startTemp; i <= endTemp; i += temperaturStep) { var tRow = new TableRow(); TemperatureTable.Rows.Add(tRow); var tcell = new TableCell(); tRow.Cells.Add(tcell); tcell.Text = i.ToString(); tcell = new TableCell(); tRow.Cells.Add(tcell); tcell.Text = CelsiusToFahrnheit.Checked ? TemperatureConverter.CelsiusToFahrenheit(i).ToString() : TemperatureConverter.FahrenheitToCelsius(i).ToString(); } TemperatureTable.Visible = true; } }
static void Main() { System.Console.WriteLine("Please select the convertor direction"); System.Console.WriteLine("1. From Celsius to Fahrenheit."); System.Console.WriteLine("2. From Fahrenheit to Celsius."); System.Console.Write(":"); string selection = System.Console.ReadLine(); double F, C = 0; switch (selection) { case "1": System.Console.Write("Please enter the Celsius temperature: "); F = TemperatureConverter.CelsiusToFahrenheit(System.Console.ReadLine()); System.Console.WriteLine("Temperature in Fahrenheit: {0:F2}", F); break; case "2": System.Console.Write("Please enter the Fahrenheit temperature: "); C = TemperatureConverter.FahrenheitToCelsius(System.Console.ReadLine()); System.Console.WriteLine("Temperature in Celsius: {0:F2}", C); break; default: System.Console.WriteLine("Please select a convertor."); break; } //This line waits for user to press key to terminate console Console.ReadLine(); }
private WeatherConditions GetResult(string json, Location location) { var weatherDto = JsonConvert.DeserializeObject <WeatherDto>(json); if (weatherDto == null) { return(null); } var weatherConditions = new WeatherConditions() { Title = weatherDto.Title, Description = weatherDto.Description, TemperatureC = (int)Math.Ceiling(TemperatureConverter.KelvinToCelsius(weatherDto.Main.Temperature)), TemperatureF = (int)Math.Ceiling(TemperatureConverter.KelvinToFahrenheit(weatherDto.Main.Temperature)), Icon = Icons.GetCssClass(weatherDto.IconCode), Location = location.City, CountryCode = location.CountryCode, UsesFahrenheit = location.UsesFahrenheit, Service = "OpenWeatherMap", ServiceUrl = "http://openweathermap.org/" }; return(weatherConditions); }
public static void test() { Console.WriteLine("Please select the convertor direction"); Console.WriteLine("1. From Celsius to Fahrenheit."); Console.WriteLine("2. From Fahrenheit to Celsius."); Console.Write(":"); string selection = Console.ReadLine(); double F, C = 0; switch (selection) { case "1": Console.Write("Please enter the Celsius temperature: "); F = TemperatureConverter.CelsiusToFahrenheit(Console.ReadLine()); Console.WriteLine("Temperature in Fahrenheit: {0:F2}", F); break; case "2": Console.Write("Please enter the Fahrenheit temperature: "); C = TemperatureConverter.FahrenheitToCelsius(Console.ReadLine()); Console.WriteLine("Temperature in Celsius: {0:F2}", C); break; default: Console.WriteLine("Please select a convertor."); break; } }
static void Main(string[] args) { Console.WriteLine("Please Select the converter"); Console.WriteLine("1.Celcius To Faherenheit"); Console.WriteLine("2.Faherenheit To Celcius"); Console.WriteLine(":"); string selection = Console.ReadLine(); double F, C = 0; switch (selection) { case "1": Console.WriteLine("Please enter the celcius temperature"); F = TemperatureConverter.CelciusToFahrenheit(Console.ReadLine()); Console.WriteLine("Temperature in Fahrenheit:" + F); break; case "2": Console.WriteLine("Please enter the faherenheit temperature"); C = TemperatureConverter.FahrenheitToCelcius(Console.ReadLine()); Console.WriteLine("Temperature in Celcius:" + C); break; default: Console.WriteLine("Please select"); break; } }
public void ConvertFromCelsiusToFahrenheitTest() { var converter = new TemperatureConverter(TemperatureUnit.Celsius, TemperatureUnit.Fahrenheit); Assert.AreEqual(32, converter.Convert(0)); Assert.AreEqual(33.8, converter.Convert(1)); Assert.AreEqual(89.6, converter.Convert(32)); Assert.AreEqual(212, converter.Convert(100)); }
public void ConvertCtoF_When100C_Expect212F() { TemperatureConverter tempConverter = new TemperatureConverter(); double tempInF = tempConverter.ConvertCtoF(100); Assert.AreEqual(212, tempInF); //Assert.That(tempInF, isW) }
public void GetCelsiusTemperature_GiveKelvin_GetRoundedCelsiusDouble() { string kelvin = "275"; TemperatureConverter temperatureConverter = new TemperatureConverter(); double result = temperatureConverter.GetCelsiusTemperature(kelvin); Assert.AreEqual(3, result); }
public void ConvertFahrenheitToCelsiusTest() { double fahrenheitTemperature = 212; double expected = 100; double actual = TemperatureConverter.ConvertFahrenheitToCelsius(fahrenheitTemperature); Assert.Equal(expected, actual); }
/// <summary> /// Calcluate the amount of water that needs to be added to raise the mash to a target temperature. /// http://www.mashspargeboil.com/calculating-strike-water-temperature/ /// </summary> /// <returns></returns> private void CalculateInfusion() { float grainAmountKG = GrainAmount / 1000; float boilingWater = TemperatureConverter.ConvertBack(100.0f, null); InfusionAmount = (float)((TargetTemp - WaterTemp) * (0.42 * grainAmountKG + WaterAmount) / (boilingWater - TargetTemp)); RaisePropertyChanged("InfusionAmount"); }
public TemperatureLookupService( WeatherService weatherService, GeoLookupService geoLookupService, TemperatureConverter englishMetricConverter) { _weatherService = weatherService; _geoLookupService = geoLookupService; _temperatureConverter = englishMetricConverter; }
public void Kelvin_Celsius() { converter = new TemperatureConverter("kelvin", "celsius"); double valL = 1; double valR = -272.150; Assert.AreEqual(valR, converter.LeftToRight(valL, 3)); Assert.AreEqual(valL, converter.RightToLeft(valR, 3)); }
public void Fahrenheit_Kelvin() { converter = new TemperatureConverter("fahrenheit", "kelvin"); double valL = 1; double valR = 255.928; Assert.AreEqual(valR, converter.LeftToRight(valL, 3)); Assert.AreEqual(valL, converter.RightToLeft(valR, 3)); }
public void Celsius_Kelvin() { converter = new TemperatureConverter("celsius", "kelvin"); double valL = 1; double valR = 274.150; Assert.AreEqual(valR, converter.LeftToRight(valL, 3)); Assert.AreEqual(valL, converter.RightToLeft(valR, 3)); }
public void Fahrenheit_Celsius_Synonym() { converter = new TemperatureConverter("F", "C"); double valL = 1; double valR = -17.222; Assert.AreEqual(valR, converter.LeftToRight(valL, 3)); Assert.AreEqual(valL, converter.RightToLeft(valR, 3)); }
public void Kelvin_Fahrenheit() { converter = new TemperatureConverter("kelvin", "fahrenheit"); double valL = 1; double valR = -457.87; Assert.AreEqual(valR, converter.LeftToRight(valL, 3)); Assert.AreEqual(valL, converter.RightToLeft(valR, 3)); }
public void Celsius_Fahrenheit() { converter = new TemperatureConverter("celsius", "fahrenheit"); double valL = 1; double valR = 33.800; Assert.AreEqual(valR, converter.LeftToRight(valL, 3)); Assert.AreEqual(valL, converter.RightToLeft(valR, 3)); }
public void ConvertFromFahrenheitToCelsiusTest() { var converter = new TemperatureConverter(TemperatureUnit.Fahrenheit, TemperatureUnit.Celsius); Assert.AreEqual(-17.7777778, converter.Convert(0),0.00000005); Assert.AreEqual(0, converter.Convert(32), 0.0000000001); Assert.AreEqual(1, converter.Convert(33.8),0.0000000001); Assert.AreEqual(32, converter.Convert(89.6), 0.0000000001); Assert.AreEqual(100, converter.Convert(212), 0.0000000001); }
public HomeController() { converter = new TemperatureConverter(); }