change calling conventions of isl_basic_set_has_defining_{,in}equalit{y,ies}
[platform/upstream/isl.git] / isl_test.c
index 33c891f..ca4b328 100644 (file)
@@ -3,9 +3,67 @@
 #include <limits.h>
 #include <isl_ctx.h>
 #include <isl_set.h>
+#include <isl_constraint.h>
 
 static char *srcdir;
 
+void test_read(struct isl_ctx *ctx)
+{
+       char filename[PATH_MAX];
+       FILE *input;
+       int n;
+       struct isl_basic_set *bset1, *bset2;
+       const char *str = "{[y]: Exists ( alpha : 2alpha = y)}";
+
+       n = snprintf(filename, sizeof(filename),
+                       "%s/test_inputs/set.omega", srcdir);
+       assert(n < sizeof(filename));
+       input = fopen(filename, "r");
+       assert(input);
+
+       bset1 = isl_basic_set_read_from_file(ctx, input, 0, ISL_FORMAT_OMEGA);
+       bset2 = isl_basic_set_read_from_str(ctx, str, 0, ISL_FORMAT_OMEGA);
+
+       assert(isl_basic_set_is_equal(bset1, bset2) == 1);
+
+       isl_basic_set_free(bset1);
+       isl_basic_set_free(bset2);
+
+       fclose(input);
+}
+
+/* Construct the basic set { [i] : 5 <= i <= N } */
+void test_construction(struct isl_ctx *ctx)
+{
+       isl_int v;
+       struct isl_dim *dim;
+       struct isl_basic_set *bset;
+       struct isl_constraint *c;
+
+       isl_int_init(v);
+
+       dim = isl_dim_set_alloc(ctx, 1, 1);
+       bset = isl_basic_set_universe(dim);
+
+       c = isl_inequality_alloc(isl_dim_copy(bset->dim));
+       isl_int_set_si(v, -1);
+       isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
+       isl_int_set_si(v, 1);
+       isl_constraint_set_coefficient(c, isl_dim_param, 0, v);
+       bset = isl_basic_set_add_constraint(bset, c);
+
+       c = isl_inequality_alloc(isl_dim_copy(bset->dim));
+       isl_int_set_si(v, 1);
+       isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
+       isl_int_set_si(v, -5);
+       isl_constraint_set_constant(c, v);
+       bset = isl_basic_set_add_constraint(bset, c);
+
+       isl_basic_set_free(bset);
+
+       isl_int_clear(v);
+}
+
 void test_application_case(struct isl_ctx *ctx, const char *name)
 {
        char filename[PATH_MAX];
@@ -119,6 +177,40 @@ void test_convex_hull(struct isl_ctx *ctx)
        test_convex_hull_case(ctx, "convex11");
 }
 
+void test_gist_case(struct isl_ctx *ctx, const char *name)
+{
+       char filename[PATH_MAX];
+       FILE *input;
+       int n;
+       struct isl_basic_set *bset1, *bset2;
+       struct isl_set *set;
+
+       n = snprintf(filename, sizeof(filename),
+                       "%s/test_inputs/%s.polylib", srcdir, name);
+       assert(n < sizeof(filename));
+       input = fopen(filename, "r");
+       assert(input);
+
+       bset1 = isl_basic_set_read_from_file(ctx, input, 0, ISL_FORMAT_POLYLIB);
+       bset2 = isl_basic_set_read_from_file(ctx, input, 0, ISL_FORMAT_POLYLIB);
+
+       bset1 = isl_basic_set_gist(bset1, bset2);
+
+       bset2 = isl_basic_set_read_from_file(ctx, input, 0, ISL_FORMAT_POLYLIB);
+
+       assert(isl_basic_set_is_equal(bset1, bset2) == 1);
+
+       isl_basic_set_free(bset1);
+       isl_basic_set_free(bset2);
+
+       fclose(input);
+}
+
+void test_gist(struct isl_ctx *ctx)
+{
+       test_gist_case(ctx, "gist1");
+}
+
 int main()
 {
        struct isl_ctx *ctx;
@@ -126,9 +218,12 @@ int main()
        srcdir = getenv("srcdir");
 
        ctx = isl_ctx_alloc();
+       test_read(ctx);
+       test_construction(ctx);
        test_application(ctx);
        test_affine_hull(ctx);
        test_convex_hull(ctx);
+       test_gist(ctx);
        isl_ctx_free(ctx);
        return 0;
 }