示例#1
0
        public void Equals_RelativeTolerance_IsImplemented()
        {
            var v = TemperatureCoefficient.FromPercentageByKelvins(1);

            Assert.True(v.Equals(TemperatureCoefficient.FromPercentageByKelvins(1), PercentageByKelvinsTolerance, ComparisonType.Relative));
            Assert.False(v.Equals(TemperatureCoefficient.Zero, PercentageByKelvinsTolerance, ComparisonType.Relative));
        }
示例#2
0
        public void Equals_SameType_IsImplemented()
        {
            var a = TemperatureCoefficient.FromPercentageByKelvins(1);
            var b = TemperatureCoefficient.FromPercentageByKelvins(2);

            Assert.True(a.Equals(a));
            Assert.False(a.Equals(b));
        }
示例#3
0
        public void CompareToIsImplemented()
        {
            TemperatureCoefficient percentagebykelvin = TemperatureCoefficient.FromPercentageByKelvins(1);

            Assert.Equal(0, percentagebykelvin.CompareTo(percentagebykelvin));
            Assert.True(percentagebykelvin.CompareTo(TemperatureCoefficient.Zero) > 0);
            Assert.True(TemperatureCoefficient.Zero.CompareTo(percentagebykelvin) < 0);
        }
示例#4
0
        public void ToUnit()
        {
            var percentagebykelvin = TemperatureCoefficient.FromPercentageByKelvins(1);

            var percentagebykelvinQuantity = percentagebykelvin.ToUnit(TemperatureCoefficientUnit.PercentageByKelvin);

            AssertEx.EqualTolerance(PercentageByKelvinsInOnePercentageByKelvin, (double)percentagebykelvinQuantity.Value, PercentageByKelvinsTolerance);
            Assert.Equal(TemperatureCoefficientUnit.PercentageByKelvin, percentagebykelvinQuantity.Unit);
        }
示例#5
0
        public void Equals_QuantityAsObject_IsImplemented()
        {
            object a = TemperatureCoefficient.FromPercentageByKelvins(1);
            object b = TemperatureCoefficient.FromPercentageByKelvins(2);

            Assert.True(a.Equals(a));
            Assert.False(a.Equals(b));
            Assert.False(a.Equals((object)null));
        }
示例#6
0
        public void ArithmeticOperators()
        {
            TemperatureCoefficient v = TemperatureCoefficient.FromPercentageByKelvins(1);

            AssertEx.EqualTolerance(-1, -v.PercentageByKelvins, PercentageByKelvinsTolerance);
            AssertEx.EqualTolerance(2, (TemperatureCoefficient.FromPercentageByKelvins(3) - v).PercentageByKelvins, PercentageByKelvinsTolerance);
            AssertEx.EqualTolerance(2, (v + v).PercentageByKelvins, PercentageByKelvinsTolerance);
            AssertEx.EqualTolerance(10, (v * 10).PercentageByKelvins, PercentageByKelvinsTolerance);
            AssertEx.EqualTolerance(10, (10 * v).PercentageByKelvins, PercentageByKelvinsTolerance);
            AssertEx.EqualTolerance(2, (TemperatureCoefficient.FromPercentageByKelvins(10) / 5).PercentageByKelvins, PercentageByKelvinsTolerance);
            AssertEx.EqualTolerance(2, TemperatureCoefficient.FromPercentageByKelvins(10) / TemperatureCoefficient.FromPercentageByKelvins(5), PercentageByKelvinsTolerance);
        }
示例#7
0
        public void ComparisonOperators()
        {
            TemperatureCoefficient onePercentageByKelvin  = TemperatureCoefficient.FromPercentageByKelvins(1);
            TemperatureCoefficient twoPercentageByKelvins = TemperatureCoefficient.FromPercentageByKelvins(2);

            Assert.True(onePercentageByKelvin < twoPercentageByKelvins);
            Assert.True(onePercentageByKelvin <= twoPercentageByKelvins);
            Assert.True(twoPercentageByKelvins > onePercentageByKelvin);
            Assert.True(twoPercentageByKelvins >= onePercentageByKelvin);

            Assert.False(onePercentageByKelvin > twoPercentageByKelvins);
            Assert.False(onePercentageByKelvin >= twoPercentageByKelvins);
            Assert.False(twoPercentageByKelvins < onePercentageByKelvin);
            Assert.False(twoPercentageByKelvins <= onePercentageByKelvin);
        }
