Skip to content

Commit d2fc085

Browse files
authored
update heap unit tests (#7324)
* new heap invariants * change ENSURE to SASSERT for unit test heap * change SASSERT to VERIFY * update heap tests * update * remove one invariant
1 parent fce4b36 commit d2fc085

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/test/heap.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ struct lt_proc { bool operator()(int v1, int v2) const { return v1 < v2; } };
2727
//struct int_hash_proc { unsigned operator()(int v) const { std::cout << "hash " << v << "\n"; VERIFY(v >= 0); return v; }};
2828
//typedef int_hashtable<int_hash_proc, default_eq<int> > int_set;
2929
typedef heap<lt_proc> int_heap;
30-
#define N 10000
30+
#define N 100
3131

3232
static random_gen heap_rand(1);
3333

@@ -146,4 +146,3 @@ void tst_heap() {
146146
tst2();
147147
}
148148
}
149-

src/util/heap.h

+13
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,19 @@ class heap : private LT {
5555
}
5656

5757
bool check_invariant_core(int idx) const {
58+
59+
// Check that m_values starts with a dummy value at index 0.
60+
if (m_values.empty() || m_values[0] != -1) {
61+
return false;
62+
}
63+
64+
// // All indices in m_value2indices that are not used in m_values should be 0
65+
// for (int val = 0; val < static_cast<int>(m_value2indices.size()); ++val) {
66+
// if (std::find(m_values.begin(), m_values.end(), val) == m_values.end() && m_value2indices[val] != 0) {
67+
// return false; // Unused indices should have a 0 value
68+
// }
69+
// }
70+
5871
if (idx < static_cast<int>(m_values.size())) {
5972
SASSERT(m_value2indices[m_values[idx]] == idx);
6073
SASSERT(parent(idx) == 0 || !less_than(m_values[idx], m_values[parent(idx)]));

0 commit comments

Comments
 (0)