public void Equals_RelativeTolerance_IsImplemented()
        {
            var v = PressureGradient.FromPascalPerMeters(1);

            Assert.True(v.Equals(PressureGradient.FromPascalPerMeters(1), PascalPerMetersTolerance, ComparisonType.Relative));
            Assert.False(v.Equals(PressureGradient.Zero, PascalPerMetersTolerance, ComparisonType.Relative));
        }
        public void Equals_SameType_IsImplemented()
        {
            var a = PressureGradient.FromPascalPerMeters(1);
            var b = PressureGradient.FromPascalPerMeters(2);

            Assert.True(a.Equals(a));
            Assert.False(a.Equals(b));
        }
        public void CompareToIsImplemented()
        {
            PressureGradient pascalpermeter = PressureGradient.FromPascalPerMeters(1);

            Assert.Equal(0, pascalpermeter.CompareTo(pascalpermeter));
            Assert.True(pascalpermeter.CompareTo(PressureGradient.Zero) > 0);
            Assert.True(PressureGradient.Zero.CompareTo(pascalpermeter) < 0);
        }
        public void ToUnit()
        {
            var pascalpermeter = PressureGradient.FromPascalPerMeters(1);

            var pascalpermeterQuantity = pascalpermeter.ToUnit(PressureGradientUnit.PascalPerMeter);

            AssertEx.EqualTolerance(PascalPerMetersInOnePascalPerMeter, (double)pascalpermeterQuantity.Value, PascalPerMetersTolerance);
            Assert.Equal(PressureGradientUnit.PascalPerMeter, pascalpermeterQuantity.Unit);
        }
        public void Equals_QuantityAsObject_IsImplemented()
        {
            object a = PressureGradient.FromPascalPerMeters(1);
            object b = PressureGradient.FromPascalPerMeters(2);

            Assert.True(a.Equals(a));
            Assert.False(a.Equals(b));
            Assert.False(a.Equals((object)null));
        }
        public void ArithmeticOperators()
        {
            PressureGradient v = PressureGradient.FromPascalPerMeters(1);

            AssertEx.EqualTolerance(-1, -v.PascalPerMeters, PascalPerMetersTolerance);
            AssertEx.EqualTolerance(2, (PressureGradient.FromPascalPerMeters(3) - v).PascalPerMeters, PascalPerMetersTolerance);
            AssertEx.EqualTolerance(2, (v + v).PascalPerMeters, PascalPerMetersTolerance);
            AssertEx.EqualTolerance(10, (v * 10).PascalPerMeters, PascalPerMetersTolerance);
            AssertEx.EqualTolerance(10, (10 * v).PascalPerMeters, PascalPerMetersTolerance);
            AssertEx.EqualTolerance(2, (PressureGradient.FromPascalPerMeters(10) / 5).PascalPerMeters, PascalPerMetersTolerance);
            AssertEx.EqualTolerance(2, PressureGradient.FromPascalPerMeters(10) / PressureGradient.FromPascalPerMeters(5), PascalPerMetersTolerance);
        }
        public void ComparisonOperators()
        {
            PressureGradient onePascalPerMeter  = PressureGradient.FromPascalPerMeters(1);
            PressureGradient twoPascalPerMeters = PressureGradient.FromPascalPerMeters(2);

            Assert.True(onePascalPerMeter < twoPascalPerMeters);
            Assert.True(onePascalPerMeter <= twoPascalPerMeters);
            Assert.True(twoPascalPerMeters > onePascalPerMeter);
            Assert.True(twoPascalPerMeters >= onePascalPerMeter);

            Assert.False(onePascalPerMeter > twoPascalPerMeters);
            Assert.False(onePascalPerMeter >= twoPascalPerMeters);
            Assert.False(twoPascalPerMeters < onePascalPerMeter);
            Assert.False(twoPascalPerMeters <= onePascalPerMeter);
        }
        public void EqualityOperators()
        {
            var a = PressureGradient.FromPascalPerMeters(1);
            var b = PressureGradient.FromPascalPerMeters(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
        }
        public void Convert_ToSingle_EqualsValueAsSameType()
        {
            var quantity = PressureGradient.FromPascalPerMeters(1.0);

            Assert.Equal((float)quantity.Value, Convert.ToSingle(quantity));
        }
        public void Convert_ToInt16_EqualsValueAsSameType()
        {
            var quantity = PressureGradient.FromPascalPerMeters(1.0);

            Assert.Equal((short)quantity.Value, Convert.ToInt16(quantity));
        }
        public void Convert_ToDecimal_EqualsValueAsSameType()
        {
            var quantity = PressureGradient.FromPascalPerMeters(1.0);

            Assert.Equal((decimal)quantity.Value, Convert.ToDecimal(quantity));
        }
        public void Convert_ToDateTime_ThrowsInvalidCastException()
        {
            var quantity = PressureGradient.FromPascalPerMeters(1.0);

            Assert.Throws <InvalidCastException>(() => Convert.ToDateTime(quantity));
        }
        public void ConversionRoundTrip()
        {
            PressureGradient pascalpermeter = PressureGradient.FromPascalPerMeters(1);

            AssertEx.EqualTolerance(1, PressureGradient.FromPascalPerMeters(pascalpermeter.PascalPerMeters).PascalPerMeters, PascalPerMetersTolerance);
        }
        public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value)
        {
            var quantity = PressureGradient.FromPascalPerMeters(value);

            Assert.Equal(PressureGradient.FromPascalPerMeters(-value), -quantity);
        }
        public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException()
        {
            var quantity = PressureGradient.FromPascalPerMeters(1.0);

            Assert.Throws <InvalidCastException>(() => Convert.ChangeType(quantity, typeof(QuantityFormatter)));
        }
        public void Convert_ChangeType_QuantityType_EqualsQuantityType()
        {
            var quantity = PressureGradient.FromPascalPerMeters(1.0);

            Assert.Equal(QuantityType.PressureGradient, Convert.ChangeType(quantity, typeof(QuantityType)));
        }
        public void Convert_ChangeType_SelfType_EqualsSelf()
        {
            var quantity = PressureGradient.FromPascalPerMeters(1.0);

            Assert.Equal(quantity, Convert.ChangeType(quantity, typeof(PressureGradient)));
        }
        public void Convert_ToString_EqualsToString()
        {
            var quantity = PressureGradient.FromPascalPerMeters(1.0);

            Assert.Equal(quantity.ToString(), Convert.ToString(quantity));
        }
        public void CompareToThrowsOnNull()
        {
            PressureGradient pascalpermeter = PressureGradient.FromPascalPerMeters(1);

            Assert.Throws <ArgumentNullException>(() => pascalpermeter.CompareTo(null));
        }
        public void CompareToThrowsOnTypeMismatch()
        {
            PressureGradient pascalpermeter = PressureGradient.FromPascalPerMeters(1);

            Assert.Throws <ArgumentException>(() => pascalpermeter.CompareTo(new object()));
        }
        public void Convert_ToUInt64_EqualsValueAsSameType()
        {
            var quantity = PressureGradient.FromPascalPerMeters(1.0);

            Assert.Equal((ulong)quantity.Value, Convert.ToUInt64(quantity));
        }
        public void Equals_NegativeRelativeTolerance_ThrowsArgumentOutOfRangeException()
        {
            var v = PressureGradient.FromPascalPerMeters(1);

            Assert.Throws <ArgumentOutOfRangeException>(() => v.Equals(PressureGradient.FromPascalPerMeters(1), -1, ComparisonType.Relative));
        }
        public void Convert_ChangeType_UnitType_EqualsUnit()
        {
            var quantity = PressureGradient.FromPascalPerMeters(1.0);

            Assert.Equal(quantity.Unit, Convert.ChangeType(quantity, typeof(PressureGradientUnit)));
        }
        public void EqualsReturnsFalseOnTypeMismatch()
        {
            PressureGradient pascalpermeter = PressureGradient.FromPascalPerMeters(1);

            Assert.False(pascalpermeter.Equals(new object()));
        }
        public void Convert_ChangeType_BaseDimensions_EqualsBaseDimensions()
        {
            var quantity = PressureGradient.FromPascalPerMeters(1.0);

            Assert.Equal(PressureGradient.BaseDimensions, Convert.ChangeType(quantity, typeof(BaseDimensions)));
        }
        public void EqualsReturnsFalseOnNull()
        {
            PressureGradient pascalpermeter = PressureGradient.FromPascalPerMeters(1);

            Assert.False(pascalpermeter.Equals(null));
        }
        public void GetHashCode_Equals()
        {
            var quantity = PressureGradient.FromPascalPerMeters(1.0);

            Assert.Equal(new { PressureGradient.QuantityType, quantity.Value, quantity.Unit }.GetHashCode(), quantity.GetHashCode());
        }
        public void ToString_NullArgs_ThrowsArgumentNullException()
        {
            var quantity = PressureGradient.FromPascalPerMeters(1.0);

            Assert.Throws <ArgumentNullException>(() => quantity.ToString(null, "g", null));
        }
Пример #29
0
 public void NumberToPascalPerMetersTest() =>
 Assert.Equal(PressureGradient.FromPascalPerMeters(2), 2.PascalPerMeters());
        public void ToString_NullProvider_EqualsCurrentUICulture()
        {
            var quantity = PressureGradient.FromPascalPerMeters(1.0);

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