3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-15 13:28:47 +00:00
z3/src/test/dl_util.cpp
Nikolaj Bjorner b08ccc7816 added missing Copyright forms
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
2015-06-10 11:54:02 -07:00

58 lines
1.3 KiB
C++

/*++
Copyright (c) 2015 Microsoft Corporation
--*/
#include "dl_util.h"
using namespace datalog;
void dl_util_two_array_sort() {
const unsigned num = 97;
unsigned a1[num];
unsigned a2[num];
for(unsigned i=0; i<num; i++) {
a1[i]=(i*30)%num;
a2[i]=(i*30)%num+3;
}
datalog::sort_two_arrays(num, a1, a2);
for(unsigned i=0; i<num; i++) {
SASSERT(a2[i]==i+3);
}
}
void dl_util_cycle_from_permutation() {
unsigned permutation_arr[] = { 0, 1, 4, 3, 2, 5, 6, 7 };
unsigned_vector perm(sizeof(permutation_arr)/sizeof(unsigned), permutation_arr);
unsigned_vector cycle;
datalog::cycle_from_permutation(perm, cycle);
SASSERT(cycle.size()==2);
SASSERT(cycle[0]==2 || cycle[0]==4);
SASSERT(cycle[1]==2 || cycle[1]==4);
SASSERT((cycle[0]==2) == (cycle[1]==4));
unsigned permutation_arr2[] = { 1, 2, 3, 4, 5, 6, 7, 0 };
unsigned len2 = sizeof(permutation_arr2)/sizeof(unsigned);
unsigned_vector perm2(len2, permutation_arr2);
cycle.reset();
datalog::cycle_from_permutation(perm2, cycle);
for(unsigned i=0; i<len2; i++) {
SASSERT( (cycle[i]+1)%len2==cycle[(i+1)%len2] );
}
}
void tst_dl_util() {
dl_util_two_array_sort();
dl_util_cycle_from_permutation();
}