Пример #1
0
        public void ToStringShouldWork(double value, string expected)
        {
            var original = new JoulesEnergy(value);
            var actual = original.ToString();

            Assert.That(actual, Is.EqualTo(expected));
        }
Пример #2
0
        public void ItShouldReturnItselfForJoules()
        {
            var original = new JoulesEnergy(0);
            var conversion = original.Joules;

            Assert.That(original, Is.SameAs(conversion));
        }
Пример #3
0
        public void ItShouldConvertToKilowattHoursProperly(double before, double after)
        {
            var original = new JoulesEnergy(before);
            var conversion = original.KilowattHours;

            Assert.That(conversion.Value, Is.EqualTo(after).Within(0.001));
        }
Пример #4
0
        public static IEnergy Parse(double value, string type)
        {
            IEnergy result;

            switch (type.ToLower())
            {
            case "j":
            case "joule":
            case "joules":
                result = new JoulesEnergy(value);
                break;

            case "kwh":
            case "kilowatt hour":
            case "kilowatt hours":
                result = new KilowattHoursEnergy(value);
                break;

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

            return(result);
        }
Пример #5
0
        public static IEnergy Parse(double value, string type)
        {
            IEnergy result;

            switch (type.ToLower())
            {
                case "j":
                case "joule":
                case "joules":
                    result = new JoulesEnergy(value);
                    break;

                case "kwh":
                case "kilowatt hour":
                case "kilowatt hours":
                    result = new KilowattHoursEnergy(value);
                    break;

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

            return result;
        }