Exemplo n.º 1
0
        public void Equals_RelativeTolerance_IsImplemented()
        {
            var v = FuelEfficiency.FromLitersPer100Kilometers(1);

            Assert.True(v.Equals(FuelEfficiency.FromLitersPer100Kilometers(1), LitersPer100KilometersTolerance, ComparisonType.Relative));
            Assert.False(v.Equals(FuelEfficiency.Zero, LitersPer100KilometersTolerance, ComparisonType.Relative));
        }
Exemplo n.º 2
0
        public void DefaultCtor_ReturnsQuantityWithZeroValueAndBaseUnit()
        {
            var quantity = new FuelEfficiency();

            Assert.Equal(0, quantity.Value);
            Assert.Equal(FuelEfficiencyUnit.LiterPer100Kilometers, quantity.Unit);
        }
Exemplo n.º 3
0
 public void FromValueAndUnit()
 {
     AssertEx.EqualTolerance(1, FuelEfficiency.From(1, FuelEfficiencyUnit.KilometerPerLiter).KilometersPerLiters, KilometersPerLitersTolerance);
     AssertEx.EqualTolerance(1, FuelEfficiency.From(1, FuelEfficiencyUnit.LiterPer100Kilometers).LitersPer100Kilometers, LitersPer100KilometersTolerance);
     AssertEx.EqualTolerance(1, FuelEfficiency.From(1, FuelEfficiencyUnit.MilePerUkGallon).MilesPerUkGallon, MilesPerUkGallonTolerance);
     AssertEx.EqualTolerance(1, FuelEfficiency.From(1, FuelEfficiencyUnit.MilePerUsGallon).MilesPerUsGallon, MilesPerUsGallonTolerance);
 }
Exemplo n.º 4
0
        public void Equals_SameType_IsImplemented()
        {
            var a = FuelEfficiency.FromLitersPer100Kilometers(1);
            var b = FuelEfficiency.FromLitersPer100Kilometers(2);

            Assert.True(a.Equals(a));
            Assert.False(a.Equals(b));
        }
Exemplo n.º 5
0
        public void Ctor_WithInfinityValue_CreateQuantityAndAffectInfinityValue()
        {
            var positiveInfinityQuantity = new FuelEfficiency(double.PositiveInfinity, FuelEfficiencyUnit.LiterPer100Kilometers);
            var negativeInfinityQuantity = new FuelEfficiency(double.NegativeInfinity, FuelEfficiencyUnit.LiterPer100Kilometers);

            Assert.True(double.IsPositiveInfinity(positiveInfinityQuantity.Value));
            Assert.True(double.IsNegativeInfinity(negativeInfinityQuantity.Value));
        }
Exemplo n.º 6
0
        public void FromLitersPer100Kilometers_WithInfinityValue_CreateQuantityAndAffectInfinityValue()
        {
            var positiveInfinityQuantity = FuelEfficiency.FromLitersPer100Kilometers(double.PositiveInfinity);
            var negativeInfinityQuantity = FuelEfficiency.FromLitersPer100Kilometers(double.NegativeInfinity);

            Assert.True(double.IsPositiveInfinity(positiveInfinityQuantity.Value));
            Assert.True(double.IsNegativeInfinity(negativeInfinityQuantity.Value));
        }
Exemplo n.º 7
0
        public void CompareToIsImplemented()
        {
            FuelEfficiency literper100kilometers = FuelEfficiency.FromLitersPer100Kilometers(1);

            Assert.Equal(0, literper100kilometers.CompareTo(literper100kilometers));
            Assert.True(literper100kilometers.CompareTo(FuelEfficiency.Zero) > 0);
            Assert.True(FuelEfficiency.Zero.CompareTo(literper100kilometers) < 0);
        }
