public static void AlmostEqualRelative(float expected, float actual, int decimalPlaces) { if (float.IsNaN(expected) && float.IsNaN(actual)) { return; } if (!expected.AlmostEqualRelative(actual, decimalPlaces)) { Assert.Fail("Not equal within {0} places. Expected:{1}; Actual:{2}", decimalPlaces, expected, actual); } }
/// <summary> /// Asserts that the expected value and the actual value are equal up to a certain number of decimal places. If both /// <paramref name="expected"/> and <paramref name="actual"/> are NaN then no assert is thrown. /// </summary> /// <param name="expected">The expected value.</param> /// <param name="actual">The actual value.</param> /// <param name="decimalPlaces">The number of decimal places to agree on.</param> public static void AlmostEqual(float expected, float actual, int decimalPlaces) { if (float.IsNaN(expected) && float.IsNaN(actual)) { return; } var pass = expected.AlmostEqualRelative(actual, decimalPlaces); if (!pass) { // signals Gallio that the test failed. Assert.Fail("Not equal within {0} places. Expected:{1}; Actual:{2}", decimalPlaces, expected, actual); } }