summaryrefslogtreecommitdiff
path: root/src/raptor_permute_test.c
diff options
context:
space:
mode:
authorDave Beckett <dave@dajobe.org>2011-11-27 09:51:14 -0800
committerDave Beckett <dave@dajobe.org>2011-11-27 09:51:14 -0800
commite5fd88059a8b1be04eec75da2a3e47267f3fd693 (patch)
treee7fa61d83a7dff503b7480c900df2cf995b88385 /src/raptor_permute_test.c
parent03eb4c57f92194e8bd4d55acc34404d0441d82fa (diff)
downloadraptor-e5fd88059a8b1be04eec75da2a3e47267f3fd693.tar.gz
Add a proper value checking test for permute size 5
Diffstat (limited to 'src/raptor_permute_test.c')
-rw-r--r--src/raptor_permute_test.c152
1 files changed, 150 insertions, 2 deletions
diff --git a/src/raptor_permute_test.c b/src/raptor_permute_test.c
index a88e834c..19b3539b 100644
--- a/src/raptor_permute_test.c
+++ b/src/raptor_permute_test.c
@@ -88,13 +88,11 @@ free_intseq(intseq* iseq)
RAPTOR_FREE(intseq*, iseq);
}
-#if PERMUTE_DEBUG > 0
static void
intseq_print(intseq *iseq, FILE* stream)
{
raptor_sequence_print(iseq->seq, stream);
}
-#endif
static int
intseq_reverse(intseq *iseq, int start_index, int length)
@@ -119,6 +117,129 @@ intseq_next_permutation(intseq *iseq)
#define MAX_SIZE 5
+int expected_results_size5[120][5] = {
+ {1, 2, 3, 4, 5},
+ {1, 2, 3, 5, 4},
+ {1, 2, 4, 3, 5},
+ {1, 2, 4, 5, 3},
+ {1, 2, 5, 3, 4},
+ {1, 2, 5, 4, 3},
+ {1, 3, 2, 4, 5},
+ {1, 3, 2, 5, 4},
+ {1, 3, 4, 2, 5},
+ {1, 3, 4, 5, 2},
+ {1, 3, 5, 2, 4},
+ {1, 3, 5, 4, 2},
+ {1, 4, 2, 3, 5},
+ {1, 4, 2, 5, 3},
+ {1, 4, 3, 2, 5},
+ {1, 4, 3, 5, 2},
+ {1, 4, 5, 2, 3},
+ {1, 4, 5, 3, 2},
+ {1, 5, 2, 3, 4},
+ {1, 5, 2, 4, 3},
+ {1, 5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 1, 5, 3, 2},
+ {4, 2, 1, 3, 5},
+ {4, 2, 1, 5, 3},
+ {4, 2, 3, 1, 5},
+ {4, 2, 3, 5, 1},
+ {4, 2, 5, 1, 3},
+ {4, 2, 5, 3, 1},
+ {4, 3, 1, 2, 5},
+ {4, 3, 1, 5, 2},
+ {4, 3, 2, 1, 5},
+ {4, 3, 2, 5, 1},
+ {4, 3, 5, 1, 2},
+ {4, 3, 5, 2, 1},
+ {4, 5, 1, 2, 3},
+ {4, 5, 1, 3, 2},
+ {4, 5, 2, 1, 3},
+ {4, 5, 2, 3, 1},
+ {4, 5, 3, 1, 2},
+ {4, 5, 3, 2, 1},
+ {5, 1, 2, 3, 4},
+ {5, 1, 2, 4, 3},
+ {5, 1, 3, 2, 4},
+ {5, 1, 3, 4, 2},
+ {5, 1, 4, 2, 3},
+ {5, 1, 4, 3, 2},
+ {5, 2, 1, 3, 4},
+ {5, 2, 1, 4, 3},
+ {5, 2, 3, 1, 4},
+ {5, 2, 3, 4, 1},
+ {5, 2, 4, 1, 3},
+ {5, 2, 4, 3, 1},
+ {5, 3, 1, 2, 4},
+ {5, 3, 1, 4, 2},
+ {5, 3, 2, 1, 4},
+ {5, 3, 2, 4, 1},
+ {5, 3, 4, 1, 2},
+ {5, 3, 4, 2, 1},
+ {5, 4, 1, 2, 3},
+ {5, 4, 1, 3, 2},
+ {5, 4, 2, 1, 3},
+ {5, 4, 2, 3, 1},
+ {5, 4, 3, 1, 2},
+ {5, 4, 3, 2, 1}
+};
+
int main (int argc, char *argv[])
{
const char *program = raptor_basename(argv[0]);
@@ -149,6 +270,33 @@ int main (int argc, char *argv[])
intseq_print(iseq, stderr);
fputc('\n', stderr);
#endif
+ if(size == 5) {
+ int* expected_result = expected_results_size5[count - 1];
+ int j;
+ int ok = 1;
+
+ for(j = 0; j < size; j++) {
+ int actual = *(int*)(raptor_sequence_get_at(iseq->seq, j));
+ int expected = expected_result[j];
+ if(actual != expected) {
+ ok = 0;
+ break;
+ }
+ }
+ if(!ok) {
+ fprintf(stderr, "%s: FAILED test %d result %d - returned ",
+ program, size, count);
+ intseq_print(iseq, stderr);
+ fputs(" expected [", stderr);
+ for(j = 0; j < size; j++) {
+ fprintf(stderr, "%d, ", expected_result[j]);
+ }
+ fputs("]\n", stderr);
+
+ failures++;
+ }
+ }
+
if(intseq_next_permutation(iseq))
break;
}