OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * Copyright (C) 2014 Google Inc. All rights reserved. | |
3 * | |
4 * Redistribution and use in source and binary forms, with or without | |
5 * modification, are permitted provided that the following conditions | |
6 * are met: | |
7 * 1. Redistributions of source code must retain the above copyright | |
8 * notice, this list of conditions and the following disclaimer. | |
9 * 2. Redistributions in binary form must reproduce the above copyright | |
10 * notice, this list of conditions and the following disclaimer in the | |
11 * documentation and/or other materials provided with the distribution. | |
12 * | |
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND AN Y | |
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |
15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
16 * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR AN Y | |
17 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
18 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
19 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND O N | |
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
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. | |
23 */ | |
24 | |
25 #include "platform/geometry/FloatBox.h" | |
26 | |
27 #include <gtest/gtest.h> | |
28 | |
29 namespace WebCore { | |
30 inline void PrintTo(const FloatBox& box, ::std::ostream* os) | |
31 { | |
32 *os << "FloatBox(" | |
33 << box.x() << ", " | |
34 << box.y() << ", " | |
35 << box.z() << ", " | |
36 << box.width() << ", " | |
37 << box.height() << ", " | |
38 << box.depth() << ")"; | |
39 } | |
40 | |
41 namespace FloatBoxTest { | |
42 const static float kTestEpsilon = 1e-6; | |
Ian Vollick
2014/06/17 15:54:55
Sorry for the churn, but I would really love to hi
awoloszyn
2014/06/17 20:06:02
Created a .cpp file and moved all of the functiona
| |
43 inline bool ApproximatelyEqual(const float& a, const float& b) | |
44 { | |
45 float absA = ::fabs(a); | |
46 float absB = ::fabs(b); | |
47 float absErr = ::fabs(a - b); | |
48 if (a == b) | |
49 return true; | |
50 | |
51 if (a == 0 || b == 0 || absErr < std::numeric_limits<float>::min()) | |
52 return absErr < (kTestEpsilon * std::numeric_limits<float>::min()); | |
53 | |
54 return ((absErr / (absA + absB)) < kTestEpsilon); | |
55 } | |
56 | |
57 inline bool ApproximatelyEqual(const FloatBox& a, const FloatBox& b) | |
58 { | |
59 if (!ApproximatelyEqual(a.x(), b.x()) | |
60 || !ApproximatelyEqual(a.y(), b.y()) | |
61 || !ApproximatelyEqual(a.z(), b.z()) | |
62 || !ApproximatelyEqual(a.width(), b.width()) | |
63 || !ApproximatelyEqual(a.height(), b.height()) | |
64 || !ApproximatelyEqual(a.depth(), b.depth())) { | |
65 return(false); | |
66 } | |
67 return(true); | |
68 } | |
69 | |
70 inline ::testing::AssertionResult AssertAlmostEqual(const char* m_expr, const ch ar* n_expr, const FloatBox& m, const FloatBox& n) | |
71 { | |
72 if (!ApproximatelyEqual(m, n)) { | |
73 return ::testing::AssertionFailure() << " Value of:" << n_expr << std::endl | |
74 << " Actual:" << testing::PrintToString(n) << std::endl | |
75 << "Expected Approx:" << m_expr << std::endl | |
76 << " Which is:" << ::testing::PrintToString(m); | |
77 } | |
78 return ::testing::AssertionSuccess(); | |
79 } | |
80 | |
81 inline ::testing::AssertionResult AssertContains(const char* m_expr, const char* n_expr, const FloatBox& m, const FloatBox& n) | |
82 { | |
83 FloatBox newM = m; | |
84 newM.expandTo(n); | |
85 if (!ApproximatelyEqual(m, newM)) { | |
86 return ::testing::AssertionFailure() << " Value of:" << n_expr << std::endl | |
87 << " Actual:" << testing::PrintToString(n) << std::endl | |
88 << "Not Contained in:" << m_expr << std::endl | |
89 << " Which is:" << ::testing::PrintToString(m); | |
90 } | |
91 return ::testing::AssertionSuccess(); | |
92 } | |
93 | |
94 } | |
95 } | |
96 | |
OLD | NEW |