示例#8
0
        public void EqualityOperators()
        {
            var a = TemperatureCoefficient.FromPercentageByKelvins(1);
            var b = TemperatureCoefficient.FromPercentageByKelvins(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
        }
示例#9
0
        public void Convert_ToDateTime_ThrowsInvalidCastException()
        {
            var quantity = TemperatureCoefficient.FromPercentageByKelvins(1.0);

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

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

            Assert.Throws <ArgumentNullException>(() => quantity.ToString(null, "g", null));
        }
示例#12
0
        public void EqualsReturnsFalseOnNull()
        {
            TemperatureCoefficient percentagebykelvin = TemperatureCoefficient.FromPercentageByKelvins(1);

            Assert.False(percentagebykelvin.Equals(null));
        }
示例#13
0
 public void FromPercentageByKelvins_WithNanValue_ThrowsArgumentException()
 {
     Assert.Throws <ArgumentException>(() => TemperatureCoefficient.FromPercentageByKelvins(double.NaN));
 }
示例#14
0
        public void Convert_ToString_EqualsToString()
        {
            var quantity = TemperatureCoefficient.FromPercentageByKelvins(1.0);

            Assert.Equal(quantity.ToString(), Convert.ToString(quantity));
        }
示例#15
0
        public void Convert_ChangeType_UnitType_EqualsUnit()
        {
            var quantity = TemperatureCoefficient.FromPercentageByKelvins(1.0);

            Assert.Equal(quantity.Unit, Convert.ChangeType(quantity, typeof(TemperatureCoefficientUnit)));
        }
示例#16
0
        public void As()
        {
            var percentagebykelvin = TemperatureCoefficient.FromPercentageByKelvins(1);

            AssertEx.EqualTolerance(PercentageByKelvinsInOnePercentageByKelvin, percentagebykelvin.As(TemperatureCoefficientUnit.PercentageByKelvin), PercentageByKelvinsTolerance);
        }
示例#17
0
        public void CompareToThrowsOnNull()
        {
            TemperatureCoefficient percentagebykelvin = TemperatureCoefficient.FromPercentageByKelvins(1);

            Assert.Throws <ArgumentNullException>(() => percentagebykelvin.CompareTo(null));
        }
示例#18
0
        public void CompareToThrowsOnTypeMismatch()
        {
            TemperatureCoefficient percentagebykelvin = TemperatureCoefficient.FromPercentageByKelvins(1);

            Assert.Throws <ArgumentException>(() => percentagebykelvin.CompareTo(new object()));
        }
示例#19
0
        public void ConversionRoundTrip()
        {
            TemperatureCoefficient percentagebykelvin = TemperatureCoefficient.FromPercentageByKelvins(1);

            AssertEx.EqualTolerance(1, TemperatureCoefficient.FromPercentageByKelvins(percentagebykelvin.PercentageByKelvins).PercentageByKelvins, PercentageByKelvinsTolerance);
        }
示例#20
0
        public void Convert_ToDecimal_EqualsValueAsSameType()
        {
            var quantity = TemperatureCoefficient.FromPercentageByKelvins(1.0);

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

            Assert.Equal((float)quantity.Value, Convert.ToSingle(quantity));
        }
示例#22
0
        public void Convert_ChangeType_BaseDimensions_EqualsBaseDimensions()
        {
            var quantity = TemperatureCoefficient.FromPercentageByKelvins(1.0);

            Assert.Equal(TemperatureCoefficient.BaseDimensions, Convert.ChangeType(quantity, typeof(BaseDimensions)));
        }
示例#23
0
        public void Convert_ToUInt64_EqualsValueAsSameType()
        {
            var quantity = TemperatureCoefficient.FromPercentageByKelvins(1.0);

            Assert.Equal((ulong)quantity.Value, Convert.ToUInt64(quantity));
        }
示例#24
0
        public void GetHashCode_Equals()
        {
            var quantity = TemperatureCoefficient.FromPercentageByKelvins(1.0);

            Assert.Equal(new { TemperatureCoefficient.QuantityType, quantity.Value, quantity.Unit }.GetHashCode(), quantity.GetHashCode());
        }
示例#25
0
        public void Convert_ChangeType_QuantityType_EqualsQuantityType()
        {
            var quantity = TemperatureCoefficient.FromPercentageByKelvins(1.0);

            Assert.Equal(QuantityType.TemperatureCoefficient, Convert.ChangeType(quantity, typeof(QuantityType)));
        }
示例#26
0
        public void Equals_NegativeRelativeTolerance_ThrowsArgumentOutOfRangeException()
        {
            var v = TemperatureCoefficient.FromPercentageByKelvins(1);

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

            Assert.Throws <InvalidCastException>(() => Convert.ChangeType(quantity, typeof(QuantityFormatter)));
        }
示例#28
0
        public void EqualsReturnsFalseOnTypeMismatch()
        {
            TemperatureCoefficient percentagebykelvin = TemperatureCoefficient.FromPercentageByKelvins(1);

            Assert.False(percentagebykelvin.Equals(new object()));
        }
示例#29
0
        public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value)
        {
            var quantity = TemperatureCoefficient.FromPercentageByKelvins(value);

            Assert.Equal(TemperatureCoefficient.FromPercentageByKelvins(-value), -quantity);
        }
示例#30
0
 public void FromPercentageByKelvins_WithInfinityValue_ThrowsArgumentException()
 {
     Assert.Throws <ArgumentException>(() => TemperatureCoefficient.FromPercentageByKelvins(double.PositiveInfinity));
     Assert.Throws <ArgumentException>(() => TemperatureCoefficient.FromPercentageByKelvins(double.NegativeInfinity));
 }