Repository navigation
Expand file tree
/
Copy pathtest_un_boolean.cpp
More file actions
66 lines (60 loc) · 2.01 KB
/
Copy pathtest_un_boolean.cpp
File metadata and controls
66 lines (60 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include "boolean_fun.h"
#include <assert.h>
#include <iostream>
#include <math.h>
#include <time.h>
using namespace std;
int main() {
// Test truth_table_to_univariate,univariate_to_truth_table
int n = 12;
int test_amount = 20;
Field_X tf(n);
BooleanFun g(n);
cout << "End of initialization of field and booleanfun." << endl;
for (int k = 0; k < test_amount; k++) {
g.set_truth_table_random();
string pre = g.get_truth_table_hex();
g.truth_table_to_univariate(tf);
assert(g.is_univariate_boolean(tf) == true);
for (int i = 0; i < (1 << n); i++) {
g.set_truth_table(i, 0);
}
g.univariate_to_truth_table(tf);
string cur = g.get_truth_table_hex();
for (int i = 0; i < (1 << n)/4; i++) {
//cout<< pre[i]<<" "<< cur[i]<<endl;
assert(pre[i]==cur[i]);
}
}
cout<<"End of test for truth_table_to_univariate and univariate_to_truth_table."<<endl;
// Test set_univariate
string un_str = "1+x^4+x^8";
g.set_trace_univariate(un_str,tf);
const int* un = g.get_un_ptr();
assert(un[0] == 1);
assert(un[4] == 1);
assert(un[8] == 1);
un_str = "0+89x^1+98x^10+999x^987";
g.set_trace_univariate(un_str,tf);
un = g.get_un_ptr();
assert(un[0] == 0);
assert(un[1] == 89);
assert(un[10] == 98);
assert(un[987] == 999);
cout<<"End of test for set_univariate."<<endl;
//Performance test of set_trace_univariate
cout << "test of set_trace_univariate... " << endl;
clock_t start, end;
start = clock();
for (int i = 0; i < (1 << n); i++) {
string str = "x^" + to_string(i)+"+x^"+to_string((2*i)%(1<<n));
g.set_trace_univariate(str, tf);
cout << (i + 1) << " pass." << endl;
}
end = clock();
double t = double(end - start) / CLOCKS_PER_SEC;
cout << "total time = " << t << endl;
cout << "average time =" <<t/(1<<n) << endl;
cout<<"End of test. Everything looks good."<<endl;
return 0;
}