-
Notifications
You must be signed in to change notification settings - Fork 7
/
frequency_test_within_a_block.cpp
57 lines (47 loc) · 1.47 KB
/
frequency_test_within_a_block.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
namespace test{
double frequency_test_within_a_block(const vector<bool> &bits, int m){
if (bits.size()==0 || m<=0 || bits.size()<m){
cerr<<"Illegal parameter!"<<endl;
throw;
}
int n = bits.size();
int N = n/m;
int n_disc = n%m;
double Pi;
double V=0;
double P;
vector<bool>::const_iterator it=bits.begin();
for (int i=0; i<N; i++){
Pi=0;
for (int j=0; j<m; j++){
if (*it) Pi++;
it++;
}
Pi/=m;
V+=(Pi-0.5)*(Pi-0.5);
}
V*=4.0*m;
P=igamc(N/2.0, V/2.0);
cout<<"Frequency test within a block:"<<endl;
cout<<" n = "<<n<<endl;
cout<<" m = "<<m<<endl;
cout<<" N = "<<N<<endl;
cout<<" V = "<<fixed<<setprecision(6)<<V<<endl;
cout<<" P = "<<fixed<<setprecision(4)<<P*100<<"%"<<endl;
cout<<" "<<n_disc<<" bits are discarded."<<endl;
return P;
}
class FrequencyTestWithinABlock: public TestMethod{
public:
int m;
void run(std::vector<bool> &bits){
P = frequency_test_within_a_block(bits, m);
}
const char* testName(int lang = 0){
char* names[1] = {"Frequency test within a block"};
return names[lang];
}
FrequencyTestWithinABlock(int _m) {m = _m;}
~FrequencyTestWithinABlock() {}
};
}