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 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 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 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_SameType_IsImplemented() { var a = RatioChangeRate.FromDecimalFractionsPerSecond(1); var b = RatioChangeRate.FromDecimalFractionsPerSecond(2); Assert.True(a.Equals(a)); Assert.False(a.Equals(b)); }
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_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 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 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_ToSingle_EqualsValueAsSameType() { var quantity = RatioChangeRate.FromDecimalFractionsPerSecond(1.0); Assert.Equal((float)quantity.Value, Convert.ToSingle(quantity)); }
public void Convert_ToDateTime_ThrowsInvalidCastException() { var quantity = RatioChangeRate.FromDecimalFractionsPerSecond(1.0); Assert.Throws <InvalidCastException>(() => Convert.ToDateTime(quantity)); }
public void ToString_NullProvider_EqualsCurrentUICulture() { var quantity = RatioChangeRate.FromDecimalFractionsPerSecond(1.0); Assert.Equal(quantity.ToString(CultureInfo.CurrentUICulture, "g"), quantity.ToString(null, "g")); }
public void ToString_NullArgs_ThrowsArgumentNullException() { var quantity = RatioChangeRate.FromDecimalFractionsPerSecond(1.0); Assert.Throws <ArgumentNullException>(() => quantity.ToString(null, "g", null)); }
public void Convert_ChangeType_SelfType_EqualsSelf() { var quantity = RatioChangeRate.FromDecimalFractionsPerSecond(1.0); Assert.Equal(quantity, Convert.ChangeType(quantity, typeof(RatioChangeRate))); }
public void Convert_ChangeType_QuantityType_EqualsQuantityType() { var quantity = RatioChangeRate.FromDecimalFractionsPerSecond(1.0); Assert.Equal(QuantityType.RatioChangeRate, Convert.ChangeType(quantity, typeof(QuantityType))); }
public void Convert_ToString_EqualsToString() { var quantity = RatioChangeRate.FromDecimalFractionsPerSecond(1.0); Assert.Equal(quantity.ToString(), Convert.ToString(quantity)); }
public void Convert_ToUInt64_EqualsValueAsSameType() { var quantity = RatioChangeRate.FromDecimalFractionsPerSecond(1.0); Assert.Equal((ulong)quantity.Value, Convert.ToUInt64(quantity)); }
public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() { var quantity = RatioChangeRate.FromDecimalFractionsPerSecond(1.0); Assert.Throws <InvalidCastException>(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); }
public void Convert_ChangeType_UnitType_EqualsUnit() { var quantity = RatioChangeRate.FromDecimalFractionsPerSecond(1.0); Assert.Equal(quantity.Unit, Convert.ChangeType(quantity, typeof(RatioChangeRateUnit))); }
public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) { var quantity = RatioChangeRate.FromDecimalFractionsPerSecond(value); Assert.Equal(RatioChangeRate.FromDecimalFractionsPerSecond(-value), -quantity); }
public void Convert_ChangeType_BaseDimensions_EqualsBaseDimensions() { var quantity = RatioChangeRate.FromDecimalFractionsPerSecond(1.0); Assert.Equal(RatioChangeRate.BaseDimensions, Convert.ChangeType(quantity, typeof(BaseDimensions))); }
public void Equals_NegativeRelativeTolerance_ThrowsArgumentOutOfRangeException() { var v = RatioChangeRate.FromDecimalFractionsPerSecond(1); Assert.Throws <ArgumentOutOfRangeException>(() => v.Equals(RatioChangeRate.FromDecimalFractionsPerSecond(1), -1, ComparisonType.Relative)); }
public void GetHashCode_Equals() { var quantity = RatioChangeRate.FromDecimalFractionsPerSecond(1.0); Assert.Equal(new { RatioChangeRate.QuantityType, quantity.Value, quantity.Unit }.GetHashCode(), quantity.GetHashCode()); }
public void EqualsReturnsFalseOnTypeMismatch() { RatioChangeRate decimalfractionpersecond = RatioChangeRate.FromDecimalFractionsPerSecond(1); Assert.False(decimalfractionpersecond.Equals(new object())); }
public static RatioChangeRate DecimalFractionsPerSecond <T>(this T value) => RatioChangeRate.FromDecimalFractionsPerSecond(Convert.ToDouble(value));
public void EqualsReturnsFalseOnNull() { RatioChangeRate decimalfractionpersecond = RatioChangeRate.FromDecimalFractionsPerSecond(1); Assert.False(decimalfractionpersecond.Equals(null)); }