public void Equals_RelativeTolerance_IsImplemented() { var v = ApparentPower.FromVoltamperes(1); Assert.True(v.Equals(ApparentPower.FromVoltamperes(1), VoltamperesTolerance, ComparisonType.Relative)); Assert.False(v.Equals(ApparentPower.Zero, VoltamperesTolerance, ComparisonType.Relative)); }
public void EqualsIsImplemented() { ApparentPower v = ApparentPower.FromVoltamperes(1); Assert.True(v.Equals(ApparentPower.FromVoltamperes(1))); Assert.False(v.Equals(ApparentPower.Zero)); }
public void CompareToThrowsOnNull() { ApparentPower voltampere = ApparentPower.FromVoltamperes(1); // ReSharper disable once ReturnValueOfPureMethodIsNotUsed voltampere.CompareTo(null); }
public void CompareToThrowsOnTypeMismatch() { ApparentPower voltampere = ApparentPower.FromVoltamperes(1); // ReSharper disable once ReturnValueOfPureMethodIsNotUsed voltampere.CompareTo(new object()); }
public void FromVoltamperes_WithInfinityValue_CreateQuantityAndAffectInfinityValue() { var positiveInfinityQuantity = ApparentPower.FromVoltamperes(double.PositiveInfinity); var negativeInfinityQuantity = ApparentPower.FromVoltamperes(double.NegativeInfinity); Assert.True(double.IsPositiveInfinity(positiveInfinityQuantity.Value)); Assert.True(double.IsNegativeInfinity(negativeInfinityQuantity.Value)); }
public void Equals_SameType_IsImplemented() { var a = ApparentPower.FromVoltamperes(1); var b = ApparentPower.FromVoltamperes(2); Assert.True(a.Equals(a)); Assert.False(a.Equals(b)); }
public void CompareToIsImplemented() { ApparentPower voltampere = ApparentPower.FromVoltamperes(1); Assert.Equal(0, voltampere.CompareTo(voltampere)); Assert.True(voltampere.CompareTo(ApparentPower.Zero) > 0); Assert.True(ApparentPower.Zero.CompareTo(voltampere) < 0); }
public void CompareToIsImplemented() { ApparentPower voltampere = ApparentPower.FromVoltamperes(1); Assert.AreEqual(0, voltampere.CompareTo(voltampere)); Assert.Greater(voltampere.CompareTo(ApparentPower.Zero), 0); Assert.Less(ApparentPower.Zero.CompareTo(voltampere), 0); }
public void ConversionRoundTrip() { ApparentPower voltampere = ApparentPower.FromVoltamperes(1); AssertEx.EqualTolerance(1, ApparentPower.FromKilovoltamperes(voltampere.Kilovoltamperes).Voltamperes, KilovoltamperesTolerance); AssertEx.EqualTolerance(1, ApparentPower.FromMegavoltamperes(voltampere.Megavoltamperes).Voltamperes, MegavoltamperesTolerance); AssertEx.EqualTolerance(1, ApparentPower.FromVoltamperes(voltampere.Voltamperes).Voltamperes, VoltamperesTolerance); }
public void Equals_QuantityAsObject_IsImplemented() { object a = ApparentPower.FromVoltamperes(1); object b = ApparentPower.FromVoltamperes(2); Assert.True(a.Equals(a)); Assert.False(a.Equals(b)); Assert.False(a.Equals((object)null)); }
public void ArithmeticOperators() { ApparentPower v = ApparentPower.FromVoltamperes(1); AssertEx.EqualTolerance(-1, -v.Voltamperes, VoltamperesTolerance); AssertEx.EqualTolerance(2, (ApparentPower.FromVoltamperes(3) - v).Voltamperes, VoltamperesTolerance); AssertEx.EqualTolerance(2, (v + v).Voltamperes, VoltamperesTolerance); AssertEx.EqualTolerance(10, (v * 10).Voltamperes, VoltamperesTolerance); AssertEx.EqualTolerance(10, (10 * v).Voltamperes, VoltamperesTolerance); AssertEx.EqualTolerance(2, (ApparentPower.FromVoltamperes(10) / 5).Voltamperes, VoltamperesTolerance); AssertEx.EqualTolerance(2, ApparentPower.FromVoltamperes(10) / ApparentPower.FromVoltamperes(5), VoltamperesTolerance); }
public void To_UnitSystem_ThrowsArgumentExceptionIfNotSupported() { var voltampere = ApparentPower.FromVoltamperes(1); Assert.Throws <ArgumentException>(() => voltampere.ToUnit(UnitSystem.SI)); Assert.Throws <ArgumentException>(() => voltampere.ToUnit(UnitSystem.CGS)); Assert.Throws <ArgumentException>(() => voltampere.ToUnit(UnitSystem.BI)); Assert.Throws <ArgumentException>(() => voltampere.ToUnit(UnitSystem.EE)); Assert.Throws <ArgumentException>(() => voltampere.ToUnit(UnitSystem.USC)); Assert.Throws <ArgumentException>(() => voltampere.ToUnit(UnitSystem.FPS)); Assert.Throws <ArgumentException>(() => voltampere.ToUnit(UnitSystem.Astronomical)); }
public void EqualityOperators() { ApparentPower a = ApparentPower.FromVoltamperes(1); ApparentPower b = ApparentPower.FromVoltamperes(2); // ReSharper disable EqualExpressionComparison Assert.True(a == a); Assert.True(a != b); Assert.False(a == b); Assert.False(a != a); // ReSharper restore EqualExpressionComparison }
public void ComparisonOperators() { ApparentPower oneVoltampere = ApparentPower.FromVoltamperes(1); ApparentPower twoVoltamperes = ApparentPower.FromVoltamperes(2); Assert.True(oneVoltampere < twoVoltamperes); Assert.True(oneVoltampere <= twoVoltamperes); Assert.True(twoVoltamperes > oneVoltampere); Assert.True(twoVoltamperes >= oneVoltampere); Assert.False(oneVoltampere > twoVoltamperes); Assert.False(oneVoltampere >= twoVoltamperes); Assert.False(twoVoltamperes < oneVoltampere); Assert.False(twoVoltamperes <= oneVoltampere); }
public void EqualityOperators() { var a = ApparentPower.FromVoltamperes(1); var b = ApparentPower.FromVoltamperes(2); #pragma warning disable CS8073 // 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 #pragma warning restore CS8073 }
public void ToUnit() { var voltampere = ApparentPower.FromVoltamperes(1); var gigavoltampereQuantity = voltampere.ToUnit(ApparentPowerUnit.Gigavoltampere); AssertEx.EqualTolerance(GigavoltamperesInOneVoltampere, (double)gigavoltampereQuantity.Value, GigavoltamperesTolerance); Assert.Equal(ApparentPowerUnit.Gigavoltampere, gigavoltampereQuantity.Unit); var kilovoltampereQuantity = voltampere.ToUnit(ApparentPowerUnit.Kilovoltampere); AssertEx.EqualTolerance(KilovoltamperesInOneVoltampere, (double)kilovoltampereQuantity.Value, KilovoltamperesTolerance); Assert.Equal(ApparentPowerUnit.Kilovoltampere, kilovoltampereQuantity.Unit); var megavoltampereQuantity = voltampere.ToUnit(ApparentPowerUnit.Megavoltampere); AssertEx.EqualTolerance(MegavoltamperesInOneVoltampere, (double)megavoltampereQuantity.Value, MegavoltamperesTolerance); Assert.Equal(ApparentPowerUnit.Megavoltampere, megavoltampereQuantity.Unit); var voltampereQuantity = voltampere.ToUnit(ApparentPowerUnit.Voltampere); AssertEx.EqualTolerance(VoltamperesInOneVoltampere, (double)voltampereQuantity.Value, VoltamperesTolerance); Assert.Equal(ApparentPowerUnit.Voltampere, voltampereQuantity.Unit); }
public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() { var quantity = ApparentPower.FromVoltamperes(1.0); Assert.Throws <InvalidCastException>(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); }
public void CompareToThrowsOnNull() { ApparentPower voltampere = ApparentPower.FromVoltamperes(1); Assert.Throws <ArgumentNullException>(() => voltampere.CompareTo(null)); }
public void CompareToThrowsOnTypeMismatch() { ApparentPower voltampere = ApparentPower.FromVoltamperes(1); Assert.Throws <ArgumentException>(() => voltampere.CompareTo(new object())); }
public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) { var quantity = ApparentPower.FromVoltamperes(value); Assert.Equal(ApparentPower.FromVoltamperes(-value), -quantity); }
public static ApparentPower Voltamperes <T>(this T value) => ApparentPower.FromVoltamperes(Convert.ToDecimal(value));
public void EqualsReturnsFalseOnTypeMismatch() { ApparentPower voltampere = ApparentPower.FromVoltamperes(1); Assert.False(voltampere.Equals(new object())); }
public void GetHashCode_Equals() { var quantity = ApparentPower.FromVoltamperes(1.0); Assert.Equal(new { ApparentPower.Info.Name, quantity.Value, quantity.Unit }.GetHashCode(), quantity.GetHashCode()); }