Пример #1
0
        public void From_ValueAndUnit_ReturnsQuantityWithSameValueAndUnit()
        {
            var quantity00 = HeatCapacity.From(1, HeatCapacityUnit.BTUPerFahrenheitDegree);

            AssertEx.EqualTolerance(1, quantity00.BTUPerFahrenheitDegrees, BTUPerFahrenheitDegreesTolerance);
            Assert.Equal(HeatCapacityUnit.BTUPerFahrenheitDegree, quantity00.Unit);
        }
Пример #2
0
        public void DefaultCtor_ReturnsQuantityWithZeroValueAndBaseUnit()
        {
            var quantity = new HeatCapacity();

            Assert.Equal(0, quantity.Value);
            Assert.Equal(HeatCapacityUnit.BTUPerFahrenheitDegree, quantity.Unit);
        }
Пример #3
0
        public void Equals_RelativeTolerance_IsImplemented()
        {
            var v = HeatCapacity.FromBTUPerFahrenheitDegrees(1);

            Assert.True(v.Equals(HeatCapacity.FromBTUPerFahrenheitDegrees(1), BTUPerFahrenheitDegreesTolerance, ComparisonType.Relative));
            Assert.False(v.Equals(HeatCapacity.Zero, BTUPerFahrenheitDegreesTolerance, ComparisonType.Relative));
        }
Пример #4
0
        public void Equals_SameType_IsImplemented()
        {
            var a = HeatCapacity.FromBTUPerFahrenheitDegrees(1);
            var b = HeatCapacity.FromBTUPerFahrenheitDegrees(2);

            Assert.True(a.Equals(a));
            Assert.False(a.Equals(b));
        }
Пример #5
0
        public void CompareToIsImplemented()
        {
            HeatCapacity btuperfahrenheitdegree = HeatCapacity.FromBTUPerFahrenheitDegrees(1);

            Assert.Equal(0, btuperfahrenheitdegree.CompareTo(btuperfahrenheitdegree));
            Assert.True(btuperfahrenheitdegree.CompareTo(HeatCapacity.Zero) > 0);
            Assert.True(HeatCapacity.Zero.CompareTo(btuperfahrenheitdegree) < 0);
        }
Пример #6
0
        public void ToUnit()
        {
            var btuperfahrenheitdegree = HeatCapacity.FromBTUPerFahrenheitDegrees(1);

            var btuperfahrenheitdegreeQuantity = btuperfahrenheitdegree.ToUnit(HeatCapacityUnit.BTUPerFahrenheitDegree);

            AssertEx.EqualTolerance(BTUPerFahrenheitDegreesInOneBTUPerFahrenheitDegree, (double)btuperfahrenheitdegreeQuantity.Value, BTUPerFahrenheitDegreesTolerance);
            Assert.Equal(HeatCapacityUnit.BTUPerFahrenheitDegree, btuperfahrenheitdegreeQuantity.Unit);
        }
Пример #7
0
        public void Equals_QuantityAsObject_IsImplemented()
        {
            object a = HeatCapacity.FromBTUPerFahrenheitDegrees(1);
            object b = HeatCapacity.FromBTUPerFahrenheitDegrees(2);

            Assert.True(a.Equals(a));
            Assert.False(a.Equals(b));
            Assert.False(a.Equals((object)null));
        }
Пример #8
0
        public void ArithmeticOperators()
        {
            HeatCapacity v = HeatCapacity.FromBTUPerFahrenheitDegrees(1);

            AssertEx.EqualTolerance(-1, -v.BTUPerFahrenheitDegrees, BTUPerFahrenheitDegreesTolerance);
            AssertEx.EqualTolerance(2, (HeatCapacity.FromBTUPerFahrenheitDegrees(3) - v).BTUPerFahrenheitDegrees, BTUPerFahrenheitDegreesTolerance);
            AssertEx.EqualTolerance(2, (v + v).BTUPerFahrenheitDegrees, BTUPerFahrenheitDegreesTolerance);
            AssertEx.EqualTolerance(10, (v * 10).BTUPerFahrenheitDegrees, BTUPerFahrenheitDegreesTolerance);
            AssertEx.EqualTolerance(10, (10 * v).BTUPerFahrenheitDegrees, BTUPerFahrenheitDegreesTolerance);
            AssertEx.EqualTolerance(2, (HeatCapacity.FromBTUPerFahrenheitDegrees(10) / 5).BTUPerFahrenheitDegrees, BTUPerFahrenheitDegreesTolerance);
            AssertEx.EqualTolerance(2, HeatCapacity.FromBTUPerFahrenheitDegrees(10) / HeatCapacity.FromBTUPerFahrenheitDegrees(5), BTUPerFahrenheitDegreesTolerance);
        }
