Skip to content

Commit eda8309

Browse files
committed
Assert immediately rather than caching failure
1 parent 5560845 commit eda8309

File tree

1 file changed

+23
-34
lines changed

1 file changed

+23
-34
lines changed

src/test/fuzz/prevector.cpp

Lines changed: 23 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -25,68 +25,61 @@ class prevector_tester {
2525
pretype pre_vector_alt;
2626

2727
typedef typename pretype::size_type Size;
28-
bool passed = true;
2928

30-
template <typename A, typename B>
31-
void local_check_equal(A a, B b)
32-
{
33-
local_check(a == b);
34-
}
35-
36-
void local_check(bool b)
37-
{
38-
passed &= b;
39-
}
4029
void test() {
4130
const pretype& const_pre_vector = pre_vector;
42-
local_check_equal(real_vector.size(), pre_vector.size());
43-
local_check_equal(real_vector.empty(), pre_vector.empty());
31+
assert(real_vector.size() == pre_vector.size());
32+
assert(real_vector.empty() == pre_vector.empty());
4433
for (Size s = 0; s < real_vector.size(); s++) {
45-
local_check(real_vector[s] == pre_vector[s]);
46-
local_check(&(pre_vector[s]) == &(pre_vector.begin()[s]));
47-
local_check(&(pre_vector[s]) == &*(pre_vector.begin() + s));
48-
local_check(&(pre_vector[s]) == &*((pre_vector.end() + s) - real_vector.size()));
34+
assert(real_vector[s] == pre_vector[s]);
35+
assert(&(pre_vector[s]) == &(pre_vector.begin()[s]));
36+
assert(&(pre_vector[s]) == &*(pre_vector.begin() + s));
37+
assert(&(pre_vector[s]) == &*((pre_vector.end() + s) - real_vector.size()));
4938
}
50-
// local_check(realtype(pre_vector) == real_vector);
51-
local_check(pretype(real_vector.begin(), real_vector.end()) == pre_vector);
52-
local_check(pretype(pre_vector.begin(), pre_vector.end()) == pre_vector);
39+
// assert(realtype(pre_vector) == real_vector);
40+
assert(pretype(real_vector.begin(), real_vector.end()) == pre_vector);
41+
assert(pretype(pre_vector.begin(), pre_vector.end()) == pre_vector);
5342
size_t pos = 0;
5443
for (const T& v : pre_vector) {
55-
local_check(v == real_vector[pos++]);
44+
assert(v == real_vector[pos]);
45+
++pos;
5646
}
5747
for (const T& v : reverse_iterate(pre_vector)) {
58-
local_check(v == real_vector[--pos]);
48+
--pos;
49+
assert(v == real_vector[pos]);
5950
}
6051
for (const T& v : const_pre_vector) {
61-
local_check(v == real_vector[pos++]);
52+
assert(v == real_vector[pos]);
53+
++pos;
6254
}
6355
for (const T& v : reverse_iterate(const_pre_vector)) {
64-
local_check(v == real_vector[--pos]);
56+
--pos;
57+
assert(v == real_vector[pos]);
6558
}
6659
CDataStream ss1(SER_DISK, 0);
6760
CDataStream ss2(SER_DISK, 0);
6861
ss1 << real_vector;
6962
ss2 << pre_vector;
70-
local_check_equal(ss1.size(), ss2.size());
63+
assert(ss1.size() == ss2.size());
7164
for (Size s = 0; s < ss1.size(); s++) {
72-
local_check_equal(ss1[s], ss2[s]);
65+
assert(ss1[s] == ss2[s]);
7366
}
7467
}
7568

7669
public:
7770
void resize(Size s) {
7871
real_vector.resize(s);
79-
local_check_equal(real_vector.size(), s);
72+
assert(real_vector.size() == s);
8073
pre_vector.resize(s);
81-
local_check_equal(pre_vector.size(), s);
74+
assert(pre_vector.size() == s);
8275
test();
8376
}
8477

8578
void reserve(Size s) {
8679
real_vector.reserve(s);
87-
local_check(real_vector.capacity() >= s);
80+
assert(real_vector.capacity() >= s);
8881
pre_vector.reserve(s);
89-
local_check(pre_vector.capacity() >= s);
82+
assert(pre_vector.capacity() >= s);
9083
test();
9184
}
9285

@@ -199,10 +192,6 @@ class prevector_tester {
199192
}
200193
test();
201194
}
202-
203-
~prevector_tester() {
204-
assert(passed);
205-
}
206195
};
207196

208197
}

0 commit comments

Comments
 (0)