Пример #1
0
        public void Celsius_To_Fahrenheit()
        {
            double toConvert      = 20;
            double convertedValue = TemperatureHelper.CelsiusToFahrenheit(toConvert);

            Assert.Equal(68, convertedValue);
        }
Пример #2
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);
        }
Пример #3
0
        public void Celsius_To_Fahrenheit_Correct()
        {
            // Arrange
            double celsius = 18;

            // Act
            double result        = TemperatureHelper.CelsiusToFahrenheit(celsius);
            double resultRounded = TemperatureHelper.CelsiusToFahrenheit(celsius, 0);

            // Assert
            Assert.Equal(64.4, result);
            Assert.Equal(64, resultRounded);
        }