diff options
Diffstat (limited to 'libraries/ode-0.9\/tests/CppTestHarness/Checks.h')
-rwxr-xr-x | libraries/ode-0.9\/tests/CppTestHarness/Checks.h | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/libraries/ode-0.9\/tests/CppTestHarness/Checks.h b/libraries/ode-0.9\/tests/CppTestHarness/Checks.h new file mode 100755 index 0000000..7b4c2ca --- /dev/null +++ b/libraries/ode-0.9\/tests/CppTestHarness/Checks.h | |||
@@ -0,0 +1,97 @@ | |||
1 | #ifndef CHECKS_H | ||
2 | #define CHECKS_H | ||
3 | |||
4 | #include <sstream> | ||
5 | #include <cmath> | ||
6 | |||
7 | namespace CppTestHarness | ||
8 | { | ||
9 | template< typename Value > | ||
10 | bool Check(Value const value) | ||
11 | { | ||
12 | #ifdef _MSC_VER | ||
13 | # pragma warning(push) | ||
14 | # pragma warning(disable:4127) // conditional expression is constant | ||
15 | # pragma warning(disable:4800) // forcing value to bool true/false, performance warning | ||
16 | #endif | ||
17 | return value; | ||
18 | #ifdef _MSC_VER | ||
19 | # pragma warning(pop) | ||
20 | #endif | ||
21 | } | ||
22 | |||
23 | template< typename Actual, typename Expected > | ||
24 | bool CheckEqual(Actual const actual, Expected const expected) | ||
25 | { | ||
26 | #ifdef _MSC_VER | ||
27 | # pragma warning(push) | ||
28 | # pragma warning(disable:4127) // conditional expression is constant | ||
29 | #endif | ||
30 | return (actual == expected); | ||
31 | #ifdef _MSC_VER | ||
32 | # pragma warning(pop) | ||
33 | #endif | ||
34 | } | ||
35 | |||
36 | template< typename Actual, typename Expected > | ||
37 | bool CheckArrayEqual(Actual const actual, Expected const expected, int const count) | ||
38 | { | ||
39 | for (int i = 0; i < count; ++i) | ||
40 | { | ||
41 | if (!(actual[i] == expected[i])) | ||
42 | return false; | ||
43 | } | ||
44 | |||
45 | return true; | ||
46 | } | ||
47 | |||
48 | template< typename Actual, typename Expected, typename Tolerance > | ||
49 | bool CheckClose(Actual const actual, Expected const expected, Tolerance const tolerance) | ||
50 | { | ||
51 | return (std::abs(double(actual) - double(expected)) <= double(tolerance)); | ||
52 | } | ||
53 | |||
54 | template< typename Actual, typename Expected, typename Tolerance > | ||
55 | bool CheckArrayClose(Actual const actual, Expected const expected, int const count, Tolerance const tolerance) | ||
56 | { | ||
57 | for (int i = 0; i < count; ++i) | ||
58 | { | ||
59 | if (!CheckClose(actual[i], expected[i], tolerance)) | ||
60 | return false; | ||
61 | } | ||
62 | |||
63 | return true; | ||
64 | } | ||
65 | |||
66 | template< typename Actual, typename Expected > | ||
67 | std::string BuildFailureString(Actual const actual, Expected const expected) | ||
68 | { | ||
69 | std::stringstream failureStr; | ||
70 | failureStr << "Expected " << actual << " but got " << expected << std::endl; | ||
71 | return failureStr.str(); | ||
72 | } | ||
73 | |||
74 | template< typename Actual, typename Expected > | ||
75 | std::string BuildFailureString(Actual const* actual, Expected const* expected, int const count) | ||
76 | { | ||
77 | std::stringstream failureStr; | ||
78 | int i; | ||
79 | |||
80 | failureStr << "Expected [ "; | ||
81 | |||
82 | for (i = 0; i < count; ++i) | ||
83 | failureStr << expected[i] << ' '; | ||
84 | |||
85 | failureStr << "] but got [ "; | ||
86 | |||
87 | for (i = 0; i < count; ++i) | ||
88 | failureStr << expected[i] << ' '; | ||
89 | |||
90 | failureStr << ']' << std::endl; | ||
91 | |||
92 | return failureStr.str(); | ||
93 | } | ||
94 | } | ||
95 | |||
96 | #endif | ||
97 | |||