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

Revert "add scoped vector unit test" #7317

Merged
merged 1 commit into from
Jul 30, 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
1 change: 0 additions & 1 deletion src/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ add_executable(test-z3
sat_lookahead.cpp
sat_user_scope.cpp
scoped_timer.cpp
scoped_vector.cpp
simple_parser.cpp
simplex.cpp
simplifier.cpp
Expand Down
79 changes: 41 additions & 38 deletions src/test/dlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Module Name:

--*/

#include <cassert>
#include <iostream>
#include "util/dlist.h"

Expand All @@ -29,38 +30,38 @@ class TestNode : public dll_base<TestNode> {
// Test the prev() method
void test_prev() {
TestNode node(1);
SASSERT(node.prev() == &node);
assert(node.prev() == &node);
std::cout << "test_prev passed." << std::endl;
}

// Test the next() method
void test_next() {
TestNode node(1);
SASSERT(node.next() == &node);
assert(node.next() == &node);
std::cout << "test_next passed." << std::endl;
}

// Test the const prev() method
void test_const_prev() {
const TestNode node(1);
SASSERT(node.prev() == &node);
assert(node.prev() == &node);
std::cout << "test_const_prev passed." << std::endl;
}

// Test the const next() method
void test_const_next() {
const TestNode node(1);
SASSERT(node.next() == &node);
assert(node.next() == &node);
std::cout << "test_const_next passed." << std::endl;
}

// Test the init() method
void test_init() {
TestNode node(1);
node.init(&node);
SASSERT(node.next() == &node);
SASSERT(node.prev() == &node);
SASSERT(node.invariant());
assert(node.next() == &node);
assert(node.prev() == &node);
assert(node.invariant());
std::cout << "test_init passed." << std::endl;
}

Expand All @@ -70,10 +71,10 @@ void test_pop() {
TestNode node1(1);
TestNode::push_to_front(list, &node1);
TestNode* popped = TestNode::pop(list);
SASSERT(popped == &node1);
SASSERT(list == nullptr);
SASSERT(popped->next() == popped);
SASSERT(popped->prev() == popped);
assert(popped == &node1);
assert(list == nullptr);
assert(popped->next() == popped);
assert(popped->prev() == popped);
std::cout << "test_pop passed." << std::endl;
}

Expand All @@ -82,12 +83,12 @@ void test_insert_after() {
TestNode node1(1);
TestNode node2(2);
node1.insert_after(&node2);
SASSERT(node1.next() == &node2);
SASSERT(node2.prev() == &node1);
SASSERT(node1.prev() == &node2);
SASSERT(node2.next() == &node1);
SASSERT(node1.invariant());
SASSERT(node2.invariant());
assert(node1.next() == &node2);
assert(node2.prev() == &node1);
assert(node1.prev() == &node2);
assert(node2.next() == &node1);
assert(node1.invariant());
assert(node2.invariant());
std::cout << "test_insert_after passed." << std::endl;
}

Expand All @@ -96,12 +97,12 @@ void test_insert_before() {
TestNode node1(1);
TestNode node2(2);
node1.insert_before(&node2);
SASSERT(node1.prev() == &node2);
SASSERT(node2.next() == &node1);
SASSERT(node1.next() == &node2);
SASSERT(node2.prev() == &node1);
SASSERT(node1.invariant());
SASSERT(node2.invariant());
assert(node1.prev() == &node2);
assert(node2.next() == &node1);
assert(node1.next() == &node2);
assert(node2.prev() == &node1);
assert(node1.invariant());
assert(node2.invariant());
std::cout << "test_insert_before passed." << std::endl;
}

Expand All @@ -113,9 +114,11 @@ void test_remove_from() {
TestNode::push_to_front(list, &node1);
TestNode::push_to_front(list, &node2);
TestNode::remove_from(list, &node1);
SASSERT(list == &node2);
SASSERT(node2.next() == &node2);
SASSERT(node2.prev() == &node2);
assert(list == &node2);
assert(node2.next() == &node2);
assert(node2.prev() == &node2);
assert(node1.next() == &node1);
assert(node1.prev() == &node1);
std::cout << "test_remove_from passed." << std::endl;
}

Expand All @@ -124,30 +127,30 @@ void test_push_to_front() {
TestNode* list = nullptr;
TestNode node1(1);
TestNode::push_to_front(list, &node1);
SASSERT(list == &node1);
SASSERT(node1.next() == &node1);
SASSERT(node1.prev() == &node1);
assert(list == &node1);
assert(node1.next() == &node1);
assert(node1.prev() == &node1);
std::cout << "test_push_to_front passed." << std::endl;
}

// Test the detach() method
void test_detach() {
TestNode node(1);
TestNode::detach(&node);
SASSERT(node.next() == &node);
SASSERT(node.prev() == &node);
SASSERT(node.invariant());
assert(node.next() == &node);
assert(node.prev() == &node);
assert(node.invariant());
std::cout << "test_detach passed." << std::endl;
}

// Test the invariant() method
void test_invariant() {
TestNode node1(1);
SASSERT(node1.invariant());
assert(node1.invariant());
TestNode node2(2);
node1.insert_after(&node2);
SASSERT(node1.invariant());
SASSERT(node2.invariant());
assert(node1.invariant());
assert(node2.invariant());
std::cout << "test_invariant passed." << std::endl;
}

Expand All @@ -158,10 +161,10 @@ void test_contains() {
TestNode node2(2);
TestNode::push_to_front(list, &node1);
TestNode::push_to_front(list, &node2);
SASSERT(TestNode::contains(list, &node1));
SASSERT(TestNode::contains(list, &node2));
assert(TestNode::contains(list, &node1));
assert(TestNode::contains(list, &node2));
TestNode node3(3);
SASSERT(!TestNode::contains(list, &node3));
assert(!TestNode::contains(list, &node3));
std::cout << "test_contains passed." << std::endl;
}

Expand Down
1 change: 0 additions & 1 deletion src/test/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,5 +269,4 @@ int main(int argc, char ** argv) {
TST(euf_bv_plugin);
TST(euf_arith_plugin);
TST(sls_test);
TST(scoped_vector);
}
99 changes: 0 additions & 99 deletions src/test/scoped_vector.cpp

This file was deleted.

44 changes: 3 additions & 41 deletions src/util/scoped_vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,46 +176,8 @@ class scoped_vector {
}

bool invariant() const {


if (!(m_size <= m_elems.size() && m_elems_start <= m_elems.size()))
return false;

// Check that source and destination trails have the same length.
if (m_src.size() != m_dst.size())
return false;
// The size of m_src, m_dst, and m_src_lim should be consistent with the scope stack.
if (m_src_lim.size() != m_sizes.size() || m_src.size() != m_dst.size())
return false;

// m_elems_lim stores the past sizes of m_elems for each scope. Each element in m_elems_lim should be
// within bounds and in non-decreasing order.
for (unsigned i = 1; i < m_elems_lim.size(); ++i) {
if (m_elems_lim[i - 1] > m_elems_lim[i]) return false;
}


// m_sizes tracks the size of the vector at each scope level.
// Each element in m_sizes should be non-decreasing and within the size of m_elems.
for (unsigned i = 1; i < m_sizes.size(); ++i) {
if (m_sizes[i - 1] > m_sizes[i])
return false;
}

// The m_src and m_dst vectors should have the same size and should contain valid indices.
if (m_src.size() != m_dst.size()) return false;
for (unsigned i = 0; i < m_src.size(); ++i) {
if (m_src[i] >= m_index.size() || m_dst[i] >= m_elems.size()) return false;
}


// The size of m_src_lim should be less than or equal to the size of m_sizes and store valid indices.
if (m_src_lim.size() > m_sizes.size()) return false;
for (unsigned elem : m_src_lim) {
if (elem > m_src.size()) return false;
}

return true;

return
m_size <= m_elems.size() &&
m_elems_start <= m_elems.size();
}
};
Loading