]>
Commit | Line | Data |
---|---|---|
cefb7c1f DK |
1 | #include <iostream> |
2 | ||
fce11533 | 3 | #define equals(x,y) assertEquals(y, x, __LINE__) |
cefb7c1f DK |
4 | |
5 | template < typename X, typename Y > | |
fce11533 | 6 | void OutputAssertEqual(X expect, char const* compare, Y get, unsigned long const &line) { |
cefb7c1f DK |
7 | std::cerr << "Test FAILED: »" << expect << "« " << compare << " »" << get << "« at line " << line << std::endl; |
8 | } | |
9 | ||
10 | template < typename X, typename Y > | |
11 | void assertEquals(X expect, Y get, unsigned long const &line) { | |
12 | if (expect == get) | |
13 | return; | |
fce11533 | 14 | OutputAssertEqual(expect, "==", get, line); |
cefb7c1f DK |
15 | } |
16 | ||
17 | void assertEquals(unsigned int const &expect, int const &get, unsigned long const &line) { | |
18 | if (get < 0) | |
fce11533 | 19 | OutputAssertEqual(expect, "==", get, line); |
cefb7c1f DK |
20 | assertEquals<unsigned int const&, unsigned int const&>(expect, get, line); |
21 | } | |
fce11533 DK |
22 | |
23 | void assertEquals(int const &expect, unsigned int const &get, unsigned long const &line) { | |
24 | if (expect < 0) | |
25 | OutputAssertEqual(expect, "==", get, line); | |
26 | assertEquals<unsigned int const&, unsigned int const&>(expect, get, line); | |
27 | } | |
28 | ||
29 | ||
30 | #define equalsOr2(x,y,z) assertEqualsOr2(y, z, x, __LINE__) | |
31 | ||
32 | template < typename X, typename Y > | |
33 | void OutputAssertEqualOr2(X expect1, X expect2, char const* compare, Y get, unsigned long const &line) { | |
34 | std::cerr << "Test FAILED: »" << expect1 << "« or »" << expect2 << "« " << compare << " »" << get << "« at line " << line << std::endl; | |
35 | } | |
36 | ||
37 | template < typename X, typename Y > | |
38 | void assertEqualsOr2(X expect1, X expect2, Y get, unsigned long const &line) { | |
39 | if (expect1 == get || expect2 == get) | |
40 | return; | |
41 | OutputAssertEqualOr2(expect1, expect2, "==", get, line); | |
42 | } | |
43 | ||
44 | void assertEqualsOr2(unsigned int const &expect1, unsigned int const &expect2, int const &get, unsigned long const &line) { | |
45 | if (get < 0) | |
46 | OutputAssertEqualOr2(expect1, expect2, "==", get, line); | |
47 | assertEqualsOr2<unsigned int const&, unsigned int const&>(expect1, expect2, get, line); | |
48 | } | |
49 | ||
50 | void assertEqualsOr2(int const &expect1, int const &expect2, unsigned int const &get, unsigned long const &line) { | |
51 | if (expect1 < 0 && expect2 < 0) | |
52 | OutputAssertEqualOr2(expect1, expect2, "==", get, line); | |
53 | assertEqualsOr2<unsigned int const&, unsigned int const&>(expect1, expect2, get, line); | |
54 | } | |
55 | ||
f7f0d6c7 | 56 | |
7cb28948 DK |
57 | #define equalsOr3(w,x,y,z) assertEqualsOr3(x, y, z, w, __LINE__) |
58 | ||
59 | template < typename X, typename Y > | |
60 | void OutputAssertEqualOr3(X expect1, X expect2, X expect3, char const* compare, Y get, unsigned long const &line) { | |
61 | std::cerr << "Test FAILED: »" << expect1 << "« or »" << expect2 << "« or »" << expect3 << "« " << compare << " »" << get << "« at line " << line << std::endl; | |
62 | } | |
63 | ||
64 | template < typename X, typename Y > | |
65 | void assertEqualsOr3(X expect1, X expect2, X expect3, Y get, unsigned long const &line) { | |
66 | if (expect1 == get || expect2 == get || expect3 == get) | |
67 | return; | |
68 | OutputAssertEqualOr3(expect1, expect2, expect3, "==", get, line); | |
69 | } | |
70 | ||
71 | ||
f7f0d6c7 DK |
72 | // simple helper to quickly output a vectors |
73 | template < typename X > | |
74 | void dumpVector(X vec) { | |
75 | for (typename X::const_iterator v = vec.begin(); | |
76 | v != vec.end(); ++v) | |
77 | std::cout << *v << std::endl; | |
78 | } |