]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // Copyright 2008 Gunter Winkler <guwi17@gmx.de> |
2 | // Distributed under the Boost Software License, Version 1.0. (See | |
3 | // accompanying file LICENSE_1_0.txt or copy at | |
4 | // http://www.boost.org/LICENSE_1_0.txt) | |
5 | ||
7c673cae FG |
6 | #ifndef _HPP_TESTHELPER_ |
7 | #define _HPP_TESTHELPER_ | |
8 | ||
9 | #include <utility> | |
10 | ||
11 | static unsigned _success_counter = 0; | |
12 | static unsigned _fail_counter = 0; | |
13 | ||
92f5a8d4 TL |
14 | static inline void assertTrue(const char* message, bool condition) |
15 | { | |
7c673cae | 16 | #ifndef NOMESSAGES |
92f5a8d4 | 17 | std::cout << message; |
7c673cae | 18 | #endif |
92f5a8d4 TL |
19 | if (condition) |
20 | { | |
21 | ++_success_counter; | |
22 | std::cout << "1\n"; // success | |
23 | } | |
24 | else | |
25 | { | |
26 | ++_fail_counter; | |
27 | std::cout << "0\n"; // failed | |
28 | } | |
7c673cae FG |
29 | } |
30 | ||
92f5a8d4 TL |
31 | template <class T> |
32 | void assertEquals(const char* message, T expected, T actual) | |
33 | { | |
7c673cae | 34 | #ifndef NOMESSAGES |
92f5a8d4 | 35 | std::cout << message; |
7c673cae | 36 | #endif |
92f5a8d4 TL |
37 | if (expected == actual) |
38 | { | |
39 | ++_success_counter; | |
40 | std::cout << "1\n"; // success | |
41 | } | |
42 | else | |
43 | { | |
44 | #ifndef NOMESSAGES | |
7c673cae | 45 | std::cout << " expected " << expected << " actual " << actual << " "; |
92f5a8d4 TL |
46 | #endif |
47 | ++_fail_counter; | |
48 | std::cout << "0\n"; // failed | |
49 | } | |
7c673cae FG |
50 | } |
51 | ||
92f5a8d4 TL |
52 | static std::pair<unsigned, unsigned> getResults() |
53 | { | |
54 | return std::make_pair(_success_counter, _fail_counter); | |
7c673cae FG |
55 | } |
56 | ||
92f5a8d4 TL |
57 | template <class M1, class M2> |
58 | bool compare(const boost::numeric::ublas::matrix_expression<M1>& m1, | |
59 | const boost::numeric::ublas::matrix_expression<M2>& m2) | |
60 | { | |
61 | size_t size1 = (std::min)(m1().size1(), m2().size1()); | |
62 | size_t size2 = (std::min)(m1().size2(), m2().size2()); | |
63 | for (size_t i = 0; i < size1; ++i) | |
64 | { | |
65 | for (size_t j = 0; j < size2; ++j) | |
66 | { | |
67 | if (m1()(i, j) != m2()(i, j)) | |
68 | return false; | |
69 | } | |
70 | } | |
71 | return true; | |
7c673cae FG |
72 | } |
73 | ||
92f5a8d4 TL |
74 | template <class M1, class M2> |
75 | bool compare(const boost::numeric::ublas::vector_expression<M1>& m1, | |
76 | const boost::numeric::ublas::vector_expression<M2>& m2) | |
77 | { | |
78 | size_t size = (std::min)(m1().size(), m2().size()); | |
79 | for (size_t i = 0; i < size; ++i) | |
80 | { | |
81 | if (m1()(i) != m2()(i)) | |
82 | return false; | |
83 | } | |
84 | return true; | |
7c673cae FG |
85 | } |
86 | ||
87 | #endif |