-
Notifications
You must be signed in to change notification settings - Fork 7
/
cumulative_test.cpp
47 lines (39 loc) · 1.2 KB
/
cumulative_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
40
41
42
43
44
45
46
47
namespace test{
double cumulative_test(const std::vector<bool> &bits){
if(bits.size()==0){
cerr<<"Illegal parameter!"<<endl;
throw;
}
int n = bits.size();
int S = 0;
int Z = 0;
double P = 1.0;
for (int i=0; i<n; i++){
if(bits[i]) S++; else S--;
Z = max(Z, abs(S));
}
for (int i=((-n/Z)+1)/4; i<=((n/Z)-1)/4; i++){
P-=normal_CDF((4*i+1)*Z/sqrt(n))-normal_CDF((4*i-1)*Z/sqrt(n));
}
for (int i=((-n/Z)-3)/4; i<=((n/Z)-1)/4; i++){
P+=normal_CDF((4*i+3)*Z/sqrt(n))-normal_CDF((4*i+1)*Z/sqrt(n));
}
cout<<"Cumulative test:"<<endl;
cout<<" n = "<<n<<endl;
cout<<" Z = "<<Z<<endl;
cout<<" P = "<<fixed<<setprecision(4)<<P*100<<"%"<<endl;
return P;
}
class CumulativeTest: public TestMethod{
public:
void run(std::vector<bool> &bits){
P = cumulative_test(bits);
}
const char* testName(int lang = 0){
char* names[1] = {"Cumulative test"};
return names[lang];
}
CumulativeTest() {}
~CumulativeTest() {}
};
}