Exemplo n.º 8
0
        public void LiterPer100KilometersToFuelEfficiencyUnits()
        {
            FuelEfficiency literper100kilometers = FuelEfficiency.FromLitersPer100Kilometers(1);

            AssertEx.EqualTolerance(KilometersPerLitersInOneLiterPer100Kilometers, literper100kilometers.KilometersPerLiters, KilometersPerLitersTolerance);
            AssertEx.EqualTolerance(LitersPer100KilometersInOneLiterPer100Kilometers, literper100kilometers.LitersPer100Kilometers, LitersPer100KilometersTolerance);
            AssertEx.EqualTolerance(MilesPerUkGallonInOneLiterPer100Kilometers, literper100kilometers.MilesPerUkGallon, MilesPerUkGallonTolerance);
            AssertEx.EqualTolerance(MilesPerUsGallonInOneLiterPer100Kilometers, literper100kilometers.MilesPerUsGallon, MilesPerUsGallonTolerance);
        }
Exemplo n.º 9
0
        public void WhenCalc_PayIsCalled()
        {
            FuelEfficiency f = new FuelEfficiency();

            _scenarioContext.Add("payment", f.calcPay(
                                     _scenarioContext.Get <float>("price"),
                                     _scenarioContext.Get <float>("card")
                                     ));
        }
Exemplo n.º 10
0
        public void WhenCalc_FuelUse()
        {
            FuelEfficiency f = new FuelEfficiency();

            _scenarioContext.Add("stops", f.calc_fuelUse(
                                     _scenarioContext.Get <float>("gallons"),
                                     _scenarioContext.Get <float>("tank"))
                                 );
        }
Exemplo n.º 11
0
        public void Equals_QuantityAsObject_IsImplemented()
        {
            object a = FuelEfficiency.FromLitersPer100Kilometers(1);
            object b = FuelEfficiency.FromLitersPer100Kilometers(2);

            Assert.True(a.Equals(a));
            Assert.False(a.Equals(b));
            Assert.False(a.Equals((object)null));
        }
Exemplo n.º 12
0
        public void As()
        {
            var literper100kilometers = FuelEfficiency.FromLitersPer100Kilometers(1);

            AssertEx.EqualTolerance(KilometersPerLitersInOneLiterPer100Kilometers, literper100kilometers.As(FuelEfficiencyUnit.KilometerPerLiter), KilometersPerLitersTolerance);
            AssertEx.EqualTolerance(LitersPer100KilometersInOneLiterPer100Kilometers, literper100kilometers.As(FuelEfficiencyUnit.LiterPer100Kilometers), LitersPer100KilometersTolerance);
            AssertEx.EqualTolerance(MilesPerUkGallonInOneLiterPer100Kilometers, literper100kilometers.As(FuelEfficiencyUnit.MilePerUkGallon), MilesPerUkGallonTolerance);
            AssertEx.EqualTolerance(MilesPerUsGallonInOneLiterPer100Kilometers, literper100kilometers.As(FuelEfficiencyUnit.MilePerUsGallon), MilesPerUsGallonTolerance);
        }
Exemplo n.º 13
0
        public void ConversionRoundTrip()
        {
            FuelEfficiency literper100kilometers = FuelEfficiency.FromLitersPer100Kilometers(1);

            AssertEx.EqualTolerance(1, FuelEfficiency.FromKilometersPerLiters(literper100kilometers.KilometersPerLiters).LitersPer100Kilometers, KilometersPerLitersTolerance);
            AssertEx.EqualTolerance(1, FuelEfficiency.FromLitersPer100Kilometers(literper100kilometers.LitersPer100Kilometers).LitersPer100Kilometers, LitersPer100KilometersTolerance);
            AssertEx.EqualTolerance(1, FuelEfficiency.FromMilesPerUkGallon(literper100kilometers.MilesPerUkGallon).LitersPer100Kilometers, MilesPerUkGallonTolerance);
            AssertEx.EqualTolerance(1, FuelEfficiency.FromMilesPerUsGallon(literper100kilometers.MilesPerUsGallon).LitersPer100Kilometers, MilesPerUsGallonTolerance);
        }