Пример #9
0
        public void ComparisonOperators()
        {
            HeatCapacity oneBTUPerFahrenheitDegree  = HeatCapacity.FromBTUPerFahrenheitDegrees(1);
            HeatCapacity twoBTUPerFahrenheitDegrees = HeatCapacity.FromBTUPerFahrenheitDegrees(2);

            Assert.True(oneBTUPerFahrenheitDegree < twoBTUPerFahrenheitDegrees);
            Assert.True(oneBTUPerFahrenheitDegree <= twoBTUPerFahrenheitDegrees);
            Assert.True(twoBTUPerFahrenheitDegrees > oneBTUPerFahrenheitDegree);
            Assert.True(twoBTUPerFahrenheitDegrees >= oneBTUPerFahrenheitDegree);

            Assert.False(oneBTUPerFahrenheitDegree > twoBTUPerFahrenheitDegrees);
            Assert.False(oneBTUPerFahrenheitDegree >= twoBTUPerFahrenheitDegrees);
            Assert.False(twoBTUPerFahrenheitDegrees < oneBTUPerFahrenheitDegree);
            Assert.False(twoBTUPerFahrenheitDegrees <= oneBTUPerFahrenheitDegree);
        }
Пример #10
0
        public void EqualityOperators()
        {
            var a = HeatCapacity.FromBTUPerFahrenheitDegrees(1);
            var b = HeatCapacity.FromBTUPerFahrenheitDegrees(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
        }
Пример #11
0
        public void HeatCapacity_QuantityInfo_ReturnsQuantityInfoDescribingQuantity()
        {
            var quantity = new HeatCapacity(1, HeatCapacityUnit.BTUPerFahrenheitDegree);

            QuantityInfo <HeatCapacityUnit> quantityInfo = quantity.QuantityInfo;

            Assert.Equal(HeatCapacity.Zero, quantityInfo.Zero);
            Assert.Equal("HeatCapacity", quantityInfo.Name);
            Assert.Equal(QuantityType.HeatCapacity, quantityInfo.QuantityType);

            var units     = EnumUtils.GetEnumValues <HeatCapacityUnit>().Except(new[] { HeatCapacityUnit.Undefined }).ToArray();
            var unitNames = units.Select(x => x.ToString());

            // Obsolete members
#pragma warning disable 618
            Assert.Equal(units, quantityInfo.Units);
            Assert.Equal(unitNames, quantityInfo.UnitNames);
#pragma warning restore 618
        }
Пример #12
0
        public void GetHashCode_Equals()
        {
            var quantity = HeatCapacity.FromBTUPerFahrenheitDegrees(1.0);

            Assert.Equal(new { HeatCapacity.QuantityType, quantity.Value, quantity.Unit }.GetHashCode(), quantity.GetHashCode());
        }
Пример #13
0
        public void Convert_ChangeType_QuantityType_EqualsQuantityType()
        {
            var quantity = HeatCapacity.FromBTUPerFahrenheitDegrees(1.0);

            Assert.Equal(QuantityType.HeatCapacity, Convert.ChangeType(quantity, typeof(QuantityType)));
        }
Пример #14
0
        public void Convert_ChangeType_SelfType_EqualsSelf()
        {
            var quantity = HeatCapacity.FromBTUPerFahrenheitDegrees(1.0);

            Assert.Equal(quantity, Convert.ChangeType(quantity, typeof(HeatCapacity)));
        }
Пример #15
0
        public void Convert_ToString_EqualsToString()
        {
            var quantity = HeatCapacity.FromBTUPerFahrenheitDegrees(1.0);

            Assert.Equal(quantity.ToString(), Convert.ToString(quantity));
        }
Пример #16
0
        public void Convert_ToInt16_EqualsValueAsSameType()
        {
            var quantity = HeatCapacity.FromBTUPerFahrenheitDegrees(1.0);

            Assert.Equal((short)quantity.Value, Convert.ToInt16(quantity));
        }
Пример #17
0
        public void Convert_ToSingle_EqualsValueAsSameType()
        {
            var quantity = HeatCapacity.FromBTUPerFahrenheitDegrees(1.0);

            Assert.Equal((float)quantity.Value, Convert.ToSingle(quantity));
        }
Пример #18
0
        public void Equals_NegativeRelativeTolerance_ThrowsArgumentOutOfRangeException()
        {
            var v = HeatCapacity.FromBTUPerFahrenheitDegrees(1);

            Assert.Throws <ArgumentOutOfRangeException>(() => v.Equals(HeatCapacity.FromBTUPerFahrenheitDegrees(1), -1, ComparisonType.Relative));
        }
Пример #19
0
        public void Convert_ToUInt64_EqualsValueAsSameType()
        {
            var quantity = HeatCapacity.FromBTUPerFahrenheitDegrees(1.0);

            Assert.Equal((ulong)quantity.Value, Convert.ToUInt64(quantity));
        }
Пример #20
0
        public void EqualsReturnsFalseOnTypeMismatch()
        {
            HeatCapacity btuperfahrenheitdegree = HeatCapacity.FromBTUPerFahrenheitDegrees(1);

            Assert.False(btuperfahrenheitdegree.Equals(new object()));
        }
Пример #21
0
        public void Convert_ChangeType_UnitType_EqualsUnit()
        {
            var quantity = HeatCapacity.FromBTUPerFahrenheitDegrees(1.0);

            Assert.Equal(quantity.Unit, Convert.ChangeType(quantity, typeof(HeatCapacityUnit)));
        }
Пример #22
0
        public void EqualsReturnsFalseOnNull()
        {
            HeatCapacity btuperfahrenheitdegree = HeatCapacity.FromBTUPerFahrenheitDegrees(1);

            Assert.False(btuperfahrenheitdegree.Equals(null));
        }
Пример #23
0
        public void Convert_ChangeType_BaseDimensions_EqualsBaseDimensions()
        {
            var quantity = HeatCapacity.FromBTUPerFahrenheitDegrees(1.0);

            Assert.Equal(HeatCapacity.BaseDimensions, Convert.ChangeType(quantity, typeof(BaseDimensions)));
        }
Пример #24
0
        public void ToString_NullArgs_ThrowsArgumentNullException()
        {
            var quantity = HeatCapacity.FromBTUPerFahrenheitDegrees(1.0);

            Assert.Throws <ArgumentNullException>(() => quantity.ToString(null, "g", null));
        }
Пример #25
0
        public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException()
        {
            var quantity = HeatCapacity.FromBTUPerFahrenheitDegrees(1.0);

            Assert.Throws <InvalidCastException>(() => Convert.ChangeType(quantity, typeof(QuantityFormatter)));
        }
Пример #26
0
        public void ToString_NullProvider_EqualsCurrentUICulture()
        {
            var quantity = HeatCapacity.FromBTUPerFahrenheitDegrees(1.0);

            Assert.Equal(quantity.ToString(CultureInfo.CurrentUICulture, "g"), quantity.ToString(null, "g"));
        }
Пример #27
0
        public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value)
        {
            var quantity = HeatCapacity.FromBTUPerFahrenheitDegrees(value);

            Assert.Equal(HeatCapacity.FromBTUPerFahrenheitDegrees(-value), -quantity);
        }
Пример #28
0
        public void Convert_ToDateTime_ThrowsInvalidCastException()
        {
            var quantity = HeatCapacity.FromBTUPerFahrenheitDegrees(1.0);

            Assert.Throws <InvalidCastException>(() => Convert.ToDateTime(quantity));
        }
Пример #29
0
 public static HeatCapacity BTUPerFahrenheitDegrees <T>(this T value) =>
 HeatCapacity.FromBTUPerFahrenheitDegrees(Convert.ToDouble(value));
Пример #30
0
        public void Convert_ToDecimal_EqualsValueAsSameType()
        {
            var quantity = HeatCapacity.FromBTUPerFahrenheitDegrees(1.0);

            Assert.Equal((decimal)quantity.Value, Convert.ToDecimal(quantity));
        }