Exemple #1
0
        public void ForcePerLengthTimesAreaEqualTorque()
        {
            Torque torque = ForcePerLength.FromNewtonsPerMeter(10) * Area.FromSquareMeters(9);

            Assert.Equal(torque, Torque.FromNewtonMeters(90));
        }
Exemple #2
0
        public void ToString_NullArgs_ThrowsArgumentNullException()
        {
            var quantity = Torque.FromNewtonMeters(1.0);

            Assert.Throws <ArgumentNullException>(() => quantity.ToString(null, "g", null));
        }
Exemple #3
0
        public void Convert_ToDateTime_ThrowsInvalidCastException()
        {
            var quantity = Torque.FromNewtonMeters(1.0);

            Assert.Throws <InvalidCastException>(() => Convert.ToDateTime(quantity));
        }
Exemple #4
0
        public void CompareToThrowsOnNull()
        {
            Torque newtonmeter = Torque.FromNewtonMeters(1);

            Assert.Throws <ArgumentNullException>(() => newtonmeter.CompareTo(null));
        }
Exemple #5
0
        public void EqualsReturnsFalseOnTypeMismatch()
        {
            Torque newtonmeter = Torque.FromNewtonMeters(1);

            Assert.False(newtonmeter.Equals(new object()));
        }
Exemple #6
0
 public void FromNewtonMeters_WithNanValue_ThrowsArgumentException()
 {
     Assert.Throws <ArgumentException>(() => Torque.FromNewtonMeters(double.NaN));
 }
Exemple #7
0
        public void ToBaseUnit_ReturnsQuantityWithBaseUnit()
        {
            var quantityInBaseUnit = Torque.FromNewtonMeters(1).ToBaseUnit();

            Assert.Equal(Torque.BaseUnit, quantityInBaseUnit.Unit);
        }
Exemple #8
0
 /// <inheritdoc cref="Torque.FromNewtonMeters(double?)"/>
 public static Torque?NewtonMeters(this float?value) => Torque.FromNewtonMeters(value);
Exemple #9
0
 /// <inheritdoc cref="Torque.FromNewtonMeters(double)"/>
 public static Torque NewtonMeters(this decimal value) => Torque.FromNewtonMeters(Convert.ToDouble(value));
Exemple #10
0
 /// <inheritdoc cref="Torque.FromNewtonMeters(double)"/>
 public static Torque NewtonMeters(this long value) => Torque.FromNewtonMeters(value);
Exemple #11
0
 /// <inheritdoc cref="Torque.FromNewtonMeters(double?)"/>
 public static Torque?NewtonMeters(this double?value) => Torque.FromNewtonMeters(value);
Exemple #12
0
        public void PowerDividedByTorqueEqualsRotationalSpeed()
        {
            RotationalSpeed rotationalSpeed = Power.FromWatts(15.0) / Torque.FromNewtonMeters(3);

            Assert.Equal(rotationalSpeed, RotationalSpeed.FromRadiansPerSecond(5));
        }
Exemple #13
0
        public void PowerDividedByRotationalSpeedEqualsForce()
        {
            Torque torque = Power.FromWatts(15.0) / RotationalSpeed.FromRadiansPerSecond(3);

            Assert.Equal(torque, Torque.FromNewtonMeters(5));
        }
 public static Torque NewtonMeters <T>(this T value) =>
 Torque.FromNewtonMeters(Convert.ToDouble(value));
Exemple #15
0
        public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value)
        {
            var quantity = Torque.FromNewtonMeters(value);

            Assert.Equal(Torque.FromNewtonMeters(-value), -quantity);
        }
Exemple #16
0
 /// <inheritdoc cref="Torque.FromNewtonMeters(double?)"/>
 public static Torque?NewtonMeters(this decimal?value) => Torque.FromNewtonMeters(value == null ? (double?)null : Convert.ToDouble(value.Value));
Exemple #17
0
 public void FromNewtonMeters_WithInfinityValue_ThrowsArgumentException()
 {
     Assert.Throws <ArgumentException>(() => Torque.FromNewtonMeters(double.PositiveInfinity));
     Assert.Throws <ArgumentException>(() => Torque.FromNewtonMeters(double.NegativeInfinity));
 }
