aboutsummaryrefslogtreecommitdiff
path: root/src/test.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/test.c')
-rw-r--r--src/test.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/test.c b/src/test.c
index dcfc03c..85d266b 100644
--- a/src/test.c
+++ b/src/test.c
@@ -1838,6 +1838,52 @@ int test_find_peaks_sorted(char *err)
return 0;
}
+int test_combinations_with_replacement(char *err)
+{
+ /* Tests the combinations_with_replacement() function. */
+ size_t i, j;
+ size_t result[100];
+ size_t len;
+
+ size_t expected1[3][2] = {{0,0},{0,1},{1,1}};
+
+ combinations_with_replacement(2,2,result,&len);
+
+ if (len != 3) {
+ sprintf(err, "combinations_with_replacement() returned %zu combinations but expected %i", len, 3);
+ return 1;
+ }
+
+ for (i = 0; i < len; i++) {
+ for (j = 0; j < 2; j++) {
+ if (result[i*2 + j] != expected1[i][j]) {
+ sprintf(err, "result[%zu][%zu] = %zu but expected %zu", i, j, result[i*2+j], expected1[i][j]);
+ return 1;
+ }
+ }
+ }
+
+ size_t expected2[6][2] = {{0,0},{0,1},{0,2},{1,1},{1,2},{2,2}};
+
+ combinations_with_replacement(3,2,result,&len);
+
+ if (len != 6) {
+ sprintf(err, "combinations_with_replacement() returned %zu combinations but expected %i", len, 6);
+ return 1;
+ }
+
+ for (i = 0; i < len; i++) {
+ for (j = 0; j < 2; j++) {
+ if (result[i*2 + j] != expected2[i][j]) {
+ sprintf(err, "result[%zu][%zu] = %zu but expected %zu", i, j, result[i*2+j], expected1[i][j]);
+ return 1;
+ }
+ }
+ }
+
+ return 0;
+}
+
struct tests {
testFunction *test;
char *name;
@@ -1884,6 +1930,7 @@ struct tests {
{test_unique_vertices, "test_unique_vertices"},
{test_find_peaks_highest, "test_find_peaks_highest"},
{test_find_peaks_sorted, "test_find_peaks_sorted"},
+ {test_combinations_with_replacement, "test_combinations_with_replacement"},
};
int main(int argc, char **argv)