Exemplo n.º 14
0
        public void WhenItIsGasHogTrue()
        {
            FuelEfficiency f       = new FuelEfficiency();
            int            gallons = _scenarioContext.Get <int>("gallons");
            int            miles   = _scenarioContext.Get <int>("miles");
            bool           gasUse  = f.gasHog(miles, gallons);

            _scenarioContext.Add("gasUse", gasUse);
        }
Exemplo n.º 15
0
        public void WhenCal_MpgIsCalled()
        {
            FuelEfficiency f = new FuelEfficiency();

            _scenarioContext.Add("gasUse", f.gasUse(
                                     _scenarioContext.Get <float>("miles"),
                                     _scenarioContext.Get <float>("gallons")
                                     ));
        }
Exemplo n.º 16
0
        public void WhenCalc_MilesIsCalled()
        {
            FuelEfficiency f = new FuelEfficiency();

            _scenarioContext.Add("miles", f.calc_miles(
                                     _scenarioContext.Get <float>("gallons"),
                                     _scenarioContext.Get <float>("mpg")
                                     ));
        }
Exemplo n.º 17
0
        public void WhenCalc_PayIsCalled()
        {
            FuelEfficiency f = new FuelEfficiency();

            _scenarioContext.Add("validation", f.calc_pay(
                                     _scenarioContext.Get <float>("gallons"),
                                     _scenarioContext.Get <float>("price"),
                                     _scenarioContext.Get <float>("cardAmount")
                                     ));
        }
Exemplo n.º 18
0
        public void To_UnitSystem_ThrowsArgumentExceptionIfNotSupported()
        {
            var literper100kilometers = FuelEfficiency.FromLitersPer100Kilometers(1);

            Assert.Throws <ArgumentException>(() => literper100kilometers.ToUnit(UnitSystem.SI));
            Assert.Throws <ArgumentException>(() => literper100kilometers.ToUnit(UnitSystem.CGS));
            Assert.Throws <ArgumentException>(() => literper100kilometers.ToUnit(UnitSystem.BI));
            Assert.Throws <ArgumentException>(() => literper100kilometers.ToUnit(UnitSystem.EE));
            Assert.Throws <ArgumentException>(() => literper100kilometers.ToUnit(UnitSystem.USC));
            Assert.Throws <ArgumentException>(() => literper100kilometers.ToUnit(UnitSystem.FPS));
            Assert.Throws <ArgumentException>(() => literper100kilometers.ToUnit(UnitSystem.Astronomical));
        }
Exemplo n.º 19
0
        public void ArithmeticOperators()
        {
            FuelEfficiency v = FuelEfficiency.FromLitersPer100Kilometers(1);

            AssertEx.EqualTolerance(-1, -v.LitersPer100Kilometers, LitersPer100KilometersTolerance);
            AssertEx.EqualTolerance(2, (FuelEfficiency.FromLitersPer100Kilometers(3) - v).LitersPer100Kilometers, LitersPer100KilometersTolerance);
            AssertEx.EqualTolerance(2, (v + v).LitersPer100Kilometers, LitersPer100KilometersTolerance);
            AssertEx.EqualTolerance(10, (v * 10).LitersPer100Kilometers, LitersPer100KilometersTolerance);
            AssertEx.EqualTolerance(10, (10 * v).LitersPer100Kilometers, LitersPer100KilometersTolerance);
            AssertEx.EqualTolerance(2, (FuelEfficiency.FromLitersPer100Kilometers(10) / 5).LitersPer100Kilometers, LitersPer100KilometersTolerance);
            AssertEx.EqualTolerance(2, FuelEfficiency.FromLitersPer100Kilometers(10) / FuelEfficiency.FromLitersPer100Kilometers(5), LitersPer100KilometersTolerance);
        }
