mirror of
https://github.com/Z3Prover/z3
synced 2025-08-05 10:50:24 +00:00
add apply_permutation tests
This commit is contained in:
parent
ad1a0ae89d
commit
6631c1e74f
1 changed files with 40 additions and 27 deletions
|
@ -42,35 +42,36 @@ void test_move_after() {
|
||||||
SASSERT(p(4) == 4);
|
SASSERT(p(4) == 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_apply_permutation() {
|
|
||||||
permutation p(4);
|
|
||||||
int data[] = {10, 20, 30, 40};
|
|
||||||
unsigned perm[] = {2, 1, 0, 3};
|
|
||||||
apply_permutation(4, data, perm);
|
|
||||||
std::cout << "000 " << data[0] << std::endl;
|
|
||||||
std::cout << "222 " << data[2] << std::endl;
|
|
||||||
|
|
||||||
SASSERT(data[0] == 10);
|
void apply_permutation_copy(unsigned sz, unsigned const * src, unsigned const * p, unsigned * target) {
|
||||||
SASSERT(data[1] == 20);
|
for (unsigned i = 0; i < sz; i++) {
|
||||||
SASSERT(data[2] == 30);
|
target[i] = src[p[i]];
|
||||||
SASSERT(data[3] == 40);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_apply_permutation_core()
|
static void test_apply_permutation(unsigned sz, unsigned num_tries, unsigned max = UINT_MAX) {
|
||||||
{
|
unsigned_vector data;
|
||||||
permutation p(4);
|
unsigned_vector p;
|
||||||
int data[] = {10, 20, 30, 40};
|
unsigned_vector new_data;
|
||||||
unsigned perm[] = {2, 1, 0, 3};
|
data.resize(sz);
|
||||||
apply_permutation_core(4, data, perm);
|
p.resize(sz);
|
||||||
std::cout << "000 " << data[0] << std::endl;
|
new_data.resize(sz);
|
||||||
std::cout << "222 " << data[2] << std::endl;
|
random_gen g;
|
||||||
|
for (unsigned i = 0; i < sz; i++)
|
||||||
SASSERT(data[0] == 10);
|
p[i] = i;
|
||||||
SASSERT(data[1] == 20);
|
// fill data with random numbers
|
||||||
SASSERT(data[2] == 30);
|
for (unsigned i = 0; i < sz; i++)
|
||||||
SASSERT(data[3] == 40);
|
data[i] = g() % max;
|
||||||
|
for (unsigned k = 0; k < num_tries; k ++) {
|
||||||
|
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]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void test_check_invariant() {
|
void test_check_invariant() {
|
||||||
permutation p(4);
|
permutation p(4);
|
||||||
SASSERT(p.check_invariant());
|
SASSERT(p.check_invariant());
|
||||||
|
@ -92,10 +93,22 @@ void tst_permutation() {
|
||||||
test_reset();
|
test_reset();
|
||||||
test_swap();
|
test_swap();
|
||||||
test_move_after();
|
test_move_after();
|
||||||
// test_apply_permutation();
|
|
||||||
// test_apply_permutation_core();
|
|
||||||
test_check_invariant();
|
test_check_invariant();
|
||||||
test_display();
|
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;
|
std::cout << "All tests passed!" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue