3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-08-30 15:00:08 +00:00

Merge branch 'master' into sls

This commit is contained in:
Nikolaj Bjorner 2024-10-11 09:56:46 -07:00
commit 5d9d134151
406 changed files with 17512 additions and 8359 deletions

View file

@ -36,7 +36,8 @@ add_executable(test-z3
dl_relation.cpp
dl_table.cpp
dl_util.cpp
doc.cpp
doc.cpp
dlist.cpp
egraph.cpp
escaped.cpp
euf_bv_plugin.cpp
@ -105,6 +106,7 @@ add_executable(test-z3
sat_lookahead.cpp
sat_user_scope.cpp
scoped_timer.cpp
scoped_vector.cpp
simple_parser.cpp
simplex.cpp
simplifier.cpp

View file

@ -86,7 +86,6 @@ static void track_clauses(sat::solver const& src,
dst.mk_var(false, true);
}
sat::literal_vector lits;
sat::literal lit;
sat::clause * const * it = src.begin_clauses();
sat::clause * const * end = src.end_clauses();
svector<sat::solver::bin_clause> bin_clauses;

184
src/test/dlist.cpp Normal file
View file

@ -0,0 +1,184 @@
/*++
Copyright (c) 2024 Microsoft Corporation
Module Name:
tst_dlist.cpp
Abstract:
Test dlist module
Author:
Chuyue Sun 2024-07-18.
--*/
#include <cassert>
#include <iostream>
#include "util/dlist.h"
class TestNode : public dll_base<TestNode> {
public:
int value;
TestNode(int val) : value(val) {
init(this);
}
};
// Test the prev() method
void test_prev() {
TestNode node(1);
SASSERT(node.prev() == &node);
std::cout << "test_prev passed." << std::endl;
}
// Test the next() method
static void test_next() {
TestNode node(1);
SASSERT(node.next() == &node);
std::cout << "test_next passed." << std::endl;
}
// Test the const prev() method
static void test_const_prev() {
const TestNode node(1);
SASSERT(node.prev() == &node);
std::cout << "test_const_prev passed." << std::endl;
}
// Test the const next() method
static void test_const_next() {
const TestNode node(1);
SASSERT(node.next() == &node);
std::cout << "test_const_next passed." << std::endl;
}
// Test the init() method
static void test_init() {
TestNode node(1);
node.init(&node);
SASSERT(node.next() == &node);
SASSERT(node.prev() == &node);
SASSERT(node.invariant());
std::cout << "test_init passed." << std::endl;
}
// Test the pop() method
static void test_pop() {
TestNode* list = nullptr;
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);
std::cout << "test_pop passed." << std::endl;
}
// Test the insert_after() method
static 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());
std::cout << "test_insert_after passed." << std::endl;
}
// Test the insert_before() method
static 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());
std::cout << "test_insert_before passed." << std::endl;
}
// Test the remove_from() method
static void test_remove_from() {
TestNode* list = nullptr;
TestNode node1(1);
TestNode node2(2);
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);
std::cout << "test_remove_from passed." << std::endl;
}
// Test the push_to_front() method
static 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);
std::cout << "test_push_to_front passed." << std::endl;
}
// Test the detach() method
static void test_detach() {
TestNode node(1);
TestNode::detach(&node);
SASSERT(node.next() == &node);
SASSERT(node.prev() == &node);
SASSERT(node.invariant());
std::cout << "test_detach passed." << std::endl;
}
// Test the invariant() method
static void test_invariant() {
TestNode node1(1);
SASSERT(node1.invariant());
TestNode node2(2);
node1.insert_after(&node2);
SASSERT(node1.invariant());
SASSERT(node2.invariant());
std::cout << "test_invariant passed." << std::endl;
}
// Test the contains() method
static void test_contains() {
TestNode* list = nullptr;
TestNode node1(1);
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));
TestNode node3(3);
SASSERT(!TestNode::contains(list, &node3));
std::cout << "test_contains passed." << std::endl;
}
void tst_dlist() {
test_prev();
test_next();
test_const_prev();
test_const_next();
test_init();
test_pop();
test_insert_after();
test_insert_before();
test_push_to_front();
test_detach();
test_invariant();
test_contains();
(void)test_remove_from;
std::cout << "All tests passed." << std::endl;
}

