-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_comparable.cc
67 lines (57 loc) · 1.68 KB
/
test_comparable.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include "compare.h"
#include <cassert>
#include <cstdlib>
struct nodeX {
nodeX(int xx) : x(xx) { }
lace::compare_t cmp(const nodeX &that) const { return lace::compare(x, that.x); }
private:
int x;
};
LACE_COMPARABLE(nodeX, cmp);
struct nodeLT {
nodeLT(int xx) : x(xx) { }
friend bool operator<(const nodeLT &foo, const nodeLT &bar) { return foo.x < bar.x; }
private:
int x;
};
LACE_COMPARABLE_LT(nodeLT);
template <typename T> void test() {
assert( (T(-1) != T(+1)) );
assert( (T(-1) < T(+1)) );
assert( (T(-1) <= T(+1)) );
assert(!(T(-1) == T(+1)) );
assert(!(T(-1) >= T(+1)) );
assert(!(T(-1) > T(+1)) );
assert(!(T( 0) != T( 0)) );
assert(!(T( 0) < T( 0)) );
assert( (T( 0) <= T( 0)) );
assert( (T( 0) == T( 0)) );
assert( (T( 0) >= T( 0)) );
assert(!(T( 0) > T( 0)) );
assert( (T(+1) != T(-1)) );
assert(!(T(+1) < T(-1)) );
assert(!(T(+1) <= T(-1)) );
assert(!(T(+1) == T(-1)) );
assert( (T(+1) >= T(-1)) );
assert( (T(+1) > T(-1)) );
}
int main(int, char*[]) {
test<int>();
test<nodeX>();
test<nodeLT>();
assert( (lace::compare("a","b") != 0));
assert( (lace::compare("a","b") < 0));
assert( (lace::compare("a","b") <= 0));
assert(!(lace::compare("a","b") == 0));
assert(!(lace::compare("a","b") >= 0));
assert(!(lace::compare("a","b") > 0));
assert(!(lace::compare("a","a") != 0));
assert(!(lace::compare("a","a") < 0));
assert( (lace::compare("a","a") <= 0));
assert( (lace::compare("a","a") == 0));
assert( (lace::compare("a","a") >= 0));
assert(!(lace::compare("a","a") > 0));
assert(!(lace::compare(L"a", L"a") != 0));
assert(!(lace::compare(std::string("a"),std::string("a")) != 0));
return EXIT_SUCCESS;
}