]>
Commit | Line | Data |
---|---|---|
1 | #include <iostream> | |
2 | #include <cstdlib> | |
3 | ||
4 | #define equals(x,y) assertEquals(y, x, __LINE__) | |
5 | #define equalsNot(x,y) assertEqualsNot(y, x, __LINE__) | |
6 | ||
7 | template < typename X, typename Y > | |
8 | void OutputAssertEqual(X expect, char const* compare, Y get, unsigned long const &line) { | |
9 | std::cerr << "Test FAILED: »" << expect << "« " << compare << " »" << get << "« at line " << line << std::endl; | |
10 | std::exit(EXIT_FAILURE); | |
11 | } | |
12 | ||
13 | template < typename X, typename Y > | |
14 | void assertEquals(X expect, Y get, unsigned long const &line) { | |
15 | if (expect == get) | |
16 | return; | |
17 | OutputAssertEqual(expect, "==", get, line); | |
18 | } | |
19 | ||
20 | template < typename X, typename Y > | |
21 | void assertEqualsNot(X expect, Y get, unsigned long const &line) { | |
22 | if (expect != get) | |
23 | return; | |
24 | OutputAssertEqual(expect, "!=", get, line); | |
25 | } | |
26 | ||
27 | void assertEquals(unsigned int const &expect, int const &get, unsigned long const &line) { | |
28 | if (get < 0) | |
29 | OutputAssertEqual(expect, "==", get, line); | |
30 | assertEquals<unsigned int const&, unsigned int const&>(expect, get, line); | |
31 | } | |
32 | ||
33 | void assertEquals(int const &expect, unsigned int const &get, unsigned long const &line) { | |
34 | if (expect < 0) | |
35 | OutputAssertEqual(expect, "==", get, line); | |
36 | assertEquals<unsigned int const&, unsigned int const&>(expect, get, line); | |
37 | } | |
38 | ||
39 | void assertEquals(unsigned long const &expect, int const &get, unsigned long const &line) { | |
40 | if (get < 0) | |
41 | OutputAssertEqual(expect, "==", get, line); | |
42 | assertEquals<unsigned long const&, unsigned long const&>(expect, get, line); | |
43 | } | |
44 | ||
45 | void assertEquals(int const &expect, unsigned long const &get, unsigned long const &line) { | |
46 | if (expect < 0) | |
47 | OutputAssertEqual(expect, "==", get, line); | |
48 | assertEquals<unsigned long const&, unsigned long const&>(expect, get, line); | |
49 | } | |
50 | ||
51 | ||
52 | #define equalsOr2(x,y,z) assertEqualsOr2(y, z, x, __LINE__) | |
53 | ||
54 | template < typename X, typename Y > | |
55 | void OutputAssertEqualOr2(X expect1, X expect2, char const* compare, Y get, unsigned long const &line) { | |
56 | std::cerr << "Test FAILED: »" << expect1 << "« or »" << expect2 << "« " << compare << " »" << get << "« at line " << line << std::endl; | |
57 | } | |
58 | ||
59 | template < typename X, typename Y > | |
60 | void assertEqualsOr2(X expect1, X expect2, Y get, unsigned long const &line) { | |
61 | if (expect1 == get || expect2 == get) | |
62 | return; | |
63 | OutputAssertEqualOr2(expect1, expect2, "==", get, line); | |
64 | } | |
65 | ||
66 | void assertEqualsOr2(unsigned int const &expect1, unsigned int const &expect2, int const &get, unsigned long const &line) { | |
67 | if (get < 0) | |
68 | OutputAssertEqualOr2(expect1, expect2, "==", get, line); | |
69 | assertEqualsOr2<unsigned int const&, unsigned int const&>(expect1, expect2, get, line); | |
70 | } | |
71 | ||
72 | void assertEqualsOr2(int const &expect1, int const &expect2, unsigned int const &get, unsigned long const &line) { | |
73 | if (expect1 < 0 && expect2 < 0) | |
74 | OutputAssertEqualOr2(expect1, expect2, "==", get, line); | |
75 | assertEqualsOr2<unsigned int const&, unsigned int const&>(expect1, expect2, get, line); | |
76 | } | |
77 | ||
78 | ||
79 | #define equalsOr3(w,x,y,z) assertEqualsOr3(x, y, z, w, __LINE__) | |
80 | ||
81 | template < typename X, typename Y > | |
82 | void OutputAssertEqualOr3(X expect1, X expect2, X expect3, char const* compare, Y get, unsigned long const &line) { | |
83 | std::cerr << "Test FAILED: »" << expect1 << "« or »" << expect2 << "« or »" << expect3 << "« " << compare << " »" << get << "« at line " << line << std::endl; | |
84 | } | |
85 | ||
86 | template < typename X, typename Y > | |
87 | void assertEqualsOr3(X expect1, X expect2, X expect3, Y get, unsigned long const &line) { | |
88 | if (expect1 == get || expect2 == get || expect3 == get) | |
89 | return; | |
90 | OutputAssertEqualOr3(expect1, expect2, expect3, "==", get, line); | |
91 | } | |
92 | ||
93 | #define equalsOr4(v,w,x,y,z) assertEqualsOr4(w, x, y, z, v, __LINE__) | |
94 | ||
95 | template < typename X, typename Y > | |
96 | void OutputAssertEqualOr4(X expect1, X expect2, X expect3, X expect4, char const* compare, Y get, unsigned long const &line) { | |
97 | std::cerr << "Test FAILED: »" << expect1 << "« or »" << expect2 << "« or »" << expect3 << "« or »" << expect4 << "« " << compare << " »" << get << "« at line " << line << std::endl; | |
98 | } | |
99 | ||
100 | template < typename X, typename Y > | |
101 | void assertEqualsOr4(X expect1, X expect2, X expect3, X expect4, Y get, unsigned long const &line) { | |
102 | if (expect1 == get || expect2 == get || expect3 == get || expect4 == get) | |
103 | return; | |
104 | OutputAssertEqualOr4(expect1, expect2, expect3, expect4, "==", get, line); | |
105 | } | |
106 | ||
107 | // simple helper to quickly output a vectors | |
108 | template < typename X > | |
109 | void dumpVector(X vec) { | |
110 | for (typename X::const_iterator v = vec.begin(); | |
111 | v != vec.end(); ++v) | |
112 | std::cout << *v << std::endl; | |
113 | } |