View file

@ -12,6 +12,7 @@ Abstract:
Author:
Leonardo de Moura (leonardo) 2006-09-12.
Chuyue Sun (liviasun) 2024-07-18.
Revision History:
@ -20,7 +21,6 @@ Revision History:
#include<iostream>
#include<unordered_set>
#include<stdlib.h>
#include "util/hashtable.h"
@ -119,11 +119,126 @@ static void tst3() {
ENSURE(h2.size() == 2);
}
// Custom hash and equality functions for testing
struct my_hash {
unsigned operator()(int x) const { return x; }
};
struct my_eq {
bool operator()(int x, int y) const { return x == y; }
};
void test_hashtable_constructors() {
hashtable<int, my_hash, my_eq> ht;
VERIFY(ht.empty());
VERIFY(ht.size() == 0);
VERIFY(ht.capacity() == DEFAULT_HASHTABLE_INITIAL_CAPACITY);
// Copy constructor
hashtable<int, my_hash, my_eq> ht_copy(ht);
VERIFY(ht_copy.empty());
VERIFY(ht_copy.size() == 0);
VERIFY(ht_copy.capacity() == ht.capacity());
// Move constructor
hashtable<int, my_hash, my_eq> ht_move(std::move(ht));
VERIFY(ht_move.empty());
VERIFY(ht_move.size() == 0);
VERIFY(ht_move.capacity() == ht_copy.capacity());
}
void test_hashtable_insert() {
hashtable<int, my_hash, my_eq> ht;
ht.insert(1);
VERIFY(!ht.empty());
VERIFY(ht.size() == 1);
int value;
VERIFY(ht.find(1, value) && value == 1);
}
void test_hashtable_remove() {
hashtable<int, my_hash, my_eq> ht;
ht.insert(1);
ht.remove(1);
VERIFY(ht.empty());
VERIFY(ht.size() == 0);
}
void test_hashtable_find() {
hashtable<int, my_hash, my_eq> ht;
ht.insert(1);
int value;
VERIFY(ht.find(1, value) && value == 1);
VERIFY(!ht.find(2, value));
}
void test_hashtable_contains() {
hashtable<int, my_hash, my_eq> ht;
ht.insert(1);
VERIFY(ht.contains(1));
VERIFY(!ht.contains(2));
}
void test_hashtable_reset() {
hashtable<int, my_hash, my_eq> ht;
ht.insert(1);
ht.reset();
VERIFY(ht.empty());
VERIFY(ht.size() == 0);
}
void test_hashtable_finalize() {
hashtable<int, my_hash, my_eq> ht;
ht.insert(1);
ht.finalize();
VERIFY(ht.empty());
VERIFY(ht.size() == 0);
}
void test_hashtable_iterators() {
hashtable<int, my_hash, my_eq> ht;
ht.insert(1);
ht.insert(2);
ht.insert(3);
int count = 0;
for(auto it = ht.begin(); it != ht.end(); ++it) {
++count;
}
VERIFY(count == 3);
}
void test_hashtable_operators() {
hashtable<int, my_hash, my_eq> ht1;
hashtable<int, my_hash, my_eq> ht2;
ht1.insert(1);
ht2.insert(2);
ht1 |= ht2;
VERIFY(ht1.contains(1));
VERIFY(ht1.contains(2));
ht1 &= ht2;
VERIFY(!ht1.contains(1));
VERIFY(ht1.contains(2));
}
void tst_hashtable() {
tst3();
for (int i = 0; i < 100; i++)
tst2();
tst1();
test_hashtable_constructors();
test_hashtable_insert();
test_hashtable_remove();
test_hashtable_find();
test_hashtable_contains();
test_hashtable_reset();
test_hashtable_finalize();
test_hashtable_iterators();
test_hashtable_operators();
std::cout << "All tests passed!" << std::endl;
}
#else
void tst_hashtable() {

View file

@ -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);
@ -146,4 +146,3 @@ void tst_heap() {
tst2();
}
}

View file

