| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2014 Google Inc. All rights reserved. | 2 * Copyright (C) 2014 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | 21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 23 */ | 23 */ |
| 24 | 24 |
| 25 #include "config.h" | 25 #include "config.h" |
| 26 #include "platform/geometry/FloatBoxTestHelpers.h" | 26 #include "platform/geometry/FloatBoxTestHelpers.h" |
| 27 | 27 |
| 28 #include "platform/geometry/FloatBox.h" | 28 #include "platform/geometry/FloatBox.h" |
| 29 const static float kTestEpsilon = 1e-6; | 29 const static float kTestEpsilon = 1e-6; |
| 30 | 30 |
| 31 void WebCore::PrintTo(const FloatBox& box, ::std::ostream* os) | 31 void blink::PrintTo(const FloatBox& box, ::std::ostream* os) |
| 32 { | 32 { |
| 33 *os << "FloatBox(" | 33 *os << "FloatBox(" |
| 34 << box.x() << ", " | 34 << box.x() << ", " |
| 35 << box.y() << ", " | 35 << box.y() << ", " |
| 36 << box.z() << ", " | 36 << box.z() << ", " |
| 37 << box.width() << ", " | 37 << box.width() << ", " |
| 38 << box.height() << ", " | 38 << box.height() << ", " |
| 39 << box.depth() << ")"; | 39 << box.depth() << ")"; |
| 40 } | 40 } |
| 41 | 41 |
| 42 bool WebCore::FloatBoxTest::ApproximatelyEqual(const float& a, const float& b) | 42 bool blink::FloatBoxTest::ApproximatelyEqual(const float& a, const float& b) |
| 43 { | 43 { |
| 44 float absA = ::fabs(a); | 44 float absA = ::fabs(a); |
| 45 float absB = ::fabs(b); | 45 float absB = ::fabs(b); |
| 46 float absErr = ::fabs(a - b); | 46 float absErr = ::fabs(a - b); |
| 47 if (a == b) | 47 if (a == b) |
| 48 return true; | 48 return true; |
| 49 | 49 |
| 50 if (a == 0 || b == 0 || absErr < std::numeric_limits<float>::min()) | 50 if (a == 0 || b == 0 || absErr < std::numeric_limits<float>::min()) |
| 51 return absErr < (kTestEpsilon * std::numeric_limits<float>::min()); | 51 return absErr < (kTestEpsilon * std::numeric_limits<float>::min()); |
| 52 | 52 |
| 53 return ((absErr / (absA + absB)) < kTestEpsilon); | 53 return ((absErr / (absA + absB)) < kTestEpsilon); |
| 54 } | 54 } |
| 55 | 55 |
| 56 bool WebCore::FloatBoxTest::ApproximatelyEqual(const FloatBox& a, const FloatBox
& b) | 56 bool blink::FloatBoxTest::ApproximatelyEqual(const FloatBox& a, const FloatBox&
b) |
| 57 { | 57 { |
| 58 if (!ApproximatelyEqual(a.x(), b.x()) | 58 if (!ApproximatelyEqual(a.x(), b.x()) |
| 59 || !ApproximatelyEqual(a.y(), b.y()) | 59 || !ApproximatelyEqual(a.y(), b.y()) |
| 60 || !ApproximatelyEqual(a.z(), b.z()) | 60 || !ApproximatelyEqual(a.z(), b.z()) |
| 61 || !ApproximatelyEqual(a.width(), b.width()) | 61 || !ApproximatelyEqual(a.width(), b.width()) |
| 62 || !ApproximatelyEqual(a.height(), b.height()) | 62 || !ApproximatelyEqual(a.height(), b.height()) |
| 63 || !ApproximatelyEqual(a.depth(), b.depth())) { | 63 || !ApproximatelyEqual(a.depth(), b.depth())) { |
| 64 return false; | 64 return false; |
| 65 } | 65 } |
| 66 return true; | 66 return true; |
| 67 } | 67 } |
| 68 | 68 |
| 69 ::testing::AssertionResult WebCore::FloatBoxTest::AssertAlmostEqual(const char*
m_expr, const char* n_expr, const FloatBox& m, const FloatBox& n) | 69 ::testing::AssertionResult blink::FloatBoxTest::AssertAlmostEqual(const char* m_
expr, const char* n_expr, const FloatBox& m, const FloatBox& n) |
| 70 { | 70 { |
| 71 if (!ApproximatelyEqual(m, n)) { | 71 if (!ApproximatelyEqual(m, n)) { |
| 72 return ::testing::AssertionFailure() << " Value of:" << n_expr <<
std::endl | 72 return ::testing::AssertionFailure() << " Value of:" << n_expr <<
std::endl |
| 73 << " Actual:" << testing::PrintToString(n) << std::endl | 73 << " Actual:" << testing::PrintToString(n) << std::endl |
| 74 << "Expected Approx:" << m_expr << std::endl | 74 << "Expected Approx:" << m_expr << std::endl |
| 75 << " Which is:" << ::testing::PrintToString(m); | 75 << " Which is:" << ::testing::PrintToString(m); |
| 76 } | 76 } |
| 77 return ::testing::AssertionSuccess(); | 77 return ::testing::AssertionSuccess(); |
| 78 } | 78 } |
| 79 | 79 |
| 80 ::testing::AssertionResult WebCore::FloatBoxTest::AssertContains(const char* m_e
xpr, const char* n_expr, const FloatBox& m, const FloatBox& n) | 80 ::testing::AssertionResult blink::FloatBoxTest::AssertContains(const char* m_exp
r, const char* n_expr, const FloatBox& m, const FloatBox& n) |
| 81 { | 81 { |
| 82 FloatBox newM = m; | 82 FloatBox newM = m; |
| 83 newM.expandTo(n); | 83 newM.expandTo(n); |
| 84 if (!ApproximatelyEqual(m, newM)) { | 84 if (!ApproximatelyEqual(m, newM)) { |
| 85 return ::testing::AssertionFailure() << " Value of:" << n_expr <<
std::endl | 85 return ::testing::AssertionFailure() << " Value of:" << n_expr <<
std::endl |
| 86 << " Actual:" << testing::PrintToString(n) << std::endl | 86 << " Actual:" << testing::PrintToString(n) << std::endl |
| 87 << "Not Contained in:" << m_expr << std::endl | 87 << "Not Contained in:" << m_expr << std::endl |
| 88 << " Which is:" << ::testing::PrintToString(m); | 88 << " Which is:" << ::testing::PrintToString(m); |
| 89 } | 89 } |
| 90 return ::testing::AssertionSuccess(); | 90 return ::testing::AssertionSuccess(); |
| 91 } | 91 } |
| 92 | 92 |
| 93 | 93 |
| OLD | NEW |