/// <summary> /// Converts the float input to the correct float value. /// </summary> /// <typeparam name="TInput"> The temperature type to be converted to. </typeparam> /// <param name="input"> The value to be converted. </param> /// <exception cref="ArgumentException"> The TInput type is not a valid type for this method. </exception> /// <returns> /// The result of the conversion. /// </returns> public static float To <TInput>(this FloatBase input) where TInput : TemperatureBase { return(typeof(TInput).Name switch { nameof(Celsius) when input is CelsiusFloat castInput => FloatParser(CelsiusConverter.CelsiusToCelsius(castInput.Temperature)), nameof(Celsius) when input is FahrenheitFloat castInput => FloatParser(FahrenheitConverter.FahrenheitToCelsius(castInput.Temperature)), nameof(Celsius) when input is KelvinFloat castInput => (float)Math.Round(FloatParser(KelvinConverter.KelvinToCelsius(castInput.Temperature)), 2), nameof(Celsius) when input is GasFloat castInput => FloatParser(GasConverter.GasToCelsius(castInput.Temperature)), nameof(Celsius) when input is RankineFloat castInput => (float)Math.Round(FloatParser(RankineConverter.RankineToCelsius(castInput.Temperature)), 2), nameof(Fahrenheit) when input is CelsiusFloat castInput => FloatParser(CelsiusConverter.CelsiusToFahrenheit(castInput.Temperature)), nameof(Fahrenheit) when input is FahrenheitFloat castInput => FloatParser(FahrenheitConverter.FahrenheitToFahrenheit(castInput.Temperature)), nameof(Fahrenheit) when input is KelvinFloat castInput => (float)Math.Round(FloatParser(KelvinConverter.KelvinToFahrenheit(castInput.Temperature)), 2), nameof(Fahrenheit) when input is GasFloat castInput => FloatParser(GasConverter.GasToFahrenheit(castInput.Temperature)), nameof(Fahrenheit) when input is RankineFloat castInput => FloatParser(RankineConverter.RankineToFahrenheit(castInput.Temperature)), nameof(Kelvin) when input is CelsiusFloat castInput => FloatParser(CelsiusConverter.CelsiusToKelvin(castInput.Temperature)), nameof(Kelvin) when input is FahrenheitFloat castInput => FloatParser(FahrenheitConverter.FahrenheitToKelvin(castInput.Temperature)), nameof(Kelvin) when input is KelvinFloat castInput => FloatParser(KelvinConverter.KelvinToKelvin(castInput.Temperature)), nameof(Kelvin) when input is GasFloat castInput => FloatParser(GasConverter.GasToKelvin(castInput.Temperature)), nameof(Kelvin) when input is RankineFloat castInput => FloatParser(RankineConverter.RankineToKelvin(castInput.Temperature)), nameof(Gas) when input is CelsiusFloat castInput => FloatParser(CelsiusConverter.CelsiusToGas(castInput.Temperature)), nameof(Gas) when input is FahrenheitFloat castInput => FloatParser(FahrenheitConverter.FahrenheitToGas(castInput.Temperature)), nameof(Gas) when input is KelvinFloat castInput => FloatParser(KelvinConverter.KelvinToGas(castInput.Temperature)), nameof(Gas) when input is GasFloat castInput => FloatParser(GasConverter.GasToGas(castInput.Temperature)), nameof(Gas) when input is RankineFloat castInput => FloatParser(RankineConverter.RankineToGas(castInput.Temperature)), nameof(Rankine) when input is CelsiusFloat castInput => FloatParser(CelsiusConverter.CelsiusToRankine(castInput.Temperature)), nameof(Rankine) when input is FahrenheitFloat castInput => FloatParser(FahrenheitConverter.FahrenheitToRankine(castInput.Temperature)), nameof(Rankine) when input is KelvinFloat castInput => FloatParser(KelvinConverter.KelvinToRankine(castInput.Temperature)), nameof(Rankine) when input is GasFloat castInput => FloatParser(GasConverter.GasToRankine(castInput.Temperature)), nameof(Rankine) when input is RankineFloat castInput => FloatParser(RankineConverter.RankineToRankine(castInput.Temperature)), _ => throw new ArgumentException($"Invalid type: {typeof(TInput).Name}") });
public void Test_to_fahrenheit_generic_from_fahrenheit_returns_correct_value() { // Arrange. var input = new FahrenheitFloat(50.456f); // Act. var result = input.To <Fahrenheit>(); // Assert. result.Should().Be(input.Temperature); }
public void Test_to_rankine_generic_from_fahrenheit_returns_correct_value() { // Arrange. const float expected = 851.6700000000001f; var input = new FahrenheitFloat(392); // Act. var result = input.To <Rankine>(); // Assert. result.Should().Be(expected); }
public void Test_to_kelvin_generic_from_fahrenheit_returns_correct_value() { // Arrange. const float expected = 473.15f; var input = new FahrenheitFloat(392); // Act. var result = input.To <Kelvin>(); // Assert. result.Should().Be(expected); }
public void Test_to_celsius_generic_from_fahrenheit_returns_correct_value() { // Arrange. const float expected = 10f; var input = new FahrenheitFloat(50.0f); // Act. var result = input.To <Celsius>(); // Assert. result.Should().Be(expected); }
public void Test_to_gas_from_fahrenheit_returns_correct_value() { // Arrange. const float expected = 6f; var input = new FahrenheitFloat(392); // Act. var result = input.ToGas(); // Assert. result.Should().Be(expected); }
/// <summary> /// Converts the FahrenheitConverter <paramref name="input"/> to FahrenheitConverter /// </summary> /// <param name="input"> The value to be converted. </param> /// <returns> /// The FahrenheitConverter <see langword="float"/> result. /// </returns> public static float ToFahrenheit(this FahrenheitFloat input) { return(FloatParser(FahrenheitConverter.FahrenheitToFahrenheit(input.Temperature))); }