OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "config.h" | 5 #include "config.h" |
6 #include "platform/geometry/GeometryTestHelpers.h" | 6 #include "platform/geometry/GeometryTestHelpers.h" |
7 | 7 |
8 #include <limits> | 8 #include <limits> |
9 #include <math.h> | 9 #include <math.h> |
10 | 10 |
11 bool blink::GeometryTest::ApproximatelyEqual(float a, float b, float testEpsilon
) | 11 namespace blink { |
| 12 namespace GeometryTest { |
| 13 |
| 14 bool ApproximatelyEqual(float a, float b, float testEpsilon) |
12 { | 15 { |
13 float absA = ::fabs(a); | 16 float absA = ::fabs(a); |
14 float absB = ::fabs(b); | 17 float absB = ::fabs(b); |
15 float absErr = ::fabs(a - b); | 18 float absErr = ::fabs(a - b); |
16 if (a == b) | 19 if (a == b) |
17 return true; | 20 return true; |
18 | 21 |
19 if (a == 0 || b == 0 || absErr < std::numeric_limits<float>::min()) | 22 if (a == 0 || b == 0 || absErr < std::numeric_limits<float>::min()) |
20 return absErr < (testEpsilon * std::numeric_limits<float>::min()); | 23 return absErr < (testEpsilon * std::numeric_limits<float>::min()); |
21 | 24 |
22 return ((absErr / (absA + absB)) < testEpsilon); | 25 return ((absErr / (absA + absB)) < testEpsilon); |
23 } | 26 } |
24 | 27 |
25 ::testing::AssertionResult blink::GeometryTest::AssertAlmostEqual(const char* ac
tual_expr, const char* expected_expr, float actual, float expected, float testEp
silon) | 28 ::testing::AssertionResult AssertAlmostEqual(const char* actual_expr, const char
* expected_expr, float actual, float expected, float testEpsilon) |
26 { | 29 { |
27 if (!ApproximatelyEqual(actual, expected, testEpsilon)) { | 30 if (!ApproximatelyEqual(actual, expected, testEpsilon)) { |
28 return ::testing::AssertionFailure() << " Value of:" << actual_exp
r << std::endl | 31 return ::testing::AssertionFailure() << " Value of:" << actual_exp
r << std::endl |
29 << " Actual:" << ::testing::PrintToString(actual) << std::en
dl | 32 << " Actual:" << ::testing::PrintToString(actual) << std::en
dl |
30 << "Expected Approx:" << expected_expr << std::endl | 33 << "Expected Approx:" << expected_expr << std::endl |
31 << " Which is:" << ::testing::PrintToString(expected); | 34 << " Which is:" << ::testing::PrintToString(expected); |
32 } | 35 } |
33 | 36 |
34 return ::testing::AssertionSuccess(); | 37 return ::testing::AssertionSuccess(); |
35 } | 38 } |
| 39 |
| 40 } // namespace GeometryTest |
| 41 } // namespace blink |
OLD | NEW |