Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update heap unit tests #7324

Merged
merged 7 commits into from
Aug 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/test/heap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ struct lt_proc { bool operator()(int v1, int v2) const { return v1 < v2; } };
//struct int_hash_proc { unsigned operator()(int v) const { std::cout << "hash " << v << "\n"; VERIFY(v >= 0); return v; }};
//typedef int_hashtable<int_hash_proc, default_eq<int> > int_set;
typedef heap<lt_proc> int_heap;
#define N 10000
#define N 100

static random_gen heap_rand(1);

Expand Down Expand Up @@ -146,4 +146,3 @@ void tst_heap() {
tst2();
}
}

13 changes: 13 additions & 0 deletions src/util/heap.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,19 @@ class heap : private LT {
}

bool check_invariant_core(int idx) const {

// Check that m_values starts with a dummy value at index 0.
if (m_values.empty() || m_values[0] != -1) {
return false;
}

// // All indices in m_value2indices that are not used in m_values should be 0
// for (int val = 0; val < static_cast<int>(m_value2indices.size()); ++val) {
// if (std::find(m_values.begin(), m_values.end(), val) == m_values.end() && m_value2indices[val] != 0) {
// return false; // Unused indices should have a 0 value
// }
// }

if (idx < static_cast<int>(m_values.size())) {
SASSERT(m_value2indices[m_values[idx]] == idx);
SASSERT(parent(idx) == 0 || !less_than(m_values[idx], m_values[parent(idx)]));
Expand Down
Loading