1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
6 #include "platform/geometry/GeometryTestHelpers.h"
12 namespace GeometryTest
{
14 bool ApproximatelyEqual(float a
, float b
, float testEpsilon
)
16 float absA
= ::fabs(a
);
17 float absB
= ::fabs(b
);
18 float absErr
= ::fabs(a
- b
);
22 if (a
== 0 || b
== 0 || absErr
< std::numeric_limits
<float>::min())
23 return absErr
< (testEpsilon
* std::numeric_limits
<float>::min());
25 return ((absErr
/ (absA
+ absB
)) < testEpsilon
);
28 ::testing::AssertionResult
AssertAlmostEqual(const char* actual_expr
, const char* expected_expr
, float actual
, float expected
, float testEpsilon
)
30 if (!ApproximatelyEqual(actual
, expected
, testEpsilon
)) {
31 return ::testing::AssertionFailure() << " Value of:" << actual_expr
<< std::endl
32 << " Actual:" << ::testing::PrintToString(actual
) << std::endl
33 << "Expected Approx:" << expected_expr
<< std::endl
34 << " Which is:" << ::testing::PrintToString(expected
);
37 return ::testing::AssertionSuccess();
40 } // namespace GeometryTest