From f280420bae7307779e8ed34d013a0f328a794468 Mon Sep 17 00:00:00 2001 From: Andrew McCaffrey Date: Fri, 9 Jun 2023 19:20:59 -0400 Subject: [PATCH] Adding permutation, chi square and LRS tests to restart IID --- cpp/restart_main.cpp | 93 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 88 insertions(+), 5 deletions(-) diff --git a/cpp/restart_main.cpp b/cpp/restart_main.cpp index e062a0c..63f3dfc 100644 --- a/cpp/restart_main.cpp +++ b/cpp/restart_main.cpp @@ -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) { @@ -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) { @@ -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;