示例#1
0
        public static ITemperature Parse(double value, string type)
        {
            ITemperature result;

            switch (type.ToLower())
            {
                case "c":
                case "celsius":
                    result = new CelsiusTemperature(value);
                    break;

                case "f":
                case "fahrenheit":
                    result = new FahrenheitTemperature(value);
                    break;

                case "k":
                case "kelvin":
                    result = new KelvinTemperature(value);
                    break;

                default:
                    throw new Exception("Could not determine type " + type);
            }

            return result;
        }
        public void ToStringShouldWork(double value, string expected)
        {
            var fahrenheit = new FahrenheitTemperature(value);
            var actual = fahrenheit.ToString();

            Assert.That(actual, Is.EqualTo(expected));
        }
        public void ItShouldReturnItselfForFahrenheit()
        {
            var fahrenheit = new FahrenheitTemperature(0);
            var newfahrenheit = fahrenheit.Fahrenheit;

            Assert.That(fahrenheit, Is.SameAs(newfahrenheit));
        }
        public void ItShouldConvertToKelvinProperly(double before, double after)
        {
            var fahrenheit = new FahrenheitTemperature(before);
            var kelvin = fahrenheit.Kelvin;

            Assert.That(kelvin.Value, Is.EqualTo(after).Within(0.001));
        }
        public void ItShouldConvertToCelsiustProperly(double before, double after)
        {
            var fahrenheit = new FahrenheitTemperature(before);
            var celsius = fahrenheit.Celsius;

            Assert.That(celsius.Value, Is.EqualTo(after).Within(0.001));
        }
        public void ItAddsCorrectly(double before, double amount, double after)
        {
            var initial = new FahrenheitTemperature(before);
            var result = initial.Add(amount);

            Assert.That(initial, Is.Not.SameAs(result));
            Assert.That(initial.Value, Is.EqualTo(before));
            Assert.That(result.Value, Is.EqualTo(after));
        }