public void ToUnit() { var metertothesixth = WarpingMomentOfInertia.FromMetersToTheSixth(1); var centimetertothesixthQuantity = metertothesixth.ToUnit(WarpingMomentOfInertiaUnit.CentimeterToTheSixth); AssertEx.EqualTolerance(CentimetersToTheSixthInOneMeterToTheSixth, (decimal)centimetertothesixthQuantity.Value, CentimetersToTheSixthTolerance); Assert.Equal(WarpingMomentOfInertiaUnit.CentimeterToTheSixth, centimetertothesixthQuantity.Unit); var decimetertothesixthQuantity = metertothesixth.ToUnit(WarpingMomentOfInertiaUnit.DecimeterToTheSixth); AssertEx.EqualTolerance(DecimetersToTheSixthInOneMeterToTheSixth, (decimal)decimetertothesixthQuantity.Value, DecimetersToTheSixthTolerance); Assert.Equal(WarpingMomentOfInertiaUnit.DecimeterToTheSixth, decimetertothesixthQuantity.Unit); var foottothesixthQuantity = metertothesixth.ToUnit(WarpingMomentOfInertiaUnit.FootToTheSixth); AssertEx.EqualTolerance(FeetToTheSixthInOneMeterToTheSixth, (decimal)foottothesixthQuantity.Value, FeetToTheSixthTolerance); Assert.Equal(WarpingMomentOfInertiaUnit.FootToTheSixth, foottothesixthQuantity.Unit); var inchtothesixthQuantity = metertothesixth.ToUnit(WarpingMomentOfInertiaUnit.InchToTheSixth); AssertEx.EqualTolerance(InchesToTheSixthInOneMeterToTheSixth, (decimal)inchtothesixthQuantity.Value, InchesToTheSixthTolerance); Assert.Equal(WarpingMomentOfInertiaUnit.InchToTheSixth, inchtothesixthQuantity.Unit); var metertothesixthQuantity = metertothesixth.ToUnit(WarpingMomentOfInertiaUnit.MeterToTheSixth); AssertEx.EqualTolerance(MetersToTheSixthInOneMeterToTheSixth, (decimal)metertothesixthQuantity.Value, MetersToTheSixthTolerance); Assert.Equal(WarpingMomentOfInertiaUnit.MeterToTheSixth, metertothesixthQuantity.Unit); var millimetertothesixthQuantity = metertothesixth.ToUnit(WarpingMomentOfInertiaUnit.MillimeterToTheSixth); AssertEx.EqualTolerance(MillimetersToTheSixthInOneMeterToTheSixth, (decimal)millimetertothesixthQuantity.Value, MillimetersToTheSixthTolerance); Assert.Equal(WarpingMomentOfInertiaUnit.MillimeterToTheSixth, millimetertothesixthQuantity.Unit); }
public void From_ValueAndUnit_ReturnsQuantityWithSameValueAndUnit() { var quantity00 = WarpingMomentOfInertia.From(1, WarpingMomentOfInertiaUnit.CentimeterToTheSixth); AssertEx.EqualTolerance(1, quantity00.CentimetersToTheSixth, CentimetersToTheSixthTolerance); Assert.Equal(WarpingMomentOfInertiaUnit.CentimeterToTheSixth, quantity00.Unit); var quantity01 = WarpingMomentOfInertia.From(1, WarpingMomentOfInertiaUnit.DecimeterToTheSixth); AssertEx.EqualTolerance(1, quantity01.DecimetersToTheSixth, DecimetersToTheSixthTolerance); Assert.Equal(WarpingMomentOfInertiaUnit.DecimeterToTheSixth, quantity01.Unit); var quantity02 = WarpingMomentOfInertia.From(1, WarpingMomentOfInertiaUnit.FootToTheSixth); AssertEx.EqualTolerance(1, quantity02.FeetToTheSixth, FeetToTheSixthTolerance); Assert.Equal(WarpingMomentOfInertiaUnit.FootToTheSixth, quantity02.Unit); var quantity03 = WarpingMomentOfInertia.From(1, WarpingMomentOfInertiaUnit.InchToTheSixth); AssertEx.EqualTolerance(1, quantity03.InchesToTheSixth, InchesToTheSixthTolerance); Assert.Equal(WarpingMomentOfInertiaUnit.InchToTheSixth, quantity03.Unit); var quantity04 = WarpingMomentOfInertia.From(1, WarpingMomentOfInertiaUnit.MeterToTheSixth); AssertEx.EqualTolerance(1, quantity04.MetersToTheSixth, MetersToTheSixthTolerance); Assert.Equal(WarpingMomentOfInertiaUnit.MeterToTheSixth, quantity04.Unit); var quantity05 = WarpingMomentOfInertia.From(1, WarpingMomentOfInertiaUnit.MillimeterToTheSixth); AssertEx.EqualTolerance(1, quantity05.MillimetersToTheSixth, MillimetersToTheSixthTolerance); Assert.Equal(WarpingMomentOfInertiaUnit.MillimeterToTheSixth, quantity05.Unit); }
public void DefaultCtor_ReturnsQuantityWithZeroValueAndBaseUnit() { var quantity = new WarpingMomentOfInertia(); Assert.Equal(0, quantity.Value); Assert.Equal(WarpingMomentOfInertiaUnit.MeterToTheSixth, quantity.Unit); }
public void Equals_RelativeTolerance_IsImplemented() { var v = WarpingMomentOfInertia.FromMetersToTheSixth(1); Assert.True(v.Equals(WarpingMomentOfInertia.FromMetersToTheSixth(1), MetersToTheSixthTolerance, ComparisonType.Relative)); Assert.False(v.Equals(WarpingMomentOfInertia.Zero, MetersToTheSixthTolerance, ComparisonType.Relative)); }
public void CompareToIsImplemented() { WarpingMomentOfInertia metertothesixth = WarpingMomentOfInertia.FromMetersToTheSixth(1); Assert.Equal(0, metertothesixth.CompareTo(metertothesixth)); Assert.True(metertothesixth.CompareTo(WarpingMomentOfInertia.Zero) > 0); Assert.True(WarpingMomentOfInertia.Zero.CompareTo(metertothesixth) < 0); }
public void Equals_SameType_IsImplemented() { var a = WarpingMomentOfInertia.FromMetersToTheSixth(1); var b = WarpingMomentOfInertia.FromMetersToTheSixth(2); Assert.True(a.Equals(a)); Assert.False(a.Equals(b)); }
public void ToUnit(WarpingMomentOfInertiaUnit unit) { var inBaseUnits = WarpingMomentOfInertia.From(1.0, WarpingMomentOfInertia.BaseUnit); var converted = inBaseUnits.ToUnit(unit); var conversionFactor = GetConversionFactor(unit); AssertEx.EqualTolerance(conversionFactor.UnitsInBaseUnit, (double)converted.Value, conversionFactor.Tolerence); Assert.Equal(unit, converted.Unit); }
public void Equals_QuantityAsObject_IsImplemented() { object a = WarpingMomentOfInertia.FromMetersToTheSixth(1); object b = WarpingMomentOfInertia.FromMetersToTheSixth(2); Assert.True(a.Equals(a)); Assert.False(a.Equals(b)); Assert.False(a.Equals((object)null)); }
public void As() { var metertothesixth = WarpingMomentOfInertia.FromMetersToTheSixth(1); AssertEx.EqualTolerance(CentimetersToTheSixthInOneMeterToTheSixth, metertothesixth.As(WarpingMomentOfInertiaUnit.CentimeterToTheSixth), CentimetersToTheSixthTolerance); AssertEx.EqualTolerance(DecimetersToTheSixthInOneMeterToTheSixth, metertothesixth.As(WarpingMomentOfInertiaUnit.DecimeterToTheSixth), DecimetersToTheSixthTolerance); AssertEx.EqualTolerance(FeetToTheSixthInOneMeterToTheSixth, metertothesixth.As(WarpingMomentOfInertiaUnit.FootToTheSixth), FeetToTheSixthTolerance); AssertEx.EqualTolerance(InchesToTheSixthInOneMeterToTheSixth, metertothesixth.As(WarpingMomentOfInertiaUnit.InchToTheSixth), InchesToTheSixthTolerance); AssertEx.EqualTolerance(MetersToTheSixthInOneMeterToTheSixth, metertothesixth.As(WarpingMomentOfInertiaUnit.MeterToTheSixth), MetersToTheSixthTolerance); AssertEx.EqualTolerance(MillimetersToTheSixthInOneMeterToTheSixth, metertothesixth.As(WarpingMomentOfInertiaUnit.MillimeterToTheSixth), MillimetersToTheSixthTolerance); }
public void MeterToTheSixthToWarpingMomentOfInertiaUnits() { WarpingMomentOfInertia metertothesixth = WarpingMomentOfInertia.FromMetersToTheSixth(1); AssertEx.EqualTolerance(CentimetersToTheSixthInOneMeterToTheSixth, metertothesixth.CentimetersToTheSixth, CentimetersToTheSixthTolerance); AssertEx.EqualTolerance(DecimetersToTheSixthInOneMeterToTheSixth, metertothesixth.DecimetersToTheSixth, DecimetersToTheSixthTolerance); AssertEx.EqualTolerance(FeetToTheSixthInOneMeterToTheSixth, metertothesixth.FeetToTheSixth, FeetToTheSixthTolerance); AssertEx.EqualTolerance(InchesToTheSixthInOneMeterToTheSixth, metertothesixth.InchesToTheSixth, InchesToTheSixthTolerance); AssertEx.EqualTolerance(MetersToTheSixthInOneMeterToTheSixth, metertothesixth.MetersToTheSixth, MetersToTheSixthTolerance); AssertEx.EqualTolerance(MillimetersToTheSixthInOneMeterToTheSixth, metertothesixth.MillimetersToTheSixth, MillimetersToTheSixthTolerance); }
public void ConversionRoundTrip() { WarpingMomentOfInertia metertothesixth = WarpingMomentOfInertia.FromMetersToTheSixth(1); AssertEx.EqualTolerance(1, WarpingMomentOfInertia.FromCentimetersToTheSixth(metertothesixth.CentimetersToTheSixth).MetersToTheSixth, CentimetersToTheSixthTolerance); AssertEx.EqualTolerance(1, WarpingMomentOfInertia.FromDecimetersToTheSixth(metertothesixth.DecimetersToTheSixth).MetersToTheSixth, DecimetersToTheSixthTolerance); AssertEx.EqualTolerance(1, WarpingMomentOfInertia.FromFeetToTheSixth(metertothesixth.FeetToTheSixth).MetersToTheSixth, FeetToTheSixthTolerance); AssertEx.EqualTolerance(1, WarpingMomentOfInertia.FromInchesToTheSixth(metertothesixth.InchesToTheSixth).MetersToTheSixth, InchesToTheSixthTolerance); AssertEx.EqualTolerance(1, WarpingMomentOfInertia.FromMetersToTheSixth(metertothesixth.MetersToTheSixth).MetersToTheSixth, MetersToTheSixthTolerance); AssertEx.EqualTolerance(1, WarpingMomentOfInertia.FromMillimetersToTheSixth(metertothesixth.MillimetersToTheSixth).MetersToTheSixth, MillimetersToTheSixthTolerance); }
public void ArithmeticOperators() { WarpingMomentOfInertia v = WarpingMomentOfInertia.FromMetersToTheSixth(1); AssertEx.EqualTolerance(-1, -v.MetersToTheSixth, MetersToTheSixthTolerance); AssertEx.EqualTolerance(2, (WarpingMomentOfInertia.FromMetersToTheSixth(3)-v).MetersToTheSixth, MetersToTheSixthTolerance); AssertEx.EqualTolerance(2, (v + v).MetersToTheSixth, MetersToTheSixthTolerance); AssertEx.EqualTolerance(10, (v*10).MetersToTheSixth, MetersToTheSixthTolerance); AssertEx.EqualTolerance(10, (10*v).MetersToTheSixth, MetersToTheSixthTolerance); AssertEx.EqualTolerance(2, (WarpingMomentOfInertia.FromMetersToTheSixth(10)/5).MetersToTheSixth, MetersToTheSixthTolerance); AssertEx.EqualTolerance(2, WarpingMomentOfInertia.FromMetersToTheSixth(10)/WarpingMomentOfInertia.FromMetersToTheSixth(5), MetersToTheSixthTolerance); }
public void To_UnitSystem_ThrowsArgumentExceptionIfNotSupported() { var metertothesixth = WarpingMomentOfInertia.FromMetersToTheSixth(1); Assert.Throws <ArgumentException>(() => metertothesixth.ToUnit(UnitSystem.SI)); Assert.Throws <ArgumentException>(() => metertothesixth.ToUnit(UnitSystem.CGS)); Assert.Throws <ArgumentException>(() => metertothesixth.ToUnit(UnitSystem.BI)); Assert.Throws <ArgumentException>(() => metertothesixth.ToUnit(UnitSystem.EE)); Assert.Throws <ArgumentException>(() => metertothesixth.ToUnit(UnitSystem.USC)); Assert.Throws <ArgumentException>(() => metertothesixth.ToUnit(UnitSystem.FPS)); Assert.Throws <ArgumentException>(() => metertothesixth.ToUnit(UnitSystem.Astronomical)); }
public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(WarpingMomentOfInertiaUnit unit) { // See if there is a unit available that is not the base unit. var fromUnit = WarpingMomentOfInertia.Units.FirstOrDefault(u => u != WarpingMomentOfInertia.BaseUnit && u != WarpingMomentOfInertiaUnit.Undefined); // If there is only one unit for the quantity, we must use the base unit. if (fromUnit == WarpingMomentOfInertiaUnit.Undefined) fromUnit = WarpingMomentOfInertia.BaseUnit; var quantity = WarpingMomentOfInertia.From(3.0, fromUnit); var converted = quantity.ToUnit(unit); Assert.Equal(converted.Unit, unit); }
public void ComparisonOperators() { WarpingMomentOfInertia oneMeterToTheSixth = WarpingMomentOfInertia.FromMetersToTheSixth(1); WarpingMomentOfInertia twoMetersToTheSixth = WarpingMomentOfInertia.FromMetersToTheSixth(2); Assert.True(oneMeterToTheSixth < twoMetersToTheSixth); Assert.True(oneMeterToTheSixth <= twoMetersToTheSixth); Assert.True(twoMetersToTheSixth > oneMeterToTheSixth); Assert.True(twoMetersToTheSixth >= oneMeterToTheSixth); Assert.False(oneMeterToTheSixth > twoMetersToTheSixth); Assert.False(oneMeterToTheSixth >= twoMetersToTheSixth); Assert.False(twoMetersToTheSixth < oneMeterToTheSixth); Assert.False(twoMetersToTheSixth <= oneMeterToTheSixth); }
public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() { var quantity = new WarpingMomentOfInertia(value: 1, unit: WarpingMomentOfInertia.BaseUnit); Func<object> AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); if (SupportsSIUnitSystem) { var value = (double) AsWithSIUnitSystem(); Assert.Equal(1, value); } else { Assert.Throws<ArgumentException>(AsWithSIUnitSystem); } }
public void WarpingMomentOfInertia_QuantityInfo_ReturnsQuantityInfoDescribingQuantity() { var quantity = new WarpingMomentOfInertia(1, WarpingMomentOfInertiaUnit.MeterToTheSixth); QuantityInfo<WarpingMomentOfInertiaUnit> quantityInfo = quantity.QuantityInfo; Assert.Equal(WarpingMomentOfInertia.Zero, quantityInfo.Zero); Assert.Equal("WarpingMomentOfInertia", quantityInfo.Name); Assert.Equal(QuantityType.WarpingMomentOfInertia, quantityInfo.QuantityType); var units = EnumUtils.GetEnumValues<WarpingMomentOfInertiaUnit>().Except(new[] {WarpingMomentOfInertiaUnit.Undefined}).OrderBy(x => x.ToString()).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 = WarpingMomentOfInertia.FromMetersToTheSixth(1); var b = WarpingMomentOfInertia.FromMetersToTheSixth(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_ChangeType_InvalidType_ThrowsInvalidCastException() { var quantity = WarpingMomentOfInertia.FromMetersToTheSixth(1.0); Assert.Throws<InvalidCastException>(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); }
public void Convert_ChangeType_BaseDimensions_EqualsBaseDimensions() { var quantity = WarpingMomentOfInertia.FromMetersToTheSixth(1.0); Assert.Equal(WarpingMomentOfInertia.BaseDimensions, Convert.ChangeType(quantity, typeof(BaseDimensions))); }
public void Convert_ChangeType_QuantityInfo_EqualsQuantityInfo() { var quantity = WarpingMomentOfInertia.FromMetersToTheSixth(1.0); Assert.Equal(WarpingMomentOfInertia.Info, Convert.ChangeType(quantity, typeof(QuantityInfo))); }
public void Convert_ChangeType_UnitType_EqualsUnit() { var quantity = WarpingMomentOfInertia.FromMetersToTheSixth(1.0); Assert.Equal(quantity.Unit, Convert.ChangeType(quantity, typeof(WarpingMomentOfInertiaUnit))); }
public void Convert_ChangeType_SelfType_EqualsSelf() { var quantity = WarpingMomentOfInertia.FromMetersToTheSixth(1.0); Assert.Equal(quantity, Convert.ChangeType(quantity, typeof(WarpingMomentOfInertia))); }
public void Convert_ToUInt64_EqualsValueAsSameType() { var quantity = WarpingMomentOfInertia.FromMetersToTheSixth(1.0); Assert.Equal((ulong)quantity.Value, Convert.ToUInt64(quantity)); }
public void Convert_ToSingle_EqualsValueAsSameType() { var quantity = WarpingMomentOfInertia.FromMetersToTheSixth(1.0); Assert.Equal((float)quantity.Value, Convert.ToSingle(quantity)); }
public void Convert_ToDateTime_ThrowsInvalidCastException() { var quantity = WarpingMomentOfInertia.FromMetersToTheSixth(1.0); Assert.Throws<InvalidCastException>(() => Convert.ToDateTime(quantity)); }
public void ToString_NullProvider_EqualsCurrentUICulture() { var quantity = WarpingMomentOfInertia.FromMetersToTheSixth(1.0); Assert.Equal(quantity.ToString(CultureInfo.CurrentUICulture, "g"), quantity.ToString(null, "g")); }
public void GetHashCode_Equals() { var quantity = WarpingMomentOfInertia.FromMetersToTheSixth(1.0); Assert.Equal(new {WarpingMomentOfInertia.Info.Name, quantity.Value, quantity.Unit}.GetHashCode(), quantity.GetHashCode()); }
public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) { var quantity = WarpingMomentOfInertia.FromMetersToTheSixth(value); Assert.Equal(WarpingMomentOfInertia.FromMetersToTheSixth(-value), -quantity); }
public void Convert_ToString_EqualsToString() { var quantity = WarpingMomentOfInertia.FromMetersToTheSixth(1.0); Assert.Equal(quantity.ToString(), Convert.ToString(quantity)); }