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 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 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 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); }
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); } }
public void ConvertsToFahrenheit(int source, int expected) { // Arrange var converter = new TemperatureConverter(); // Act var result = converter.Convert(source, "F"); // Assert Assert.Equal(expected, result); }
public void ConvertsToCelsius_32() { // Arrange var converter = new TemperatureConverter(); // Act var result = converter.Convert(32, "C"); // Assert Assert.Equal(0, result); }
public void Test100FarenheitConvertsTo310Kelvin() { // Arrange var converter = new TemperatureConverter(); var inputvalue = 100; // Act var result = converter.Convert(inputvalue, Temperature.Fahrenheit, Temperature.Kelvin); // Assert Assert.AreEqual(310.928, result, 0.1); }
public void Test100FarenheitConvertsTo37Celcius() { // Arrange var converter = new TemperatureConverter(); var inputvalue = 100; // Act var result = converter.Convert(inputvalue, Temperature.Fahrenheit, Temperature.Celcius); // Assert Assert.AreEqual(37.7778, result, 0.1); }
public void Test800KelvinConvertsTo526Celcius() { // Arrange var converter = new TemperatureConverter(); var inputvalue = 800; // Act var result = converter.Convert(inputvalue, Temperature.Kelvin, Temperature.Celcius); // Assert Assert.AreEqual(526.85, result, 0.1); }
public void Test800KelvinConvertsTo980Farenheit() { // Arrange var converter = new TemperatureConverter(); var inputvalue = 800; // Act var result = converter.Convert(inputvalue, Temperature.Kelvin, Temperature.Fahrenheit); // Assert Assert.AreEqual(980.33, result, 0.1); }
public void Test1CelciusConvertsTo33Point8Farentheit() { // Arrange var converter = new TemperatureConverter(); var inputvalue = 1; // Act var result = converter.Convert(inputvalue, Temperature.Celcius, Temperature.Fahrenheit); // Assert Assert.AreEqual(33.8, result, 0.1); }
public void Test100CelciusConvertsTo373Kelvin() { // Arrange var converter = new TemperatureConverter(); var inputvalue = 100; // Act var result = converter.Convert(inputvalue, Temperature.Celcius, Temperature.Kelvin); // Assert Assert.AreEqual(373.15, result, 0.1); }
public void CelsuisToKelvin(decimal input, decimal expectedResult) { var temp = new Temperature(input, Unit.Celsius); var result = temperatureConverter.Convert(temp, Unit.Kelvin); Assert.Equal(expectedResult, Math.Round(result.Value, 2)); }
public void TemperatureConverter_Convert() { decimal result = TemperatureConverter.Convert(TemperatureUnit.Celsius, TemperatureUnit.Fahrenheit, -40); Assert.AreEqual(-40m, result); result = TemperatureConverter.Convert(TemperatureUnit.Celsius, TemperatureUnit.Fahrenheit, 0); Assert.AreEqual(32m, result); result = TemperatureConverter.Convert(TemperatureUnit.Fahrenheit, TemperatureUnit.Celsius, 212); Assert.AreEqual(100m, result); result = TemperatureConverter.Convert(TemperatureUnit.Fahrenheit, TemperatureUnit.Kelvin, 212); Assert.AreEqual(373.15m, result); }
/// <summary>Convert the numbers to the new unit.</summary> /// <param name="numbers">The numbers used in the convertion.</param> /// <returns>The result of the convertion execution.</returns> /// <exception cref="ArgumentNullException">When numbers is null.</exception> /// <exception cref="ArgumentException">When the length of numbers do not equal <see cref="ArgumentCount"/>.</exception> public double Convert(double[] numbers) { base.Validate(numbers); double fromValue = numbers[0]; switch (current.UnitType) { case UnitType.Length: return(LengthConverter.Convert( (LengthUnit)current.FromUnit, (LengthUnit)current.ToUnit, fromValue)); case UnitType.Mass: return(MassConverter.Convert( (MassUnit)current.FromUnit, (MassUnit)current.ToUnit, fromValue)); case UnitType.Speed: return(SpeedConverter.Convert( (SpeedUnit)current.FromUnit, (SpeedUnit)current.ToUnit, fromValue)); case UnitType.Temperature: return(TemperatureConverter.Convert( (TemperatureUnit)current.FromUnit, (TemperatureUnit)current.ToUnit, fromValue)); case UnitType.Time: return(TimeConverter.Convert( (TimeUnit)current.FromUnit, (TimeUnit)current.ToUnit, fromValue)); case UnitType.Volume: return(VolumeConverter.Convert( (VolumeUnit)current.FromUnit, (VolumeUnit)current.ToUnit, fromValue)); default: throw new ArgumentOutOfRangeException("numbers"); } }
public ActionResult ConvertTemp(float?inputtemp, Temperature inputunit, Temperature outputunit) { if (ModelState.IsValid && inputtemp.HasValue) { var converter = new TemperatureConverter(); var result = converter.Convert(inputtemp.Value, inputunit, outputunit); var con = new UnitConverter.Dto.Convert(); con.outputtemp = result; return(View("Index", con)); } else { return(View("Index")); } }
public void Convert() { double result = TemperatureConverter.Convert( TemperatureUnit.Celsius, TemperatureUnit.Fahrenheit, -40d); Assert.AreEqual(-40, result); result = TemperatureConverter.Convert( TemperatureUnit.Celsius, TemperatureUnit.Fahrenheit, 0); Assert.AreEqual(32, result); result = TemperatureConverter.Convert( TemperatureUnit.Fahrenheit, TemperatureUnit.Celsius, 212); Assert.AreEqual(100, result); result = TemperatureConverter.Convert( TemperatureUnit.Fahrenheit, TemperatureUnit.Kelvin, 212); Assert.AreEqual(373.15, result); }
public ActionResult GetAll(TemperatureType type) { Log.Information("GET Element/GetAll triggered"); var elements = _repo.GetAllElements(); //Map to DTO object var elementDtos = Mapper.Map <List <ElementDto> >(elements); //Recalculate temperature if (type != TemperatureType.Kelvin) { foreach (var element in elementDtos) { element.BoilingTemperature = TemperatureConverter.Convert(element.BoilingTemperature, type); } } return(Json(elementDtos, JsonRequestBehavior.AllowGet)); }
public static void Main() { List <string> result = new List <string>(); while (true) { var inputLine = Console.ReadLine(); if (inputLine == "End") { break; } result.Add(TemperatureConverter.Convert(inputLine)); } foreach (var temperature in result) { Console.WriteLine(temperature); } }
/// <summary>Convert the numbers to the new unit.</summary> /// <param name="numbers">The numbers used in the conversion.</param> /// <returns>The result of the conversion execution.</returns> /// <exception cref="ArgumentNullException">When numbers is null.</exception> /// <exception cref="ArgumentException">When the length of numbers do not equal <see cref="ArgumentCount"/>.</exception> public PreciseNumber Evaluate(PreciseNumber[] operands) { ((IExpression)this).Validate(operands); PreciseNumber fromValue = operands[0]; if (!fromValue.HasValue) { return(fromValue); } return(_current.UnitType switch { UnitType.Length => new PreciseNumber(LengthConverter.Convert((LengthUnit)_current.FromUnit, (LengthUnit)_current.ToUnit, fromValue.Value)), UnitType.Mass => new PreciseNumber(MassConverter.Convert((MassUnit)_current.FromUnit, (MassUnit)_current.ToUnit, fromValue.Value)), UnitType.Speed => new PreciseNumber(SpeedConverter.Convert((SpeedUnit)_current.FromUnit, (SpeedUnit)_current.ToUnit, fromValue.Value)), UnitType.Temperature => new PreciseNumber(TemperatureConverter.Convert((TemperatureUnit)_current.FromUnit, (TemperatureUnit)_current.ToUnit, fromValue.Value)), UnitType.Time => new PreciseNumber(TimeConverter.Convert((TimeUnit)_current.FromUnit, (TimeUnit)_current.ToUnit, fromValue.Value)), UnitType.Volume => new PreciseNumber(VolumeConverter.Convert((VolumeUnit)_current.FromUnit, (VolumeUnit)_current.ToUnit, fromValue.Value)), _ => throw new ArgumentOutOfRangeException(nameof(operands)), });
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 void UnsupportedConversionFromTypeThrowsException() { IConverter temperatureConverter = new TemperatureConverter(); Assert.ThrowsAsync <NotImplementedException>(() => temperatureConverter.Convert(SupportedTypes.Temperature.Unsupported, 2.25, SupportedTypes.Temperature.Celsius)); }
public void InvalidCurrentUnit() { converter.Convert("f", 5, "celsius"); }
public void ConvertMustReturnIConverterResult() { IConverter temperatureConverter = new TemperatureConverter(); Assert.IsAssignableFrom <Task <IConverterResult> >(temperatureConverter.Convert(SupportedTypes.Temperature.Fahrenheit, 2.25, SupportedTypes.Temperature.Celsius)); }
private void Convert(double value) { switch (SelectedOp) { case "Length": { LengthunitConverter unit = new LengthunitConverter(); Result = unit.Convert(value, SelectedFrom, SelectedTo).ToString(); break; } case "Mass and Weight": { MassConverter unit = new MassConverter(); Result = unit.Convert(value, SelectedFrom, SelectedTo).ToString(); break; } case "Power": { PowerConverter unit = new PowerConverter(); Result = unit.Convert(value, SelectedFrom, SelectedTo).ToString(); break; } case "Pressure": { PressureConverter unit = new PressureConverter(); Result = unit.Convert(value, SelectedFrom, SelectedTo).ToString(); break; } case "Energy": { EnergyConveter unit = new EnergyConveter(); Result = unit.Convert(value, SelectedFrom, SelectedTo).ToString(); break; } case "Temperature": { TemperatureConverter unit = new TemperatureConverter(); Result = unit.Convert(value, SelectedFrom, SelectedTo).ToString(); break; } case "Volume": { VolumeConverter unit = new VolumeConverter(); Result = unit.Convert(value, SelectedFrom, SelectedTo).ToString(); break; } case "Angle": { AngleConverter unit = new AngleConverter(); Result = unit.Convert(value, SelectedFrom, SelectedTo).ToString(); break; } case "Area": { AreaConverter unit = new AreaConverter(); Result = unit.Convert(value, SelectedFrom, SelectedTo).ToString(); break; } case "Speed": { SpeedConverter unit = new SpeedConverter(); Result = unit.Convert(value, SelectedFrom, SelectedTo).ToString(); break; } case "Time": { TimeunitsConverter unit = new TimeunitsConverter(); Result = unit.Convert(value, SelectedFrom, SelectedTo).ToString(); break; } } }
public void UnsupportedConversionToTypeThrowsException() { IConverter temperatureConverter = new TemperatureConverter(); Assert.ThrowsAsync <NotImplementedException>(() => temperatureConverter.Convert(SupportedTypes.Temperature.Fahrenheit, 2.25, SupportedTypes.Temperature.Unsupported)); }
public void ConvertToSame() { var value = conv.Convert(12, TemperatureUnits.Celsius, TemperatureUnits.Celsius); Assert.Equal(12, value); }