Esempio n. 1
0
        /// <summary>
        /// The be approximately.
        /// </summary>
        /// <param name="quantityAssertions">
        /// The quantity assertions.
        /// </param>
        /// <param name="expectedValue">
        /// The expected value.
        /// </param>
        /// <param name="expectedUnit">
        /// The expected unit.
        /// </param>
        /// <param name="unitFormat">
        /// The unit format.
        /// </param>
        /// <param name="precision">
        /// The precision.
        /// </param>
        /// <returns>
        /// The <see cref="AndConstraint{T}"/>.
        /// </returns>
        public static AndConstraint <ComparableTypeAssertions <IQuantity> > BeApproximately(
            this ComparableTypeAssertions <IQuantity> quantityAssertions,
            double expectedValue,
            string expectedUnit,
            UnitFormat unitFormat,
            double precision)
        {
            var quantity      = (IQuantity)quantityAssertions.Subject;
            var quantityValue = quantity.Value;
            var quantityUnit  = UnitFormatHelper.GetNotation(quantity.Unit, unitFormat);

            Execute.Assertion.ForCondition(quantityValue == expectedValue || Math.Abs(quantityValue - expectedValue) < precision)
            .FailWith("The value: {0}, but found: {1}", expectedValue, quantityValue);
            AssertUnit(quantityUnit, expectedUnit);

            return(new AndConstraint <ComparableTypeAssertions <IQuantity> >(quantityAssertions));
        }
Esempio n. 2
0
        /// <summary>
        /// The be.
        /// </summary>
        /// <param name="quantityAssertions">
        /// The quantity assertions.
        /// </param>
        /// <param name="expectedValue">
        /// The expected value.
        /// </param>
        /// <param name="expectedUnit">
        /// The expected unit.
        /// </param>
        /// <param name="unitFormat">
        /// The unit format.
        /// </param>
        /// <returns>
        /// The <see cref="AndConstraint{T}"/>.
        /// </returns>
        public static AndConstraint <ComparableTypeAssertions <IQuantity> > Be(
            this ComparableTypeAssertions <IQuantity> quantityAssertions,
            double expectedValue,
            string expectedUnit,
            UnitFormat unitFormat)
        {
            var quantity      = (IQuantity)quantityAssertions.Subject;
            var quantityValue = quantity.Value;
            var quantityUnit  = UnitFormatHelper.GetNotation(quantity.Unit, unitFormat);

            Execute.Assertion.ForCondition(quantityValue.Equals(expectedValue))
            .FailWith(
                "The value: {0}, but found: {1}",
                expectedValue.ToString("N20"),
                quantityValue.ToString("N20"));
            AssertUnit(quantityUnit, expectedUnit);

            return(new AndConstraint <ComparableTypeAssertions <IQuantity> >(quantityAssertions));
        }