Exemple #18
0
        public void Convert_ChangeType_SelfType_EqualsSelf()
        {
            var quantity = Torque.FromNewtonMeters(1.0);

            Assert.Equal(quantity, Convert.ChangeType(quantity, typeof(Torque)));
        }
Exemple #19
0
        public void ToUnit()
        {
            var newtonmeter = Torque.FromNewtonMeters(1);

            var kilogramforcecentimeterQuantity = newtonmeter.ToUnit(TorqueUnit.KilogramForceCentimeter);

            AssertEx.EqualTolerance(KilogramForceCentimetersInOneNewtonMeter, (double)kilogramforcecentimeterQuantity.Value, KilogramForceCentimetersTolerance);
            Assert.Equal(TorqueUnit.KilogramForceCentimeter, kilogramforcecentimeterQuantity.Unit);

            var kilogramforcemeterQuantity = newtonmeter.ToUnit(TorqueUnit.KilogramForceMeter);

            AssertEx.EqualTolerance(KilogramForceMetersInOneNewtonMeter, (double)kilogramforcemeterQuantity.Value, KilogramForceMetersTolerance);
            Assert.Equal(TorqueUnit.KilogramForceMeter, kilogramforcemeterQuantity.Unit);

            var kilogramforcemillimeterQuantity = newtonmeter.ToUnit(TorqueUnit.KilogramForceMillimeter);

            AssertEx.EqualTolerance(KilogramForceMillimetersInOneNewtonMeter, (double)kilogramforcemillimeterQuantity.Value, KilogramForceMillimetersTolerance);
            Assert.Equal(TorqueUnit.KilogramForceMillimeter, kilogramforcemillimeterQuantity.Unit);

            var kilonewtoncentimeterQuantity = newtonmeter.ToUnit(TorqueUnit.KilonewtonCentimeter);

            AssertEx.EqualTolerance(KilonewtonCentimetersInOneNewtonMeter, (double)kilonewtoncentimeterQuantity.Value, KilonewtonCentimetersTolerance);
            Assert.Equal(TorqueUnit.KilonewtonCentimeter, kilonewtoncentimeterQuantity.Unit);

            var kilonewtonmeterQuantity = newtonmeter.ToUnit(TorqueUnit.KilonewtonMeter);

            AssertEx.EqualTolerance(KilonewtonMetersInOneNewtonMeter, (double)kilonewtonmeterQuantity.Value, KilonewtonMetersTolerance);
            Assert.Equal(TorqueUnit.KilonewtonMeter, kilonewtonmeterQuantity.Unit);

            var kilonewtonmillimeterQuantity = newtonmeter.ToUnit(TorqueUnit.KilonewtonMillimeter);

            AssertEx.EqualTolerance(KilonewtonMillimetersInOneNewtonMeter, (double)kilonewtonmillimeterQuantity.Value, KilonewtonMillimetersTolerance);
            Assert.Equal(TorqueUnit.KilonewtonMillimeter, kilonewtonmillimeterQuantity.Unit);

            var kilopoundforcefootQuantity = newtonmeter.ToUnit(TorqueUnit.KilopoundForceFoot);

            AssertEx.EqualTolerance(KilopoundForceFeetInOneNewtonMeter, (double)kilopoundforcefootQuantity.Value, KilopoundForceFeetTolerance);
            Assert.Equal(TorqueUnit.KilopoundForceFoot, kilopoundforcefootQuantity.Unit);

            var kilopoundforceinchQuantity = newtonmeter.ToUnit(TorqueUnit.KilopoundForceInch);

            AssertEx.EqualTolerance(KilopoundForceInchesInOneNewtonMeter, (double)kilopoundforceinchQuantity.Value, KilopoundForceInchesTolerance);
            Assert.Equal(TorqueUnit.KilopoundForceInch, kilopoundforceinchQuantity.Unit);

            var meganewtoncentimeterQuantity = newtonmeter.ToUnit(TorqueUnit.MeganewtonCentimeter);

            AssertEx.EqualTolerance(MeganewtonCentimetersInOneNewtonMeter, (double)meganewtoncentimeterQuantity.Value, MeganewtonCentimetersTolerance);
            Assert.Equal(TorqueUnit.MeganewtonCentimeter, meganewtoncentimeterQuantity.Unit);

            var meganewtonmeterQuantity = newtonmeter.ToUnit(TorqueUnit.MeganewtonMeter);

            AssertEx.EqualTolerance(MeganewtonMetersInOneNewtonMeter, (double)meganewtonmeterQuantity.Value, MeganewtonMetersTolerance);
            Assert.Equal(TorqueUnit.MeganewtonMeter, meganewtonmeterQuantity.Unit);

            var meganewtonmillimeterQuantity = newtonmeter.ToUnit(TorqueUnit.MeganewtonMillimeter);

            AssertEx.EqualTolerance(MeganewtonMillimetersInOneNewtonMeter, (double)meganewtonmillimeterQuantity.Value, MeganewtonMillimetersTolerance);
            Assert.Equal(TorqueUnit.MeganewtonMillimeter, meganewtonmillimeterQuantity.Unit);

            var megapoundforcefootQuantity = newtonmeter.ToUnit(TorqueUnit.MegapoundForceFoot);

            AssertEx.EqualTolerance(MegapoundForceFeetInOneNewtonMeter, (double)megapoundforcefootQuantity.Value, MegapoundForceFeetTolerance);
            Assert.Equal(TorqueUnit.MegapoundForceFoot, megapoundforcefootQuantity.Unit);

            var megapoundforceinchQuantity = newtonmeter.ToUnit(TorqueUnit.MegapoundForceInch);

            AssertEx.EqualTolerance(MegapoundForceInchesInOneNewtonMeter, (double)megapoundforceinchQuantity.Value, MegapoundForceInchesTolerance);
            Assert.Equal(TorqueUnit.MegapoundForceInch, megapoundforceinchQuantity.Unit);

            var newtoncentimeterQuantity = newtonmeter.ToUnit(TorqueUnit.NewtonCentimeter);

            AssertEx.EqualTolerance(NewtonCentimetersInOneNewtonMeter, (double)newtoncentimeterQuantity.Value, NewtonCentimetersTolerance);
            Assert.Equal(TorqueUnit.NewtonCentimeter, newtoncentimeterQuantity.Unit);

            var newtonmeterQuantity = newtonmeter.ToUnit(TorqueUnit.NewtonMeter);

            AssertEx.EqualTolerance(NewtonMetersInOneNewtonMeter, (double)newtonmeterQuantity.Value, NewtonMetersTolerance);
            Assert.Equal(TorqueUnit.NewtonMeter, newtonmeterQuantity.Unit);

            var newtonmillimeterQuantity = newtonmeter.ToUnit(TorqueUnit.NewtonMillimeter);

            AssertEx.EqualTolerance(NewtonMillimetersInOneNewtonMeter, (double)newtonmillimeterQuantity.Value, NewtonMillimetersTolerance);
            Assert.Equal(TorqueUnit.NewtonMillimeter, newtonmillimeterQuantity.Unit);

            var poundalfootQuantity = newtonmeter.ToUnit(TorqueUnit.PoundalFoot);

            AssertEx.EqualTolerance(PoundalFeetInOneNewtonMeter, (double)poundalfootQuantity.Value, PoundalFeetTolerance);
            Assert.Equal(TorqueUnit.PoundalFoot, poundalfootQuantity.Unit);

            var poundforcefootQuantity = newtonmeter.ToUnit(TorqueUnit.PoundForceFoot);

            AssertEx.EqualTolerance(PoundForceFeetInOneNewtonMeter, (double)poundforcefootQuantity.Value, PoundForceFeetTolerance);
            Assert.Equal(TorqueUnit.PoundForceFoot, poundforcefootQuantity.Unit);

            var poundforceinchQuantity = newtonmeter.ToUnit(TorqueUnit.PoundForceInch);

            AssertEx.EqualTolerance(PoundForceInchesInOneNewtonMeter, (double)poundforceinchQuantity.Value, PoundForceInchesTolerance);
            Assert.Equal(TorqueUnit.PoundForceInch, poundforceinchQuantity.Unit);

            var tonneforcecentimeterQuantity = newtonmeter.ToUnit(TorqueUnit.TonneForceCentimeter);

            AssertEx.EqualTolerance(TonneForceCentimetersInOneNewtonMeter, (double)tonneforcecentimeterQuantity.Value, TonneForceCentimetersTolerance);
            Assert.Equal(TorqueUnit.TonneForceCentimeter, tonneforcecentimeterQuantity.Unit);

            var tonneforcemeterQuantity = newtonmeter.ToUnit(TorqueUnit.TonneForceMeter);

            AssertEx.EqualTolerance(TonneForceMetersInOneNewtonMeter, (double)tonneforcemeterQuantity.Value, TonneForceMetersTolerance);
            Assert.Equal(TorqueUnit.TonneForceMeter, tonneforcemeterQuantity.Unit);

            var tonneforcemillimeterQuantity = newtonmeter.ToUnit(TorqueUnit.TonneForceMillimeter);

            AssertEx.EqualTolerance(TonneForceMillimetersInOneNewtonMeter, (double)tonneforcemillimeterQuantity.Value, TonneForceMillimetersTolerance);
            Assert.Equal(TorqueUnit.TonneForceMillimeter, tonneforcemillimeterQuantity.Unit);
        }
