Skip to content

Commit

Permalink
Adding permutation, chi square and LRS tests to restart IID
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewmccaffreynist committed Jun 9, 2023
1 parent 57ae8e4 commit f280420
Showing 1 changed file with 88 additions and 5 deletions.
93 changes: 88 additions & 5 deletions cpp/restart_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,13 @@ int main(int argc, char* argv[]) {
testRunNonIid.testCases.push_back(tc631nonIid);
testRunIid.testCases.push_back(tc631Iid);

IidTestCase tcOverallIid;
tcOverallIid.h_r = H_r;
tcOverallIid.h_c = H_c;
tcOverallIid.h_i = H_I;
tcOverallIid.testCaseNumber = "Overall";


if (!iid) {

if (data.alph_size == 2) {
Expand Down Expand Up @@ -682,6 +689,86 @@ int main(int argc, char* argv[]) {
}
testRunNonIid.testCases.push_back(tc6310);

} else { /* IID tests */

// Compute chi square stats
bool chi_square_test_pass_row = chi_square_tests(rdata, sample_size, alphabet_size, verbose);
bool chi_square_test_pass_col = chi_square_tests(cdata, sample_size, alphabet_size, verbose);
bool chi_square_test_pass = chi_square_test_pass_row && chi_square_test_pass_col;

tcOverallIid.passed_chi_square_tests = chi_square_test_pass;

if ((verbose == 1) || (verbose == 2)) {
if (chi_square_test_pass) {
printf("** Passed chi square tests\n\n");
}
else {
printf("** Failed chi square tests\n\n");
}
}
else if (verbose > 2) {
if (chi_square_test_pass) {
printf("Chi square tests: Passed\n");
}
else {
printf("Chi square tests: Failed\n");
}
}

// Compute length of the longest repeated substring stats
bool len_LRS_test_pass_row = len_LRS_test(rdata, sample_size, alphabet_size, verbose, "Literal");
bool len_LRS_test_pass_col = len_LRS_test(cdata, sample_size, alphabet_size, verbose, "Literal");
bool len_LRS_test_pass = len_LRS_test_pass_row && len_LRS_test_pass_col;

tcOverallIid.passed_longest_repeated_substring_test = len_LRS_test_pass;

if ((verbose == 1) || (verbose == 2)) {
if (len_LRS_test_pass) {
printf("** Passed length of longest repeated substring test\n\n");
}
else {
printf("** Failed length of longest repeated substring test\n\n");
}
}
else if (verbose > 2) {
if (len_LRS_test_pass) {
printf("Length of longest repeated substring test: Passed\n");
}
else {
printf("Length of longest repeated substring test: Failed\n");
}
}

// Compute permutation stats
bool perm_test_pass_row = permutation_tests(&data, rawmean, median, verbose, tcOverallIid);

data_t data_col;
memcpy(&data_col, &data, sizeof(data));
data_col.symbols = rdata;

bool perm_test_pass_col = permutation_tests(&data_col, rawmean, median, verbose, tcOverallIid);
bool perm_test_pass = perm_test_pass_row && perm_test_pass_col;

tcOverallIid.passed_iid_permutation_tests = perm_test_pass;

if ((verbose == 1) || (verbose == 2)) {
if (perm_test_pass) {
printf("** Passed IID permutation tests\n\n");
}
else {
printf("** Failed IID permutation tests\n\n");
}
}
else if (verbose > 2) {
if (perm_test_pass) {
printf("IID permutation tests: Passed\n");
}
else {
printf("IID permutation tests: Failed\n");
}
}


}

if (verbose > 0) {
Expand Down Expand Up @@ -714,11 +801,7 @@ int main(int argc, char* argv[]) {
exit(-1);
}

IidTestCase tcOverallIid;
tcOverallIid.h_r = H_r;
tcOverallIid.h_c = H_c;
tcOverallIid.h_i = H_I;
tcOverallIid.testCaseNumber = "Overall";

testRunIid.testCases.push_back(tcOverallIid);
testRunIid.errorLevel = 0;

Expand Down

0 comments on commit f280420

Please sign in to comment.