-
Notifications
You must be signed in to change notification settings - Fork 3
/
test1.cpp
executable file
·131 lines (102 loc) · 2.55 KB
/
test1.cpp
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/*
© 2009, Jon Stewart
Released under the terms of the Boost license (http://www.boost.org/LICENSE_1_0.txt). See License.txt for details.
*/
#include "scope/test.h"
#include <vector>
#include <list>
#include <set>
SCOPE_TEST(simpleTest) {
SCOPE_ASSERT(true);
}
SCOPE_TEST(failTest) {
SCOPE_ASSERT(false); // ha-ha!
}
void doNothing() {
;
}
SCOPE_TEST(TestExpectMacro) {
SCOPE_EXPECT(throw int(1), int);
SCOPE_EXPECT(doNothing(), int);
}
SCOPE_TEST_FAILS(knownBadTest) {
SCOPE_ASSERT(false);
}
SCOPE_TEST_FAILS(aGoodBadTest) {
;
}
SCOPE_TEST_IGNORE(thisTestNeverRuns) {
*reinterpret_cast<int*>(1) = 25; // segfaults
}
SCOPE_TEST(simpleEquality) {
SCOPE_ASSERT_EQUAL(1, 1);
}
SCOPE_TEST(sequenceEquality) {
std::vector<int> e = {1, 2, 3};
std::list<int> a = {1, 2, 3};
SCOPE_ASSERT_EQUAL(e, a);
}
SCOPE_TEST(initListExpectedEqual) {
std::vector<int> a = {1, 2, 3};
std::list<int> b = {1, 2, 3};
SCOPE_ASSERT_EQUAL({1, 2, 3}, a);
SCOPE_ASSERT_EQUAL({1, 2, 3}, b);
}
SCOPE_TEST(initListActualEqual) {
std::vector<int> a = {1, 2, 3};
std::list<int> b = {1, 2, 3};
SCOPE_ASSERT_EQUAL(a, {1, 2, 3});
SCOPE_ASSERT_EQUAL(b, {1, 2, 3});
}
SCOPE_TEST(initListPedantic) {
SCOPE_ASSERT_EQUAL({1, 2, 3}, {1, 2, 3});
}
SCOPE_TEST(pairEquality) {
std::pair<short, std::string> a = {5, "hello"};
std::pair<int, std::string> b = {5, "hello, world"};
SCOPE_ASSERT_EQUAL(a, b);
}
SCOPE_TEST(setEquality) {
std::set<std::string> a {"hello", "world"};
std::set<std::string> b {"hello", "world"};
SCOPE_ASSERT_EQUAL(a, b);
}
SCOPE_TEST(setInequality) {
std::set<std::string> a {"hello", "world"};
std::set<std::string> b {"hello"};
SCOPE_ASSERT_EQUAL(a, b);
}
SCOPE_TEST(pairSequence) {
std::vector<std::pair<std::string, unsigned int>> actual = {{"hello", 5u}};
// actual.emplace_back({"hello", 5u});
SCOPE_ASSERT_EQUAL({std::make_pair(std::string("hello"), 5u)}, actual);
}
SCOPE_TEST(strings) {
std::string a("a");
std::string a2("a");
char cs[2];
cs[0] = 'a';
cs[1] = '\0';
char cs2[2];
cs2[0] = 'a';
cs2[1] = '\0';
char* cp = &cs2[0];
SCOPE_ASSERT_EQUAL(a, "a");
SCOPE_ASSERT_EQUAL("a", a);
SCOPE_ASSERT_EQUAL(a, a2);
SCOPE_ASSERT_EQUAL(a, cs);
SCOPE_ASSERT_EQUAL(cs, a);
SCOPE_ASSERT_EQUAL("a", cp);
}
SCOPE_TEST(nulls) {
void* v = 0;
char* x = 0;
int* z = nullptr;
SCOPE_ASSERT_EQUAL(nullptr, v);
SCOPE_ASSERT_EQUAL(nullptr, x);
SCOPE_ASSERT_EQUAL(nullptr, z);
// SCOPE_ASSERT_EQUAL(0, v);
// SCOPE_ASSERT_EQUAL(0, x);
// SCOPE_ASSERT_EQUAL(0, z);
// SCOPE_ASSERT_EQUAL(null, x);
}