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 #define TEST_EPSILON 1e-3 | |
43 inline bool ApproximatelyEqual(const FloatBox& a, const FloatBox& b) | |
44 { | |
45 if (::fabsf(a.x() - b.x()) > TEST_EPSILON | |
Ian Vollick
2014/06/16 15:23:37
Why not make an inline, "approximately equal" help
awoloszyn
2014/06/17 14:26:00
Done.
| |
46 || ::fabsf(a.y() - b.y()) > TEST_EPSILON | |
47 || ::fabsf(a.z() - b.z()) > TEST_EPSILON | |
48 || ::fabsf(a.width() - b.width()) > TEST_EPSILON | |
49 || ::fabsf(a.height() - b.height()) > TEST_EPSILON | |
50 || ::fabsf(a.depth() - b.depth()) > TEST_EPSILON) { | |
51 return(false); | |
52 } | |
53 return(true); | |
54 } | |
55 | |
56 inline ::testing::AssertionResult AssertAlmostEqual(const char* m_expr, const ch ar* n_expr, const FloatBox& m, const FloatBox& n) | |
57 { | |
58 if (!ApproximatelyEqual(m, n)) { | |
59 return ::testing::AssertionFailure() << " Value of:" << n_expr << std::endl | |
60 << " Actual:" << testing::PrintToString(n) << std::endl | |
61 << "Expected Approx:" << m_expr << std::endl | |
62 << " Which is:" << ::testing::PrintToString(m); | |
63 } | |
64 return ::testing::AssertionSuccess(); | |
65 } | |
66 | |
67 inline ::testing::AssertionResult AssertContains(const char* m_expr, const char* n_expr, const FloatBox& m, const FloatBox& n) | |
68 { | |
69 FloatBox newM = m; | |
70 newM.expandTo(n); | |
71 if (!ApproximatelyEqual(m, newM)) { | |
72 return ::testing::AssertionFailure() << " Value of:" << n_expr << std::endl | |
73 << " Actual:" << testing::PrintToString(n) << std::endl | |
74 << "Not Contained in:" << m_expr << std::endl | |
75 << " Which is:" << ::testing::PrintToString(m); | |
76 } | |
77 return ::testing::AssertionSuccess(); | |
78 } | |
79 | |
80 } | |
81 } | |
82 | |
OLD | NEW |