public void ComparisonOperators()
        {
            AreaDensity oneKilogramPerSquareMeter  = AreaDensity.FromKilogramsPerSquareMeter(1);
            AreaDensity twoKilogramsPerSquareMeter = AreaDensity.FromKilogramsPerSquareMeter(2);

            Assert.True(oneKilogramPerSquareMeter < twoKilogramsPerSquareMeter);
            Assert.True(oneKilogramPerSquareMeter <= twoKilogramsPerSquareMeter);
            Assert.True(twoKilogramsPerSquareMeter > oneKilogramPerSquareMeter);
            Assert.True(twoKilogramsPerSquareMeter >= oneKilogramPerSquareMeter);

            Assert.False(oneKilogramPerSquareMeter > twoKilogramsPerSquareMeter);
            Assert.False(oneKilogramPerSquareMeter >= twoKilogramsPerSquareMeter);
            Assert.False(twoKilogramsPerSquareMeter < oneKilogramPerSquareMeter);
            Assert.False(twoKilogramsPerSquareMeter <= oneKilogramPerSquareMeter);
        }
示例#2
0
        public void EqualityOperators()
        {
            var a = AreaDensity.FromKilogramsPerSquareMeter(1);
            var b = AreaDensity.FromKilogramsPerSquareMeter(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
        }
示例#3
0
        public void ToBaseUnit_ReturnsQuantityWithBaseUnit()
        {
            var quantityInBaseUnit = AreaDensity.FromKilogramsPerSquareMeter(1).ToBaseUnit();

            Assert.Equal(AreaDensity.BaseUnit, quantityInBaseUnit.Unit);
        }
示例#4
0
 /// <inheritdoc cref="AreaDensity.FromKilogramsPerSquareMeter(double?)"/>
 public static AreaDensity?KilogramsPerSquareMeter(this decimal?value) => AreaDensity.FromKilogramsPerSquareMeter(value == null ? (double?)null : Convert.ToDouble(value.Value));
示例#5
0
 /// <inheritdoc cref="AreaDensity.FromKilogramsPerSquareMeter(double)"/>
 public static AreaDensity KilogramsPerSquareMeter(this double value) => AreaDensity.FromKilogramsPerSquareMeter(value);
示例#6
0
        public void As()
        {
            var kilogrampersquaremeter = AreaDensity.FromKilogramsPerSquareMeter(1);

            AssertEx.EqualTolerance(KilogramsPerSquareMeterInOneKilogramPerSquareMeter, kilogrampersquaremeter.As(AreaDensityUnit.KilogramPerSquareMeter), KilogramsPerSquareMeterTolerance);
        }
示例#7
0
        public void EqualsReturnsFalseOnNull()
        {
            AreaDensity kilogrampersquaremeter = AreaDensity.FromKilogramsPerSquareMeter(1);

            Assert.False(kilogrampersquaremeter.Equals(null));
        }
示例#8
0
        public void CompareToThrowsOnNull()
        {
            AreaDensity kilogrampersquaremeter = AreaDensity.FromKilogramsPerSquareMeter(1);

            Assert.Throws <ArgumentNullException>(() => kilogrampersquaremeter.CompareTo(null));
        }
示例#9
0
        public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value)
        {
            var quantity = AreaDensity.FromKilogramsPerSquareMeter(value);

            Assert.Equal(AreaDensity.FromKilogramsPerSquareMeter(-value), -quantity);
        }
示例#10
0
        public void Convert_ToInt16_EqualsValueAsSameType()
        {
            var quantity = AreaDensity.FromKilogramsPerSquareMeter(1.0);

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

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

            Assert.Throws <InvalidCastException>(() => Convert.ToDateTime(quantity));
        }
示例#13
0
        public void ToString_NullProvider_EqualsCurrentUICulture()
        {
            var quantity = AreaDensity.FromKilogramsPerSquareMeter(1.0);

            Assert.Equal(quantity.ToString(CultureInfo.CurrentUICulture, "g"), quantity.ToString(null, "g"));
        }
示例#14
0
        public void ToString_NullArgs_ThrowsArgumentNullException()
        {
            var quantity = AreaDensity.FromKilogramsPerSquareMeter(1.0);

            Assert.Throws <ArgumentNullException>(() => quantity.ToString(null, "g", null));
        }
示例#15
0
        public void Equals_NegativeRelativeTolerance_ThrowsArgumentOutOfRangeException()
        {
            var v = AreaDensity.FromKilogramsPerSquareMeter(1);

            Assert.Throws <ArgumentOutOfRangeException>(() => v.Equals(AreaDensity.FromKilogramsPerSquareMeter(1), -1, ComparisonType.Relative));
        }
