-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_lib.cpp
166 lines (128 loc) · 3.61 KB
/
test_lib.cpp
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#include "weilei_lib.h"
void standard_test();
void test_mmio();
void test_getC();
void test_CSS_code();
void test_classical_code();
void test_print(char * text);
int main(){
std::cout<<" --------------------- begin test"<<std::endl;
// test_getC();
// test_classical_code();
// test_CSS_code();
// test_mmio();
standard_test();
std::cout<<" --------------------- finish test"<<std::endl;
return 0;
}
// ============ implementations ==============
void standard_test(){
//run all the test
test_print("getC()"); test_getC();
test_classical_code();
test_CSS_code();
test_print("test_mmio"); test_mmio();
return;
}
void test_print(char * text){
//a print function used through out the tests
std::cout<<"---------------------- "<<text<<std::endl;
}
void test_mmio(){
//test mmio interface
itpp::GF2mat G = common::get_check_code743(7); //init a matrix
GF2mat_to_MM(G, "tmp/G.mm"); //save matrix to a temp file
std::cout<<"The matrix is saved into tmp/G.mm"<<std::endl;
itpp::GF2mat H = MM_to_GF2mat("tmp/G.mm"); //read matrix from the file
std::cout<<H<<std::endl;
return;
}
void test_getC(){
//test othorgonality of matrices from the code generated by getC()
ClassicalCode code;
code.get_743_code(7);
code.dist();
itpp::GF2mat H = code.H;
std::cout<<"H is the parity check matrix of Hamming code"
<<std::endl<<H<<std::endl;
itpp::GF2mat G = H;//common::nullSpace(H);
std::cout<<"G is the same as H"<<std::endl<<G<<std::endl;
if ( ( G*H.transpose() ).is_zero() ){
std::cout<<"checked: G*H^T=0\n";
}
itpp::GF2mat C = common::getC(G,H);
std::cout<<"C is the codeword generating matrix"
<<std::endl<<C<<std::endl;
return;
}
void test_classical_code(){
std::cout<<"begin test for ClassicalCode"<<std::endl;
ClassicalCode code;
if ( code.is_defined ){
std::cout<<"code is_defined"<<std::endl;
}else{
std::cout<<"code is_defined"<<std::endl;
}
//Hamming code
// code.n = 7;
code.get_743_code(7);
code.full_rank();
code.title="Hamming code";
code.info();
code.d = code.dist();
std::cout<<"The Hamming [7,4,3] code has distance d="<<code.d<<std::endl;
//repetition code
code.title="repetition code";
code.get_repetition_code(7);
code.full_rank();
// code.info();
code.d = code.dist();
std::cout<<"repetition code: d="<<code.d<<std::endl;
std::cout<<code<<std::endl;
std::cout<<"finish test for ClassicalCode"<<std::endl;
return;
}
void test_CSS_code(){
std::cout<<"begin test for CSSCode"<<std::endl;
CSSCode code;
code.n = 7;
code.title="Quantum hamming 713 code";
code.get_713_code();
// std::cout<<code<<std::endl;
// code.full_rank();
// code.info();
// code.d =
code.dist();
std::cout<<"[7,1,3] Hamming code: dx="<<code.dx<<std::endl;
std::cout<<code<<std::endl;
std::cout<<"finish test for CSSCode"<<std::endl;
std::cout<<"begin test for ProductCSSCode"<<std::endl;
//random CSS code
CSSCode codeR;
codeR.title="random code";
codeR.n=7;
codeR.Gx_row=3;
codeR.Gz_row=3;
codeR.id_Gx=3511;
codeR.id_Gz=2657;
codeR.generate_by_id(0);
codeR.dist();
std::cout<<codeR<<std::endl;
std::cout<<codeR.Gx<<std::endl;
std::cout<<codeR.Gz<<std::endl;
ProductCSSCode codeP;
codeP.n=10;
codeP.title="some codeP";
std::cout<<codeP<<std::endl;
ConcatenatedProductCSSCode codeCP;
codeCP.n=61;
std::cout<<codeCP<<std::endl;
SubsystemProductCSSCode codeSP;
codeSP.n=9;
SubsystemProductCSSCode codeSP2;
codeSP=codeSP2;
std::cout<<codeSP<<std::endl;
// codeSP.info();
std::cout<<"finish test for ProductCSSCode"<<std::endl;
return;
}