int main(void) { int n; for (n = 0; n <= PERM_NMAX; n++) { test_perm(n); } for (n = 0; n <= COMB_NMAX; n++) { test_setcomb(n); test_listcomb(n); } printf("Failed %d / %d tests\n", nfails, ntests); return 0; }
void test4(int n) { cout << endl << endl; cout << "Combinations and permutations" << endl; cout << endl; cout << "Just checking that we get a valid permutation or combination" << endl; { cout << "Doing permutations" << endl; RandomPermutation RP; int i, j, k; int p[10]; cout << "... select 10 items from 100...119 without replacement" << endl; for (i = 1; i <= 10; i++) { RP.Next(20,10,p,100); for (j = 0; j < 10; j++) { int pj = p[j]; if (pj < 100 || pj > 119) Throw(BaseException("Invalid permutation generated")); for (k = 0; k < j; ++k) if (p[k] == pj) Throw(BaseException("Invalid permutation generated")); } } cout << "... select 10 items from 100...109 without replacement" << endl; for (i = 1; i <= 10; i++) { RP.Next(10,10,p,100); for (j = 0; j < 10; j++) { int pj = p[j]; //cout << pj << " "; if (pj < 100 || pj > 109) Throw(BaseException("Invalid permutation generated")); for (k = 0; k < j; ++k) if (p[k] == pj) Throw(BaseException("Invalid permutation generated")); } } } { cout << "Doing combinations" << endl; RandomCombination RC; int i, j; int p[10]; cout << "... select 10 items from 100...119 without replacement" << endl; for (i = 1; i <= 10; i++) { RC.Next(20,10,p,100); for (j = 0; j < 10; j++) { int pj = p[j]; if (pj < 100 || pj > 119) Throw(BaseException("Invalid permutation generated")); if (j > 0 && pj <= p[j-1]) Throw(BaseException("Invalid permutation generated")); } } cout << "... select 10 items from 100...109 without replacement" << endl; for (i = 1; i <= 10; i++) { RC.Next(10,10,p,100); for (j = 0; j < 10; j++) { int pj = p[j]; //cout << pj << " "; if (pj < 100 || pj > 109) Throw(BaseException("Invalid permutation generated")); if (j > 0 && pj <= p[j-1]) Throw(BaseException("Invalid permutation generated")); } //cout << "\n"; } //cout << "\n"; } cout << endl; cout << "Doing formal tests of permutation generator" << endl; cout << endl; cout << "Carries out a number of tests which generate approximately" << endl; cout << "normally distributed test statistics;" << endl; cout << "param. 1 and param. 2 show the mean and s.d. of the test statistic;" << endl; cout << "statistic shows the test statistic value;" << endl; cout << "n. stat shows the normalised value;" << endl; cout << "-lg sig shows -log10 of the significance probability." << endl; cout << "Should be less than 1.3 (5% sig) in most cases and" << endl; cout << "2 (1% sig) in almost all cases." << endl; cout << endl; cout << "* shows 5% significance; ** shows 1% significance;" << endl; cout << "*** shows 0.1% significance." << endl; test_perm(1, 10, n * 10); test_perm(4, 10, n * 10); test_perm(7, 10, n * 10); test_perm(10, 10, n * 10); test_perm(1, 100, n); test_perm(30, 100, n); test_perm(65, 100, n); test_perm(100, 100, n); test_perm(100, 1000, n / 10); }
int main() { int a[] = { 0, 3, 5, 4, 3, 1 }; printf("%d\n", test_perm(a, 5)); return 0; }