Exemple #20
0
        public void Convert_ChangeType_UnitType_EqualsUnit()
        {
            var quantity = Torque.FromNewtonMeters(1.0);

            Assert.Equal(quantity.Unit, Convert.ChangeType(quantity, typeof(TorqueUnit)));
        }
Exemple #21
0
        public void CompareToThrowsOnTypeMismatch()
        {
            Torque newtonmeter = Torque.FromNewtonMeters(1);

            Assert.Throws <ArgumentException>(() => newtonmeter.CompareTo(new object()));
        }
Exemple #22
0
        public void Convert_ChangeType_QuantityType_EqualsQuantityType()
        {
            var quantity = Torque.FromNewtonMeters(1.0);

            Assert.Equal(QuantityType.Torque, Convert.ChangeType(quantity, typeof(QuantityType)));
        }
Exemple #23
0
        public void Equals_NegativeRelativeTolerance_ThrowsArgumentOutOfRangeException()
        {
            var v = Torque.FromNewtonMeters(1);

            Assert.Throws <ArgumentOutOfRangeException>(() => v.Equals(Torque.FromNewtonMeters(1), -1, ComparisonType.Relative));
        }
Exemple #24
0
        public void Convert_ChangeType_BaseDimensions_EqualsBaseDimensions()
        {
            var quantity = Torque.FromNewtonMeters(1.0);

            Assert.Equal(Torque.BaseDimensions, Convert.ChangeType(quantity, typeof(BaseDimensions)));
        }
