isl_test: generalize subset test
authorSven Verdoolaege <skimo@kotnet.org>
Sun, 15 Jul 2012 07:06:38 +0000 (09:06 +0200)
committerSven Verdoolaege <skimo@kotnet.org>
Mon, 3 Sep 2012 13:40:09 +0000 (15:40 +0200)
This will make it easier to add additional test cases.

Signed-off-by: Sven Verdoolaege <skimo@kotnet.org>
isl_test.c

index 0bb70be..931459c 100644 (file)
@@ -2010,20 +2010,37 @@ void test_lift(isl_ctx *ctx)
        isl_basic_set_free(bset);
 }
 
-void test_subset(isl_ctx *ctx)
+struct {
+       const char *set1;
+       const char *set2;
+       int subset;
+} subset_tests[] = {
+       { "{ [112, 0] }",
+         "{ [i0, i1] : exists (e0 = [(i0 - i1)/16], e1: "
+               "16e0 <= i0 - i1 and 16e0 >= -15 + i0 - i1 and "
+               "16e1 <= i1 and 16e0 >= -i1 and 16e1 >= -i0 + i1) }", 1 },
+};
+
+static int test_subset(isl_ctx *ctx)
 {
-       const char *str;
+       int i;
        isl_set *set1, *set2;
+       int subset;
+
+       for (i = 0; i < ARRAY_SIZE(subset_tests); ++i) {
+               set1 = isl_set_read_from_str(ctx, subset_tests[i].set1);
+               set2 = isl_set_read_from_str(ctx, subset_tests[i].set2);
+               subset = isl_set_is_subset(set1, set2);
+               isl_set_free(set1);
+               isl_set_free(set2);
+               if (subset < 0)
+                       return -1;
+               if (subset != subset_tests[i].subset)
+                       isl_die(ctx, isl_error_unknown,
+                               "incorrect subset result", return -1);
+       }
 
-       str = "{ [112, 0] }";
-       set1 = isl_set_read_from_str(ctx, str);
-       str = "{ [i0, i1] : exists (e0 = [(i0 - i1)/16], e1: "
-               "16e0 <= i0 - i1 and 16e0 >= -15 + i0 - i1 and "
-               "16e1 <= i1 and 16e0 >= -i1 and 16e1 >= -i0 + i1) }";
-       set2 = isl_set_read_from_str(ctx, str);
-       assert(isl_set_is_subset(set1, set2));
-       isl_set_free(set1);
-       isl_set_free(set2);
+       return 0;
 }
 
 int test_factorize(isl_ctx *ctx)
@@ -3137,6 +3154,7 @@ struct {
        { "affine hull", &test_affine_hull },
        { "coalesce", &test_coalesce },
        { "factorize", &test_factorize },
+       { "subset", &test_subset },
 };
 
 int main()
@@ -3153,7 +3171,6 @@ int main()
                if (tests[i].fn(ctx) < 0)
                        goto error;
        }
-       test_subset(ctx);
        test_lift(ctx);
        test_bound(ctx);
        test_union(ctx);