Exemplo n.º 20
0
        public void WhenCalc_MpgIsCalled()
        {
            FuelEfficiency f = new FuelEfficiency();

            //int m = _scenarioContext.Get<int>("miles");
            //int g = _scenarioContext.Get<int>("gallons");
            //int answer = f.calc_mpg(m, g);
            //_scenarioContext.Add("mpg", answer);

            _scenarioContext.Add("mpg",
                                 f.calc_mpg(_scenarioContext.Get <double>("miles"),
                                            _scenarioContext.Get <double>("gallons")));
        }
Exemplo n.º 21
0
        public void ComparisonOperators()
        {
            FuelEfficiency oneLiterPer100Kilometers  = FuelEfficiency.FromLitersPer100Kilometers(1);
            FuelEfficiency twoLitersPer100Kilometers = FuelEfficiency.FromLitersPer100Kilometers(2);

            Assert.True(oneLiterPer100Kilometers < twoLitersPer100Kilometers);
            Assert.True(oneLiterPer100Kilometers <= twoLitersPer100Kilometers);
            Assert.True(twoLitersPer100Kilometers > oneLiterPer100Kilometers);
            Assert.True(twoLitersPer100Kilometers >= oneLiterPer100Kilometers);

            Assert.False(oneLiterPer100Kilometers > twoLitersPer100Kilometers);
            Assert.False(oneLiterPer100Kilometers >= twoLitersPer100Kilometers);
            Assert.False(twoLitersPer100Kilometers < oneLiterPer100Kilometers);
            Assert.False(twoLitersPer100Kilometers <= oneLiterPer100Kilometers);
        }
Exemplo n.º 22
0
        public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported()
        {
            var           quantity           = new FuelEfficiency(value: 1, unit: FuelEfficiency.BaseUnit);
            Func <object> AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI);

            if (SupportsSIUnitSystem)
            {
                var value = (double)AsWithSIUnitSystem();
                Assert.Equal(1, value);
            }
            else
            {
                Assert.Throws <ArgumentException>(AsWithSIUnitSystem);
            }
        }
Exemplo n.º 23
0
        public void FuelEfficiency_QuantityInfo_ReturnsQuantityInfoDescribingQuantity()
        {
            var quantity = new FuelEfficiency(1, FuelEfficiencyUnit.LiterPer100Kilometers);

            QuantityInfo <FuelEfficiencyUnit> quantityInfo = quantity.QuantityInfo;

            Assert.Equal(FuelEfficiency.Zero, quantityInfo.Zero);
            Assert.Equal("FuelEfficiency", quantityInfo.Name);
            Assert.Equal(QuantityType.FuelEfficiency, quantityInfo.QuantityType);

            var units     = EnumUtils.GetEnumValues <FuelEfficiencyUnit>().Except(new[] { FuelEfficiencyUnit.Undefined }).ToArray();
            var unitNames = units.Select(x => x.ToString());

            // Obsolete members
            Assert.Equal(units, quantityInfo.Units);
            Assert.Equal(unitNames, quantityInfo.UnitNames);
        }
Exemplo n.º 24
0
        public void EqualityOperators()
        {
            var a = FuelEfficiency.FromLitersPer100Kilometers(1);
            var b = FuelEfficiency.FromLitersPer100Kilometers(2);

            // ReSharper disable EqualExpressionComparison

            Assert.True(a == a);
            Assert.False(a != a);

            Assert.True(a != b);
            Assert.False(a == b);

            Assert.False(a == null);
            Assert.False(null == a);

// ReSharper restore EqualExpressionComparison
        }