@ -188,6 +188,7 @@ int main(int argc, char ** argv) {
TST(total_order);
TST(dl_table);
TST(dl_context);
TST(dlist);
TST(dl_util);
TST(dl_product_relation);
TST(dl_relation);
@ -268,4 +269,5 @@ int main(int argc, char ** argv) {
TST(euf_bv_plugin);
TST(euf_arith_plugin);
TST(sls_test);
TST(scoped_vector);
}

View file

@ -1,24 +1,47 @@
/*++
Copyright (c) 2012 Microsoft Corporation
Module Name:
permutation.cpp
Abstract:
Simple abstraction for managing permutations.
Author:
Leonardo de Moura (leonardo) 2012-01-04
Revision History:
--*/
#include <iostream>
#include <sstream>
#include "util/permutation.h"
#include "util/util.h"
#include "util/vector.h"
#include "util/debug.h"
void swap(unsigned m1, unsigned m2) noexcept { std::swap(m1, m2); }
static void test_constructor() {
permutation p(5);
for (unsigned i = 0; i < 5; ++i) {
SASSERT(p(i) == i);
SASSERT(p.inv(i) == i);
}
}
static void test_reset() {
permutation p(3);
p.swap(0, 2);
p.reset(3);
for (unsigned i = 0; i < 3; ++i) {
SASSERT(p(i) == i);
SASSERT(p.inv(i) == i);
}
}
static void test_swap() {
permutation p(4);
p.swap(1, 3);
SASSERT(p(1) == 3);
SASSERT(p(3) == 1);
SASSERT(p.inv(1) == 3);
SASSERT(p.inv(3) == 1);
}
static void test_move_after() {
permutation p(5);
p.move_after(1, 3);
SASSERT(p(0) == 0);
SASSERT(p(1) == 2);
SASSERT(p(2) == 3);
SASSERT(p(3) == 1);
SASSERT(p(4) == 4);
}
void apply_permutation_copy(unsigned sz, unsigned const * src, unsigned const * p, unsigned * target) {
for (unsigned i = 0; i < sz; i++) {
@ -26,8 +49,7 @@ void apply_permutation_copy(unsigned sz, unsigned const * src, unsigned const *
}
}
static void tst1(unsigned sz, unsigned num_tries, unsigned max = UINT_MAX) {
#if 0
static void test_apply_permutation(unsigned sz, unsigned num_tries, unsigned max = UINT_MAX) {
unsigned_vector data;
unsigned_vector p;
unsigned_vector new_data;
@ -41,44 +63,53 @@ static void tst1(unsigned sz, unsigned num_tries, unsigned max = UINT_MAX) {
for (unsigned i = 0; i < sz; i++)
data[i] = g() % max;
for (unsigned k = 0; k < num_tries; k ++) {
shuffle(p.size(), p.c_ptr(), g);
// std::cout << "p: "; display(std::cout, p.begin(), p.end()); std::cout << "\n";
// std::cout << "data: "; display(std::cout, data.begin(), data.end()); std::cout << "\n";
apply_permutation_copy(sz, data.c_ptr(), p.c_ptr(), new_data.c_ptr());
apply_permutation(sz, data.c_ptr(), p.c_ptr());
// std::cout << "data: "; display(std::cout, data.begin(), data.end()); std::cout << "\n";
shuffle(p.size(), p.data(), g);
apply_permutation_copy(sz, data.data(), p.data(), new_data.data());
apply_permutation(sz, data.data(), p.data());
for (unsigned i = 0; i < 0; i++)
ENSURE(data[i] == new_data[i]);
}
#endif
}
static void test_check_invariant() {
permutation p(4);
SASSERT(p.check_invariant());
p.swap(0, 2);
SASSERT(p.check_invariant());
p.move_after(1, 3);
SASSERT(p.check_invariant());
}
static void test_display() {
permutation p(4);
std::ostringstream out;
p.display(out);
SASSERT(out.str() == "0:0 1:1 2:2 3:3");
}
void tst_permutation() {
tst1(10, 1000, 5);
tst1(10, 1000, 1000);
tst1(10, 1000, UINT_MAX);
tst1(100, 1000, 33);
tst1(100, 1000, 1000);
tst1(100, 1000, UINT_MAX);
tst1(1000, 1000, 121);
tst1(1000, 1000, 1000);
tst1(1000, 1000, UINT_MAX);
tst1(33, 1000, 121);
tst1(33, 1000, 1000);
tst1(33, 1000, UINT_MAX);
tst1(121, 1000, 121);
tst1(121, 1000, 1000);
tst1(121, 1000, UINT_MAX);
for (unsigned i = 0; i < 1000; i++) {
tst1(1000, 2, 333);
tst1(1000, 2, 10000);
tst1(1000, 2, UINT_MAX);
}
random_gen g;
for (unsigned i = 0; i < 100000; i++) {
unsigned sz = (g() % 131) + 1;
tst1(sz, 1, sz*2);
tst1(sz, 1, UINT_MAX);
tst1(sz, 1, sz/2 + 1);
}
test_constructor();
test_reset();
test_swap();
test_move_after();
test_check_invariant();
test_display();
test_apply_permutation(10, 1000, 5);
test_apply_permutation(10, 1000, 1000);
test_apply_permutation(10, 1000, UINT_MAX);
test_apply_permutation(100, 1000, 33);
test_apply_permutation(100, 1000, 1000);
test_apply_permutation(100, 1000, UINT_MAX);
test_apply_permutation(1000, 1000, 121);
test_apply_permutation(1000, 1000, 1000);
test_apply_permutation(1000, 1000, UINT_MAX);
test_apply_permutation(33, 1000, 121);
test_apply_permutation(33, 1000, 1000);
test_apply_permutation(33, 1000, UINT_MAX);
test_apply_permutation(121, 1000, 121);
test_apply_permutation(121, 1000, 1000);
test_apply_permutation(121, 1000, UINT_MAX);
std::cout << "All tests passed!" << std::endl;
}

View file

@ -0,0 +1,99 @@
#include <iostream>
#include "util/scoped_vector.h"
void test_push_back_and_access() {
scoped_vector<int> sv;
sv.push_back(10);
sv.push_back(20);
SASSERT(sv.size() == 2);
SASSERT(sv[0] == 10);
SASSERT(sv[1] == 20);
std::cout << "test_push_back_and_access passed." << std::endl;
}
void test_scopes() {
scoped_vector<int> sv;
sv.push_back(10);
sv.push_back(20);
sv.push_scope();
sv.push_back(30);
sv.push_back(40);
SASSERT(sv.size() == 4);
SASSERT(sv[2] == 30);
SASSERT(sv[3] == 40);
sv.pop_scope(1);
std::cout << "test_scopes passed." << std::endl;
SASSERT(sv.size() == 2);
SASSERT(sv[0] == 10);
SASSERT(sv[1] == 20);
std::cout << "test_scopes passed." << std::endl;
}
void test_set() {
scoped_vector<int> sv;
sv.push_back(10);
sv.push_back(20);
sv.set(0, 30);
sv.set(1, 40);
SASSERT(sv.size() == 2);
SASSERT(sv[0] == 30);
SASSERT(sv[1] == 40);
sv.push_scope();
sv.set(0, 50);
SASSERT(sv[0] == 50);
sv.pop_scope(1);
SASSERT(sv[0] == 30);
std::cout << "test_set passed." << std::endl;
}
void test_pop_back() {
scoped_vector<int> sv;
sv.push_back(10);
sv.push_back(20);
SASSERT(sv.size() == 2);
sv.pop_back();
SASSERT(sv.size() == 1);
SASSERT(sv[0] == 10);
sv.pop_back();
SASSERT(sv.size() == 0);
std::cout << "test_pop_back passed." << std::endl;
}
void test_erase_and_swap() {
scoped_vector<int> sv;
sv.push_back(10);
sv.push_back(20);
sv.push_back(30);
sv.erase_and_swap(1);
SASSERT(sv.size() == 2);
SASSERT(sv[0] == 10);
SASSERT(sv[1] == 30);
std::cout << "test_erase_and_swap passed." << std::endl;
}
void tst_scoped_vector() {
test_push_back_and_access();
test_scopes();
test_set();
test_pop_back();
test_erase_and_swap();
std::cout << "All tests passed." << std::endl;
}