public void Kelvin_To_Celsius()
        {
            double toConvert      = 293.15;
            double convertedValue = TemperatureHelper.KelvinToCelsius(toConvert);

            Assert.Equal(20, convertedValue);
        }
        protected WeatherModel CalculateUnMappableValues(WeatherModel model, int precision, TemperatureUOM temperatureUOM)
        {
            model.TemperatureCelsius    = TemperatureHelper.KelvinToCelsius(model.TemperatureKelvin, precision);
            model.TemperatureFahrenheit = TemperatureHelper.KelvinToFahrenheit(model.TemperatureKelvin, precision);

            switch (temperatureUOM)
            {
            case TemperatureUOM.Celsius:
                model.Temperature = model.TemperatureCelsius;
                break;

            case TemperatureUOM.Fahrenheit:
                model.Temperature = model.TemperatureFahrenheit;
                break;

            case TemperatureUOM.Kelvin:
                model.Temperature = model.TemperatureKelvin;
                break;

            default:
                model.Temperature = model.TemperatureCelsius;
                break;
            }

            DateTime sunrise = model.SunRiseMilliseconds.ConvertFromUnixTimestamp();
            DateTime sunset  = model.SunSetMilliSeconds.ConvertFromUnixTimestamp();

            model.SunRise = sunrise.ToString("HH:mm");
            model.SunSet  = sunset.ToString("HH:mm");

            return(model);
        }
Example #3
0
        public double ConvertTemperature(TemperatureUom targetUom)
        {
            double result = 0;

            switch (TemperatureUom)
            {
            case TemperatureUom.Kelvin:
                if (targetUom == TemperatureUom.Celsius)
                {
                    result = TemperatureHelper.KelvinToCelsius(Temperature);
                }
                else if (targetUom == TemperatureUom.Fahrenheit)
                {
                    result = TemperatureHelper.KelvinToFahrenheit(Temperature);
                }
                else
                {
                    result = Temperature;
                }
                break;

            case TemperatureUom.Fahrenheit:
                if (targetUom == TemperatureUom.Celsius)
                {
                    result = TemperatureHelper.FahrenheitToCelsius(Temperature);
                }
                else if (targetUom == TemperatureUom.Kelvin)
                {
                    result = TemperatureHelper.FahrenheitToKelvin(Temperature);
                }
                else
                {
                    result = Temperature;
                }
                break;

            case TemperatureUom.Celsius:
                if (targetUom == TemperatureUom.Kelvin)
                {
                    result = TemperatureHelper.CelsiusToKelvin(Temperature);
                }
                else if (targetUom == TemperatureUom.Fahrenheit)
                {
                    result = TemperatureHelper.CelsiusToFahrenheit(Temperature);
                }
                else
                {
                    result = Temperature;
                }
                break;
            }

            Temperature    = result;
            TemperatureUom = targetUom;

            return(result);
        }
        public void Kelvin_To_Celsius_Correct()
        {
            // Arrange
            double kelvin = 290;

            // Act
            double result        = TemperatureHelper.KelvinToCelsius(kelvin);
            double resultRounded = TemperatureHelper.KelvinToCelsius(kelvin, 0);

            // Assert
            Assert.Equal(16.85, result);
            Assert.Equal(17, resultRounded);
        }