/// <summary> /// Converts the Int input to the correct int 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 int To <TInput>(this IntBase input) where TInput : TemperatureBase { return(typeof(TInput).Name switch { nameof(Celsius) when input is CelsiusInt castInput => IntParser(CelsiusConverter.CelsiusToCelsius(castInput.Temperature)), nameof(Celsius) when input is FahrenheitInt castInput => IntParser(FahrenheitConverter.FahrenheitToCelsius(castInput.Temperature)), nameof(Celsius) when input is KelvinInt castInput => IntParser(KelvinConverter.KelvinToCelsius(castInput.Temperature)), nameof(Celsius) when input is GasInt castInput => IntParser(GasConverter.GasToCelsius(castInput.Temperature)), nameof(Celsius) when input is RankineInt castInput => IntParser(RankineConverter.RankineToCelsius(castInput.Temperature)), nameof(Fahrenheit) when input is CelsiusInt castInput => IntParser(CelsiusConverter.CelsiusToFahrenheit(castInput.Temperature)), nameof(Fahrenheit) when input is FahrenheitInt castInput => IntParser(FahrenheitConverter.FahrenheitToFahrenheit(castInput.Temperature)), nameof(Fahrenheit) when input is KelvinInt castInput => IntParser(KelvinConverter.KelvinToFahrenheit(castInput.Temperature)), nameof(Fahrenheit) when input is GasInt castInput => IntParser(GasConverter.GasToFahrenheit(castInput.Temperature)), nameof(Fahrenheit) when input is RankineInt castInput => IntParser(RankineConverter.RankineToFahrenheit(castInput.Temperature)), nameof(Kelvin) when input is CelsiusInt castInput => IntParser(CelsiusConverter.CelsiusToKelvin(castInput.Temperature)), nameof(Kelvin) when input is FahrenheitInt castInput => IntParser(FahrenheitConverter.FahrenheitToKelvin(castInput.Temperature)), nameof(Kelvin) when input is KelvinInt castInput => IntParser(KelvinConverter.KelvinToKelvin(castInput.Temperature)), nameof(Kelvin) when input is GasInt castInput => IntParser(GasConverter.GasToKelvin(castInput.Temperature)), nameof(Kelvin) when input is RankineInt castInput => IntParser(RankineConverter.RankineToKelvin(castInput.Temperature)), nameof(Gas) when input is CelsiusInt castInput => IntParser(CelsiusConverter.CelsiusToGas(castInput.Temperature)), nameof(Gas) when input is FahrenheitInt castInput => IntParser(FahrenheitConverter.FahrenheitToGas(castInput.Temperature)), nameof(Gas) when input is KelvinInt castInput => IntParser(KelvinConverter.KelvinToGas(castInput.Temperature)), nameof(Gas) when input is GasInt castInput => IntParser(GasConverter.GasToGas(castInput.Temperature)), nameof(Gas) when input is RankineInt castInput => IntParser(RankineConverter.RankineToGas(castInput.Temperature)), nameof(Rankine) when input is CelsiusInt castInput => IntParser(CelsiusConverter.CelsiusToRankine(castInput.Temperature)), nameof(Rankine) when input is FahrenheitInt castInput => IntParser(FahrenheitConverter.FahrenheitToRankine(castInput.Temperature)), nameof(Rankine) when input is KelvinInt castInput => IntParser(KelvinConverter.KelvinToRankine(castInput.Temperature)), nameof(Rankine) when input is GasInt castInput => IntParser(GasConverter.GasToRankine(castInput.Temperature)), nameof(Rankine) when input is RankineInt castInput => IntParser(RankineConverter.RankineToRankine(castInput.Temperature)), _ => throw new ArgumentException($"Invalid type: {typeof(TInput).Name}") });
public void Test_to_rankine_generic_from_rankine_returns_same_value() { // Arrange. var input = new RankineInt(862); // Act. var result = input.To <Rankine>(); // Assert. result.Should().Be(input.Temperature); }
public void Test_to_kelvin_generic_from_rankine_returns_correct_value() { // Arrange. const int expected = 479; var input = new RankineInt(862); // Act. var result = input.To <Kelvin>(); // Assert. result.Should().Be(expected); }
public void Test_to_gas_from_rankine_returns_correct_value() { // Arrange. const int expected = 6; var input = new RankineInt(862); // Act. var result = input.ToGas(); // Assert. result.Should().Be(expected); }
public void Test_to_fahrenheit_generic_from_rankine_returns_correct_value() { // Arrange. const int expected = -186; var input = new RankineInt(274); // Act. var result = input.To <Fahrenheit>(); // Assert. result.Should().Be(expected); }
public void Test_to_celsius_from_rankine_returns_correct_value() { // Arrange. const int expected = -121; var input = new RankineInt(274); // Act. var result = input.ToCelsius(); // Assert. result.Should().Be(expected); }
/// <summary> /// Converts the RankineConverter <paramref name="input"/> to Celsius /// </summary> /// <param name="input"> The value to be converted. </param> /// <exception cref="T:System.ArgumentOutOfRangeException"> If calculated value is beyond the limits of the type. </exception> /// <returns> /// The Celsius <see langword="int"/> result. /// </returns> public static int ToCelsius(this RankineInt input) { return(IntParser(RankineConverter.RankineToCelsius(input.Temperature))); }
/// <summary> /// Converts the RankineConverter <paramref name="input"/> to FahrenheitConverter /// </summary> /// <param name="input"> The value to be converted. </param> /// <exception cref="T:System.ArgumentOutOfRangeException">If calculated value is beyond the limits of the type.</exception> /// <returns> /// The FahrenheitConverter <see langword="int"/> result. /// </returns> public static int ToFahrenheit(this RankineInt input) { return(IntParser(RankineConverter.RankineToFahrenheit(input.Temperature))); }