Exemple #25
0
        public void EqualsReturnsFalseOnNull()
        {
            Torque newtonmeter = Torque.FromNewtonMeters(1);

            Assert.False(newtonmeter.Equals(null));
        }
Exemple #26
0
        public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException()
        {
            var quantity = Torque.FromNewtonMeters(1.0);

            Assert.Throws <InvalidCastException>(() => Convert.ChangeType(quantity, typeof(QuantityFormatter)));
        }
Exemple #27
0
        public void ToString_NullProvider_EqualsCurrentUICulture()
        {
            var quantity = Torque.FromNewtonMeters(1.0);

            Assert.Equal(quantity.ToString(CultureInfo.CurrentUICulture, "g"), quantity.ToString(null, "g"));
        }
Exemple #28
0
        public void GetHashCode_Equals()
        {
            var quantity = Torque.FromNewtonMeters(1.0);

            Assert.Equal(new { Torque.QuantityType, quantity.Value, quantity.Unit }.GetHashCode(), quantity.GetHashCode());
        }
Exemple #29
0
        public void Convert_ToDouble_EqualsValueAsSameType()
        {
            var quantity = Torque.FromNewtonMeters(1.0);

            Assert.Equal((double)quantity.Value, Convert.ToDouble(quantity));
        }
Exemple #30
0
        // Windows Runtime Component does not allow operator overloads: https://msdn.microsoft.com/en-us/library/br230301.aspx
#if !WINDOWS_UWP
        public static Torque operator *(RotationalStiffness rotationalStiffness, Angle angle)
        {
            return(Torque.FromNewtonMeters(rotationalStiffness.NewtonMetersPerRadian * angle.Radians));
        }