public void As() { var decimalfractionpersecond = RatioChangeRate.FromDecimalFractionsPerSecond(1); AssertEx.EqualTolerance(DecimalFractionsPerSecondInOneDecimalFractionPerSecond, decimalfractionpersecond.As(RatioChangeRateUnit.DecimalFractionPerSecond), DecimalFractionsPerSecondTolerance); AssertEx.EqualTolerance(PercentsPerSecondInOneDecimalFractionPerSecond, decimalfractionpersecond.As(RatioChangeRateUnit.PercentPerSecond), PercentsPerSecondTolerance); }
public void DecimalFractionPerSecondToRatioChangeRateUnits() { RatioChangeRate decimalfractionpersecond = RatioChangeRate.FromDecimalFractionsPerSecond(1); AssertEx.EqualTolerance(DecimalFractionsPerSecondInOneDecimalFractionPerSecond, decimalfractionpersecond.DecimalFractionsPerSecond, DecimalFractionsPerSecondTolerance); AssertEx.EqualTolerance(PercentsPerSecondInOneDecimalFractionPerSecond, decimalfractionpersecond.PercentsPerSecond, PercentsPerSecondTolerance); }
public void Equals_RelativeTolerance_IsImplemented() { var v = RatioChangeRate.FromDecimalFractionsPerSecond(1); Assert.True(v.Equals(RatioChangeRate.FromDecimalFractionsPerSecond(1), DecimalFractionsPerSecondTolerance, ComparisonType.Relative)); Assert.False(v.Equals(RatioChangeRate.Zero, DecimalFractionsPerSecondTolerance, ComparisonType.Relative)); }
public void DefaultCtor_ReturnsQuantityWithZeroValueAndBaseUnit() { var quantity = new RatioChangeRate(); Assert.Equal(0, quantity.Value); Assert.Equal(RatioChangeRateUnit.DecimalFractionPerSecond, quantity.Unit); }
public void ConversionRoundTrip() { RatioChangeRate decimalfractionpersecond = RatioChangeRate.FromDecimalFractionsPerSecond(1); AssertEx.EqualTolerance(1, RatioChangeRate.FromDecimalFractionsPerSecond(decimalfractionpersecond.DecimalFractionsPerSecond).DecimalFractionsPerSecond, DecimalFractionsPerSecondTolerance); AssertEx.EqualTolerance(1, RatioChangeRate.FromPercentsPerSecond(decimalfractionpersecond.PercentsPerSecond).DecimalFractionsPerSecond, PercentsPerSecondTolerance); }
public void CompareToIsImplemented() { RatioChangeRate decimalfractionpersecond = RatioChangeRate.FromDecimalFractionsPerSecond(1); Assert.Equal(0, decimalfractionpersecond.CompareTo(decimalfractionpersecond)); Assert.True(decimalfractionpersecond.CompareTo(RatioChangeRate.Zero) > 0); Assert.True(RatioChangeRate.Zero.CompareTo(decimalfractionpersecond) < 0); }
public void Equals_SameType_IsImplemented() { var a = RatioChangeRate.FromDecimalFractionsPerSecond(1); var b = RatioChangeRate.FromDecimalFractionsPerSecond(2); Assert.True(a.Equals(a)); Assert.False(a.Equals(b)); }
public void Ctor_WithInfinityValue_CreateQuantityAndAffectInfinityValue() { var positiveInfinityQuantity = new RatioChangeRate(double.PositiveInfinity, RatioChangeRateUnit.DecimalFractionPerSecond); var negativeInfinityQuantity = new RatioChangeRate(double.NegativeInfinity, RatioChangeRateUnit.DecimalFractionPerSecond); Assert.True(double.IsPositiveInfinity(positiveInfinityQuantity.Value)); Assert.True(double.IsNegativeInfinity(negativeInfinityQuantity.Value)); }
public void FromDecimalFractionsPerSecond_WithInfinityValue_CreateQuantityAndAffectInfinityValue() { var positiveInfinityQuantity = RatioChangeRate.FromDecimalFractionsPerSecond(double.PositiveInfinity); var negativeInfinityQuantity = RatioChangeRate.FromDecimalFractionsPerSecond(double.NegativeInfinity); Assert.True(double.IsPositiveInfinity(positiveInfinityQuantity.Value)); Assert.True(double.IsNegativeInfinity(negativeInfinityQuantity.Value)); }
public void Equals_QuantityAsObject_IsImplemented() { object a = RatioChangeRate.FromDecimalFractionsPerSecond(1); object b = RatioChangeRate.FromDecimalFractionsPerSecond(2); Assert.True(a.Equals(a)); Assert.False(a.Equals(b)); Assert.False(a.Equals((object)null)); }
public void To_UnitSystem_ThrowsArgumentExceptionIfNotSupported() { var decimalfractionpersecond = RatioChangeRate.FromDecimalFractionsPerSecond(1); Assert.Throws <ArgumentException>(() => decimalfractionpersecond.ToUnit(UnitSystem.SI)); Assert.Throws <ArgumentException>(() => decimalfractionpersecond.ToUnit(UnitSystem.CGS)); Assert.Throws <ArgumentException>(() => decimalfractionpersecond.ToUnit(UnitSystem.BI)); Assert.Throws <ArgumentException>(() => decimalfractionpersecond.ToUnit(UnitSystem.EE)); Assert.Throws <ArgumentException>(() => decimalfractionpersecond.ToUnit(UnitSystem.USC)); Assert.Throws <ArgumentException>(() => decimalfractionpersecond.ToUnit(UnitSystem.FPS)); Assert.Throws <ArgumentException>(() => decimalfractionpersecond.ToUnit(UnitSystem.Astronomical)); }
public void ArithmeticOperators() { RatioChangeRate v = RatioChangeRate.FromDecimalFractionsPerSecond(1); AssertEx.EqualTolerance(-1, -v.DecimalFractionsPerSecond, DecimalFractionsPerSecondTolerance); AssertEx.EqualTolerance(2, (RatioChangeRate.FromDecimalFractionsPerSecond(3) - v).DecimalFractionsPerSecond, DecimalFractionsPerSecondTolerance); AssertEx.EqualTolerance(2, (v + v).DecimalFractionsPerSecond, DecimalFractionsPerSecondTolerance); AssertEx.EqualTolerance(10, (v * 10).DecimalFractionsPerSecond, DecimalFractionsPerSecondTolerance); AssertEx.EqualTolerance(10, (10 * v).DecimalFractionsPerSecond, DecimalFractionsPerSecondTolerance); AssertEx.EqualTolerance(2, (RatioChangeRate.FromDecimalFractionsPerSecond(10) / 5).DecimalFractionsPerSecond, DecimalFractionsPerSecondTolerance); AssertEx.EqualTolerance(2, RatioChangeRate.FromDecimalFractionsPerSecond(10) / RatioChangeRate.FromDecimalFractionsPerSecond(5), DecimalFractionsPerSecondTolerance); }
public void From_ValueAndUnit_ReturnsQuantityWithSameValueAndUnit() { var quantity00 = RatioChangeRate.From(1, RatioChangeRateUnit.DecimalFractionPerSecond); AssertEx.EqualTolerance(1, quantity00.DecimalFractionsPerSecond, DecimalFractionsPerSecondTolerance); Assert.Equal(RatioChangeRateUnit.DecimalFractionPerSecond, quantity00.Unit); var quantity01 = RatioChangeRate.From(1, RatioChangeRateUnit.PercentPerSecond); AssertEx.EqualTolerance(1, quantity01.PercentsPerSecond, PercentsPerSecondTolerance); Assert.Equal(RatioChangeRateUnit.PercentPerSecond, quantity01.Unit); }
public void ToUnit() { var decimalfractionpersecond = RatioChangeRate.FromDecimalFractionsPerSecond(1); var decimalfractionpersecondQuantity = decimalfractionpersecond.ToUnit(RatioChangeRateUnit.DecimalFractionPerSecond); AssertEx.EqualTolerance(DecimalFractionsPerSecondInOneDecimalFractionPerSecond, (double)decimalfractionpersecondQuantity.Value, DecimalFractionsPerSecondTolerance); Assert.Equal(RatioChangeRateUnit.DecimalFractionPerSecond, decimalfractionpersecondQuantity.Unit); var percentpersecondQuantity = decimalfractionpersecond.ToUnit(RatioChangeRateUnit.PercentPerSecond); AssertEx.EqualTolerance(PercentsPerSecondInOneDecimalFractionPerSecond, (double)percentpersecondQuantity.Value, PercentsPerSecondTolerance); Assert.Equal(RatioChangeRateUnit.PercentPerSecond, percentpersecondQuantity.Unit); }
public void ComparisonOperators() { RatioChangeRate oneDecimalFractionPerSecond = RatioChangeRate.FromDecimalFractionsPerSecond(1); RatioChangeRate twoDecimalFractionsPerSecond = RatioChangeRate.FromDecimalFractionsPerSecond(2); Assert.True(oneDecimalFractionPerSecond < twoDecimalFractionsPerSecond); Assert.True(oneDecimalFractionPerSecond <= twoDecimalFractionsPerSecond); Assert.True(twoDecimalFractionsPerSecond > oneDecimalFractionPerSecond); Assert.True(twoDecimalFractionsPerSecond >= oneDecimalFractionPerSecond); Assert.False(oneDecimalFractionPerSecond > twoDecimalFractionsPerSecond); Assert.False(oneDecimalFractionPerSecond >= twoDecimalFractionsPerSecond); Assert.False(twoDecimalFractionsPerSecond < oneDecimalFractionPerSecond); Assert.False(twoDecimalFractionsPerSecond <= oneDecimalFractionPerSecond); }
public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() { var quantity = new RatioChangeRate(value: 1, unit: RatioChangeRate.BaseUnit); Func <object> AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); if (SupportsSIUnitSystem) { var value = (decimal)AsWithSIUnitSystem(); Assert.Equal(1, value); } else { Assert.Throws <ArgumentException>(AsWithSIUnitSystem); } }
public void RatioChangeRate_QuantityInfo_ReturnsQuantityInfoDescribingQuantity() { var quantity = new RatioChangeRate(1, RatioChangeRateUnit.DecimalFractionPerSecond); QuantityInfo <RatioChangeRateUnit> quantityInfo = quantity.QuantityInfo; Assert.Equal(RatioChangeRate.Zero, quantityInfo.Zero); Assert.Equal("RatioChangeRate", quantityInfo.Name); Assert.Equal(QuantityType.RatioChangeRate, quantityInfo.QuantityType); var units = EnumUtils.GetEnumValues <RatioChangeRateUnit>().Except(new[] { RatioChangeRateUnit.Undefined }).ToArray(); var unitNames = units.Select(x => x.ToString()); // Obsolete members Assert.Equal(units, quantityInfo.Units); Assert.Equal(unitNames, quantityInfo.UnitNames); }
public void EqualityOperators() { var a = RatioChangeRate.FromDecimalFractionsPerSecond(1); var b = RatioChangeRate.FromDecimalFractionsPerSecond(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_ToUInt64_EqualsValueAsSameType() { var quantity = RatioChangeRate.FromDecimalFractionsPerSecond(1.0); Assert.Equal((ulong)quantity.Value, Convert.ToUInt64(quantity)); }
public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) { var quantity = RatioChangeRate.FromDecimalFractionsPerSecond(value); Assert.Equal(RatioChangeRate.FromDecimalFractionsPerSecond(-value), -quantity); }
public void GetHashCode_Equals() { var quantity = RatioChangeRate.FromDecimalFractionsPerSecond(1.0); Assert.Equal(new { RatioChangeRate.QuantityType, quantity.Value, quantity.Unit }.GetHashCode(), quantity.GetHashCode()); }
public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() { var quantity = RatioChangeRate.FromDecimalFractionsPerSecond(1.0); Assert.Throws <InvalidCastException>(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); }
public void Convert_ChangeType_BaseDimensions_EqualsBaseDimensions() { var quantity = RatioChangeRate.FromDecimalFractionsPerSecond(1.0); Assert.Equal(RatioChangeRate.BaseDimensions, Convert.ChangeType(quantity, typeof(BaseDimensions))); }
public void Convert_ChangeType_QuantityType_EqualsQuantityType() { var quantity = RatioChangeRate.FromDecimalFractionsPerSecond(1.0); Assert.Equal(QuantityType.RatioChangeRate, Convert.ChangeType(quantity, typeof(QuantityType))); }
public void Convert_ChangeType_UnitType_EqualsUnit() { var quantity = RatioChangeRate.FromDecimalFractionsPerSecond(1.0); Assert.Equal(quantity.Unit, Convert.ChangeType(quantity, typeof(RatioChangeRateUnit))); }
public static RatioChangeRate DecimalFractionsPerSecond <T>(this T value) => RatioChangeRate.FromDecimalFractionsPerSecond(Convert.ToDouble(value));
public void Convert_ToString_EqualsToString() { var quantity = RatioChangeRate.FromDecimalFractionsPerSecond(1.0); Assert.Equal(quantity.ToString(), Convert.ToString(quantity)); }
public void Convert_ToSingle_EqualsValueAsSameType() { var quantity = RatioChangeRate.FromDecimalFractionsPerSecond(1.0); Assert.Equal((float)quantity.Value, Convert.ToSingle(quantity)); }
public static RatioChangeRate PercentsPerSecond <T>(this T value) => RatioChangeRate.FromPercentsPerSecond(Convert.ToDouble(value));
public void Convert_ChangeType_SelfType_EqualsSelf() { var quantity = RatioChangeRate.FromDecimalFractionsPerSecond(1.0); Assert.Equal(quantity, Convert.ChangeType(quantity, typeof(RatioChangeRate))); }