]>
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 | ||
6 | ||
7 | #ifndef _HPP_TESTHELPER_ | |
8 | #define _HPP_TESTHELPER_ | |
9 | ||
10 | #include <utility> | |
11 | ||
12 | static unsigned _success_counter = 0; | |
13 | static unsigned _fail_counter = 0; | |
14 | ||
15 | static inline | |
16 | void assertTrue(const char* message, bool condition) { | |
17 | #ifndef NOMESSAGES | |
18 | std::cout << message; | |
19 | #endif | |
20 | if ( condition ) { | |
21 | ++ _success_counter; | |
22 | std::cout << "1\n"; // success | |
23 | } else { | |
24 | ++ _fail_counter; | |
25 | std::cout << "0\n"; // failed | |
26 | } | |
27 | } | |
28 | ||
29 | template < class T > | |
30 | void assertEquals(const char* message, T expected, T actual) { | |
31 | #ifndef NOMESSAGES | |
32 | std::cout << message; | |
33 | #endif | |
34 | if ( expected == actual ) { | |
35 | ++ _success_counter; | |
36 | std::cout << "1\n"; // success | |
37 | } else { | |
38 | #ifndef NOMESSAGES | |
39 | std::cout << " expected " << expected << " actual " << actual << " "; | |
40 | #endif | |
41 | ++ _fail_counter; | |
42 | std::cout << "0\n"; // failed | |
43 | } | |
44 | } | |
45 | ||
46 | static | |
47 | std::pair<unsigned, unsigned> getResults() { | |
48 | return std::make_pair(_success_counter, _fail_counter); | |
49 | } | |
50 | ||
51 | template < class M1, class M2 > | |
52 | bool compare( const boost::numeric::ublas::matrix_expression<M1> & m1, | |
53 | const boost::numeric::ublas::matrix_expression<M2> & m2 ) { | |
54 | size_t size1 = (std::min)(m1().size1(), m2().size1()); | |
55 | size_t size2 = (std::min)(m1().size2(), m2().size2()); | |
56 | for (size_t i=0; i < size1; ++i) { | |
57 | for (size_t j=0; j < size2; ++j) { | |
58 | if ( m1()(i,j) != m2()(i,j) ) return false; | |
59 | } | |
60 | } | |
61 | return true; | |
62 | } | |
63 | ||
64 | template < class M1, class M2 > | |
65 | bool compare( const boost::numeric::ublas::vector_expression<M1> & m1, | |
66 | const boost::numeric::ublas::vector_expression<M2> & m2 ) { | |
67 | size_t size = (std::min)(m1().size(), m2().size()); | |
68 | for (size_t i=0; i < size; ++i) { | |
69 | if ( m1()(i) != m2()(i) ) return false; | |
70 | } | |
71 | return true; | |
72 | } | |
73 | ||
74 | #endif |