示例#16
0
        public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException()
        {
            var quantity = AreaDensity.FromKilogramsPerSquareMeter(1.0);

            Assert.Throws <InvalidCastException>(() => Convert.ChangeType(quantity, typeof(QuantityFormatter)));
        }
示例#17
0
        public void GetHashCode_Equals()
        {
            var quantity = AreaDensity.FromKilogramsPerSquareMeter(1.0);

            Assert.Equal(new { AreaDensity.QuantityType, quantity.Value, quantity.Unit }.GetHashCode(), quantity.GetHashCode());
        }
示例#18
0
        public void Convert_ToSingle_EqualsValueAsSameType()
        {
            var quantity = AreaDensity.FromKilogramsPerSquareMeter(1.0);

            Assert.Equal((float)quantity.Value, Convert.ToSingle(quantity));
        }
示例#19
0
        public void CompareToThrowsOnTypeMismatch()
        {
            AreaDensity kilogrampersquaremeter = AreaDensity.FromKilogramsPerSquareMeter(1);

            Assert.Throws <ArgumentException>(() => kilogrampersquaremeter.CompareTo(new object()));
        }
示例#20
0
        public void Convert_ToString_EqualsToString()
        {
            var quantity = AreaDensity.FromKilogramsPerSquareMeter(1.0);

            Assert.Equal(quantity.ToString(), Convert.ToString(quantity));
        }
示例#21
0
        public void EqualsReturnsFalseOnTypeMismatch()
        {
            AreaDensity kilogrampersquaremeter = AreaDensity.FromKilogramsPerSquareMeter(1);

            Assert.False(kilogrampersquaremeter.Equals(new object()));
        }
示例#22
0
        public void Convert_ToUInt64_EqualsValueAsSameType()
        {
            var quantity = AreaDensity.FromKilogramsPerSquareMeter(1.0);

            Assert.Equal((ulong)quantity.Value, Convert.ToUInt64(quantity));
        }
示例#23
0
        public void KilogramPerSquareMeterToAreaDensityUnits()
        {
            AreaDensity kilogrampersquaremeter = AreaDensity.FromKilogramsPerSquareMeter(1);

            AssertEx.EqualTolerance(KilogramsPerSquareMeterInOneKilogramPerSquareMeter, kilogrampersquaremeter.KilogramsPerSquareMeter, KilogramsPerSquareMeterTolerance);
        }
示例#24
0
        public void Convert_ChangeType_SelfType_EqualsSelf()
        {
            var quantity = AreaDensity.FromKilogramsPerSquareMeter(1.0);

            Assert.Equal(quantity, Convert.ChangeType(quantity, typeof(AreaDensity)));
        }
示例#25
0
        public void ConversionRoundTrip()
        {
            AreaDensity kilogrampersquaremeter = AreaDensity.FromKilogramsPerSquareMeter(1);

            AssertEx.EqualTolerance(1, AreaDensity.FromKilogramsPerSquareMeter(kilogrampersquaremeter.KilogramsPerSquareMeter).KilogramsPerSquareMeter, KilogramsPerSquareMeterTolerance);
        }
示例#26
0
        public void Convert_ChangeType_UnitType_EqualsUnit()
        {
            var quantity = AreaDensity.FromKilogramsPerSquareMeter(1.0);

            Assert.Equal(quantity.Unit, Convert.ChangeType(quantity, typeof(AreaDensityUnit)));
        }
示例#27
0
 /// <inheritdoc cref="AreaDensity.FromKilogramsPerSquareMeter(double?)"/>
 public static AreaDensity?KilogramsPerSquareMeter(this float?value) => AreaDensity.FromKilogramsPerSquareMeter(value);
示例#28
0
        public void Convert_ChangeType_QuantityType_EqualsQuantityType()
        {
            var quantity = AreaDensity.FromKilogramsPerSquareMeter(1.0);

            Assert.Equal(QuantityType.AreaDensity, Convert.ChangeType(quantity, typeof(QuantityType)));
        }
示例#29
0
 /// <inheritdoc cref="AreaDensity.FromKilogramsPerSquareMeter(UnitsNet.QuantityValue)" />
 public static AreaDensity KilogramsPerSquareMeter <T>(this T value) => AreaDensity.FromKilogramsPerSquareMeter(Convert.ToDouble(value));
示例#30
0
        public void Convert_ChangeType_BaseDimensions_EqualsBaseDimensions()
        {
            var quantity = AreaDensity.FromKilogramsPerSquareMeter(1.0);

            Assert.Equal(AreaDensity.BaseDimensions, Convert.ChangeType(quantity, typeof(BaseDimensions)));
        }