/// <summary> /// Asserts a floating point value does not approximate another value by a given amount. /// </summary> /// <param name="parent">The <see cref="NumericAssertions{T}"/> object that is being extended.</param> /// <param name="unexpectedValue"> /// The unexpected value to compare the actual value with. /// </param> /// <param name="precision"> /// The minimum exclusive amount of which the two values should differ. /// </param> /// <param name="because"> /// A formatted phrase as is supported by <see cref="string.Format(string,object[])"/> explaining why the assertion /// is needed. If the phrase does not start with the word <i>because</i>, it is prepended automatically. /// </param> /// <param name="becauseArgs"> /// Zero or more objects to format using the placeholders in <see cref="because"/>. /// </param> public static AndConstraint <NullableNumericAssertions <float> > NotBeApproximately(this NullableNumericAssertions <float> parent, float unexpectedValue, float precision, string because = "", params object[] becauseArgs) { Execute.Assertion .ForCondition(parent.Subject != null) .BecauseOf(because, becauseArgs) .FailWith("Expected {context:value} to not approximate {0} +/- {1}{reason}, but it was <null>.", unexpectedValue, precision); var nonNullableAssertions = new NumericAssertions <float>((float)parent.Subject); nonNullableAssertions.NotBeApproximately(unexpectedValue, precision, because, becauseArgs); return(new AndConstraint <NullableNumericAssertions <float> >(parent)); }
/// <summary> /// Asserts a double value approximates another value as close as possible. /// </summary> /// <param name="parent">The <see cref="NumericAssertions{T}"/> object that is being extended.</param> /// <param name="expectedValue"> /// The expected value to compare the actual value with. /// </param> /// <param name="precision"> /// The maximum amount of which the two values may differ. /// </param> /// <param name="because"> /// A formatted phrase as is supported by <see cref="string.Format(string,object[])"/> explaining why the assertion /// is needed. If the phrase does not start with the word <i>because</i>, it is prepended automatically. /// </param> /// <param name="becauseArgs"> /// Zero or more objects to format using the placeholders in <see cref="because"/>. /// </param> public static AndConstraint <NullableNumericAssertions <double> > BeApproximately(this NullableNumericAssertions <double> parent, double expectedValue, double precision, string because = "", params object [] becauseArgs) { Execute.Assertion .ForCondition(parent.Subject != null) .BecauseOf(because, becauseArgs) .FailWith("Expected {context:value} to approximate {0} +/- {1}{reason}, but it was <null>.", expectedValue, precision); var nonNullableAssertions = new NumericAssertions <double>((double)parent.Subject); BeApproximately(nonNullableAssertions, expectedValue, precision, because, becauseArgs); return(new AndConstraint <NullableNumericAssertions <double> >(parent)); }
public static AndConstraint <NumericAssertions <double> > BeGreaterOrEqualToMinimumSleepLength(this NullableNumericAssertions <double> duration, int numberOfSleeps ) { var expectedTransactionLength = numberOfSleeps * WaitHelpers.SleepLength; return(duration.NotBeNull() .And.BeGreaterOrEqualTo(expectedTransactionLength, $"we expected {numberOfSleeps} to influence the total duration")); }
BeGreaterOrEqualToMinimumSleepLength(this NullableNumericAssertions <double> duration) => duration.NotBeNull().And.BeGreaterOrEqualTo(WaitHelpers.SleepLength);
public static AndConstraint <NullableNumericAssertions <decimal> > BeApproximately(this NullableNumericAssertions <decimal> parent, decimal?expectedValue, string because = "", params object[] becauseArgs) { return(parent.BeApproximately(expectedValue, NumericPrecision, because, becauseArgs)); }
/// <summary> /// Asserts a floating point value approximates another value as close as possible. /// </summary> /// <param name="parent">The <see cref="NumericAssertions{T}"/> object that is being extended.</param> /// <param name="expectedValue"> /// The expected value to compare the actual value with. /// </param> /// <param name="precision"> /// The maximum amount of which the two values may differ. /// </param> /// <param name="reason"> /// A formatted phrase as is supported by <see cref="string.Format(string,object[])"/> explaining why the assertion /// is needed. If the phrase does not start with the word <i>because</i>, it is prepended automatically. /// </param> /// <param name="reasonArgs"> /// Zero or more objects to format using the placeholders in <see cref="reason"/>. /// </param> public static AndConstraint <NullableNumericAssertions <float> > BeApproximately(this NullableNumericAssertions <float> parent, float expectedValue, float precision, string reason = "", params object [] reasonArgs) { Execute.Assertion .ForCondition(parent.Subject != null) .BecauseOf(reason, reasonArgs) .FailWith("Expected value to approximate {0} +/- {1}{reason}, but it was <null>.", expectedValue, precision); var nonNullableAssertions = new NumericAssertions <float>((float)parent.Subject); nonNullableAssertions.BeApproximately(expectedValue, precision, reason, reasonArgs); return(new AndConstraint <NullableNumericAssertions <float> >(parent)); }
public static AndConstraint <NullableNumericAssertions <double> > BeApproximately(this NullableNumericAssertions <double> parent, decimal?expectedValue, string because = "", params object[] becauseArgs) => parent.BeApproximately((double?)expectedValue, Math.Abs((double?)expectedValue * TestsBase.DoublePrecisionPercentage ?? TestsBase.DoublePrecision), because, becauseArgs);
public static AndConstraint <NumericAssertions <double> > Be(this NullableNumericAssertions <double> parent, decimal?expectedValue, string because = "", params object[] becauseArgs) => parent.Be((double?)expectedValue, because, becauseArgs);
public static AndConstraint <NullableNumericAssertions <Length> > NotBeApproximately(this NullableNumericAssertions <Length> parent, Length?expectedValue, Length precision, string because = "", params object[] becauseArgs) { string failMessage = ((Length?)parent.Subject).HasValue ? "Did not expect {context:Length} to be approximately {0} +/- {1}{reason}, but found {2} which differs by {3}." : "Did not expect {context:Length} to be approximately {0} +/- {1}{reason}, but found {2}."; var difference = (Length?)parent.Subject - expectedValue; Execute.Assertion .ForCondition( !((Length?)parent.Subject).HasValue && !expectedValue.HasValue || Length.Abs(difference) > precision) .BecauseOf(because, becauseArgs) .FailWith(failMessage, expectedValue, precision, ((Length?)parent.Subject), difference); return(new AndConstraint <NullableNumericAssertions <Length> >(parent)); }