Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / Source / platform / geometry / GeometryTestHelpers.cpp
blob743ee1f0e58165ff329f18711c8caa3a533c59bf
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.
5 #include "config.h"
6 #include "platform/geometry/GeometryTestHelpers.h"
8 #include <limits>
9 #include <math.h>
11 namespace blink {
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);
19 if (a == b)
20 return true;
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
41 } // namespace blink