public static T TemperatureConvert <T>(this ITemperature current)
            where T : ITemperature, new()
        {
            T obj = new T();

            // if conversion of same types
            if (current.GetType() == typeof(T))
            {
                obj.Value = current.Value;
            }


            // converting to kelvin
            if (obj.GetType() == typeof(Kelvin))
            {
                obj.Value = current.GetType() == typeof(Celsius) ? current.Value + 273.15 : (current.Value + 459.67) * (5.0 / 9.0);
            }

            // converting to Celcius
            if (obj.GetType() == typeof(Celsius))
            {
                obj.Value = current.GetType() == typeof(Kelvin) ? current.Value - 273.15 : (current.Value - 32) * (5.0 / 9.0);
            }

            if (obj.GetType() == typeof(Fahrenheit))
            {
                obj.Value = current.GetType() == typeof(Kelvin) ? ((current.Value * (9.0 / 5.0)) - 459.67) : (current.Value * (9.0 / 5.0) + 32);
            }

            // Automatically round to 2 precicision points
            obj.Value = Math.Round(obj.Value, 2);

            return(obj);
        }
Example #2
0
        public static void AssertTemperatureEqual(ITemperature one, ITemperature two)
        {
            if (one == null && two == null)
            {
                return;
            }

            AssertHelperHelper(one, two);

            Assert.That(one.GetType(), Is.EqualTo(two.GetType()));
            Assert.That(one.Value, Is.EqualTo(two.Value));
        }