/
monobit_frequency_test.cpp
39 lines (34 loc) · 1.04 KB
/
monobit_frequency_test.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
namespace test{
double monobit_frequency_test(const std::vector<bool> &bits){
if(bits.size()==0){
cerr<<"Illegal parameter!"<<endl;
throw;
}
int n = bits.size();
int S = 0;
double V;
double P;
for (int i=0; i<n; i++)
if(bits[i]) S++; else S--;
V = fabs(S)/sqrt(n);
P = erfc(V/sqrt(2));
cout<<"Monobit frequency test:"<<endl;
cout<<" n = "<<n<<endl;
cout<<" S = "<<S<<endl;
cout<<" V = "<<fixed<<setprecision(6)<<V<<endl;
cout<<" P = "<<fixed<<setprecision(4)<<P*100<<"%"<<endl;
return P;
}
class MonobitFrequencyTest: public TestMethod{
public:
void run(std::vector<bool> &bits){
P = monobit_frequency_test(bits);
}
const char* testName(int lang = 0){
char* names[1] = {"Monobit frequency test"};
return names[lang];
}
MonobitFrequencyTest() {}
~MonobitFrequencyTest() {}
};
}