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);
        }
Example #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
        }
Example #3
0
        public void ToBaseUnit_ReturnsQuantityWithBaseUnit()
        {
            var quantityInBaseUnit = AreaDensity.FromKilogramsPerSquareMeter(1).ToBaseUnit();

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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