示例#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));
        }
示例#2
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);
        }
示例#3
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));
        }
示例#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));
        }
示例#5
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));
        }
示例#6
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);
        }
示例#7
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);
        }
示例#8
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);
        }
示例#9
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);
        }
        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));
        }
示例#11
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);
        }
示例#12
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
        }
示例#13
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);
        }
示例#14
0
        public void Convert_ChangeType_UnitType_EqualsUnit()
        {
            var quantity = FuelEfficiency.FromLitersPer100Kilometers(1.0);

            Assert.Equal(quantity.Unit, Convert.ChangeType(quantity, typeof(FuelEfficiencyUnit)));
        }
示例#15
0
        public void Convert_ChangeType_SelfType_EqualsSelf()
        {
            var quantity = FuelEfficiency.FromLitersPer100Kilometers(1.0);

            Assert.Equal(quantity, Convert.ChangeType(quantity, typeof(FuelEfficiency)));
        }
示例#16
0
        public void Convert_ToUInt64_EqualsValueAsSameType()
        {
            var quantity = FuelEfficiency.FromLitersPer100Kilometers(1.0);

            Assert.Equal((ulong)quantity.Value, Convert.ToUInt64(quantity));
        }
示例#17
0
        public void Convert_ToString_EqualsToString()
        {
            var quantity = FuelEfficiency.FromLitersPer100Kilometers(1.0);

            Assert.Equal(quantity.ToString(), Convert.ToString(quantity));
        }
示例#18
0
        public void Convert_ToSingle_EqualsValueAsSameType()
        {
            var quantity = FuelEfficiency.FromLitersPer100Kilometers(1.0);

            Assert.Equal((float)quantity.Value, Convert.ToSingle(quantity));
        }
示例#19
0
        public void Convert_ToInt16_EqualsValueAsSameType()
        {
            var quantity = FuelEfficiency.FromLitersPer100Kilometers(1.0);

            Assert.Equal((short)quantity.Value, Convert.ToInt16(quantity));
        }
示例#20
0
        public void Convert_ToDecimal_EqualsValueAsSameType()
        {
            var quantity = FuelEfficiency.FromLitersPer100Kilometers(1.0);

            Assert.Equal((decimal)quantity.Value, Convert.ToDecimal(quantity));
        }
示例#21
0
        public void Convert_ToDateTime_ThrowsInvalidCastException()
        {
            var quantity = FuelEfficiency.FromLitersPer100Kilometers(1.0);

            Assert.Throws <InvalidCastException>(() => Convert.ToDateTime(quantity));
        }
示例#22
0
        public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value)
        {
            var quantity = FuelEfficiency.FromLitersPer100Kilometers(value);

            Assert.Equal(FuelEfficiency.FromLitersPer100Kilometers(-value), -quantity);
        }
示例#23
0
        public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException()
        {
            var quantity = FuelEfficiency.FromLitersPer100Kilometers(1.0);

            Assert.Throws <InvalidCastException>(() => Convert.ChangeType(quantity, typeof(QuantityFormatter)));
        }
示例#24
0
        public void Convert_ChangeType_QuantityType_EqualsQuantityType()
        {
            var quantity = FuelEfficiency.FromLitersPer100Kilometers(1.0);

            Assert.Equal(QuantityType.FuelEfficiency, Convert.ChangeType(quantity, typeof(QuantityType)));
        }
示例#25
0
        public void Convert_ChangeType_BaseDimensions_EqualsBaseDimensions()
        {
            var quantity = FuelEfficiency.FromLitersPer100Kilometers(1.0);

            Assert.Equal(FuelEfficiency.BaseDimensions, Convert.ChangeType(quantity, typeof(BaseDimensions)));
        }
示例#26
0
        public void EqualsReturnsFalseOnNull()
        {
            FuelEfficiency literper100kilometers = FuelEfficiency.FromLitersPer100Kilometers(1);

            Assert.False(literper100kilometers.Equals(null));
        }
示例#27
0
        public void GetHashCode_Equals()
        {
            var quantity = FuelEfficiency.FromLitersPer100Kilometers(1.0);

            Assert.Equal(new { FuelEfficiency.QuantityType, quantity.Value, quantity.Unit }.GetHashCode(), quantity.GetHashCode());
        }
示例#28
0
        public void ToString_NullArgs_ThrowsArgumentNullException()
        {
            var quantity = FuelEfficiency.FromLitersPer100Kilometers(1.0);

            Assert.Throws <ArgumentNullException>(() => quantity.ToString(null, "g", null));
        }
示例#29
0
 public static FuelEfficiency LitersPer100Kilometers <T>(this T value) =>
 FuelEfficiency.FromLitersPer100Kilometers(Convert.ToDecimal(value));
示例#30
0
        public void ToString_NullProvider_EqualsCurrentUICulture()
        {
            var quantity = FuelEfficiency.FromLitersPer100Kilometers(1.0);

            Assert.Equal(quantity.ToString(CultureInfo.CurrentUICulture, "g"), quantity.ToString(null, "g"));
        }