Exemplo n.º 25
0
        public void From_ValueAndUnit_ReturnsQuantityWithSameValueAndUnit()
        {
            var quantity00 = FuelEfficiency.From(1, FuelEfficiencyUnit.KilometerPerLiter);

            AssertEx.EqualTolerance(1, quantity00.KilometersPerLiters, KilometersPerLitersTolerance);
            Assert.Equal(FuelEfficiencyUnit.KilometerPerLiter, quantity00.Unit);

            var quantity01 = FuelEfficiency.From(1, FuelEfficiencyUnit.LiterPer100Kilometers);

            AssertEx.EqualTolerance(1, quantity01.LitersPer100Kilometers, LitersPer100KilometersTolerance);
            Assert.Equal(FuelEfficiencyUnit.LiterPer100Kilometers, quantity01.Unit);

            var quantity02 = FuelEfficiency.From(1, FuelEfficiencyUnit.MilePerUkGallon);

            AssertEx.EqualTolerance(1, quantity02.MilesPerUkGallon, MilesPerUkGallonTolerance);
            Assert.Equal(FuelEfficiencyUnit.MilePerUkGallon, quantity02.Unit);

            var quantity03 = FuelEfficiency.From(1, FuelEfficiencyUnit.MilePerUsGallon);

            AssertEx.EqualTolerance(1, quantity03.MilesPerUsGallon, MilesPerUsGallonTolerance);
            Assert.Equal(FuelEfficiencyUnit.MilePerUsGallon, quantity03.Unit);
        }
Exemplo n.º 26
0
        public void ToUnit()
        {
            var literper100kilometers = FuelEfficiency.FromLitersPer100Kilometers(1);

            var kilometerperliterQuantity = literper100kilometers.ToUnit(FuelEfficiencyUnit.KilometerPerLiter);

            AssertEx.EqualTolerance(KilometersPerLitersInOneLiterPer100Kilometers, (double)kilometerperliterQuantity.Value, KilometersPerLitersTolerance);
            Assert.Equal(FuelEfficiencyUnit.KilometerPerLiter, kilometerperliterQuantity.Unit);

            var literper100kilometersQuantity = literper100kilometers.ToUnit(FuelEfficiencyUnit.LiterPer100Kilometers);

            AssertEx.EqualTolerance(LitersPer100KilometersInOneLiterPer100Kilometers, (double)literper100kilometersQuantity.Value, LitersPer100KilometersTolerance);
            Assert.Equal(FuelEfficiencyUnit.LiterPer100Kilometers, literper100kilometersQuantity.Unit);

            var mileperukgallonQuantity = literper100kilometers.ToUnit(FuelEfficiencyUnit.MilePerUkGallon);

            AssertEx.EqualTolerance(MilesPerUkGallonInOneLiterPer100Kilometers, (double)mileperukgallonQuantity.Value, MilesPerUkGallonTolerance);
            Assert.Equal(FuelEfficiencyUnit.MilePerUkGallon, mileperukgallonQuantity.Unit);

            var mileperusgallonQuantity = literper100kilometers.ToUnit(FuelEfficiencyUnit.MilePerUsGallon);

            AssertEx.EqualTolerance(MilesPerUsGallonInOneLiterPer100Kilometers, (double)mileperusgallonQuantity.Value, MilesPerUsGallonTolerance);
            Assert.Equal(FuelEfficiencyUnit.MilePerUsGallon, mileperusgallonQuantity.Unit);
        }
Exemplo n.º 27
0
 public static FuelEfficiency MilesPerUsGallon <T>(this T value) =>
 FuelEfficiency.FromMilesPerUsGallon(Convert.ToDecimal(value));
Exemplo n.º 28
0
 public static FuelEfficiency LitersPer100Kilometers <T>(this T value) =>
 FuelEfficiency.FromLitersPer100Kilometers(Convert.ToDecimal(value));
Exemplo n.º 29
0
        public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value)
        {
            var quantity = FuelEfficiency.FromLitersPer100Kilometers(value);

            Assert.Equal(FuelEfficiency.FromLitersPer100Kilometers(-value), -quantity);
        }
Exemplo n.º 30
0
        public void Ctor_WithNaNValue_CreateQuantityAndAffectNaNValue()
        {
            var nanQuantity = new FuelEfficiency(double.NaN, FuelEfficiencyUnit.LiterPer100Kilometers);

            Assert.True(double.IsNaN(nanQuantity.Value));
        }