fix isl_union_{set,map}_lex_g{e,t}_union_map
[platform/upstream/isl.git] / isl_test.c
index 5b7a9ea..c4d8b51 100644 (file)
 #include <isl_set.h>
 #include <isl_flow.h>
 #include <isl_constraint.h>
+#include <isl_polynomial.h>
+#include <isl_union_map.h>
 
 static char *srcdir;
 
+void test_parse_map(isl_ctx *ctx, const char *str)
+{
+       isl_map *map;
+
+       map = isl_map_read_from_str(ctx, str, -1);
+       assert(map);
+       isl_map_free(map);
+}
+
+void test_parse(struct isl_ctx *ctx)
+{
+       isl_map *map;
+       const char *str;
+
+       str = "{ [i] -> [-i] }";
+       map = isl_map_read_from_str(ctx, str, -1);
+       assert(map);
+       isl_map_free(map);
+
+       str = "{ A[i] -> L[([i/3])] }";
+       map = isl_map_read_from_str(ctx, str, -1);
+       assert(map);
+       isl_map_free(map);
+
+       test_parse_map(ctx, "{[[s] -> A[i]] -> [[s+1] -> A[i]]}");
+}
+
 void test_read(struct isl_ctx *ctx)
 {
        char filename[PATH_MAX];
@@ -97,11 +126,12 @@ void test_construction(struct isl_ctx *ctx)
 
 void test_dim(struct isl_ctx *ctx)
 {
+       const char *str;
        isl_map *map1, *map2;
 
        map1 = isl_map_read_from_str(ctx,
            "[n] -> { [i] -> [j] : exists (a = [i/10] : i - 10a <= n ) }", -1);
-       map1 = isl_map_add(map1, isl_dim_in, 1);
+       map1 = isl_map_add_dims(map1, isl_dim_in, 1);
        map2 = isl_map_read_from_str(ctx,
            "[n] -> { [i,k] -> [j] : exists (a = [i/10] : i - 10a <= n ) }", -1);
        assert(isl_map_is_equal(map1, map2));
@@ -113,6 +143,16 @@ void test_dim(struct isl_ctx *ctx)
 
        isl_map_free(map1);
        isl_map_free(map2);
+
+       str = "[n] -> { [i] -> [] : exists a : 0 <= i <= n and i = 2 a }";
+       map1 = isl_map_read_from_str(ctx, str, -1);
+       str = "{ [i] -> [j] : exists a : 0 <= i <= j and i = 2 a }";
+       map2 = isl_map_read_from_str(ctx, str, -1);
+       map1 = isl_map_move_dims(map1, isl_dim_out, 0, isl_dim_param, 0, 1);
+       assert(isl_map_is_equal(map1, map2));
+
+       isl_map_free(map1);
+       isl_map_free(map2);
 }
 
 void test_div(struct isl_ctx *ctx)
@@ -818,6 +858,10 @@ void test_coalesce(struct isl_ctx *ctx)
                        "x-z + 20 >= 0 and x+z + 20 >= 0 and -10 <= y <= 0}", 1);
        test_coalesce_set(ctx,
                "{[x,y] : 0 <= x,y <= 10; [5,y]: 4 <=y <= 11}", 1);
+       test_coalesce_set(ctx, "{[x,0] : x >= 0; [x,1] : x <= 20}", 0);
+       test_coalesce_set(ctx,
+               "{[x,0,0] : -5 <= x <= 5; [0,y,1] : -5 <= y <= 5 }", 1);
+       test_coalesce_set(ctx, "{ [x, 1 - x] : 0 <= x <= 1; [0,0] }", 1);
 }
 
 void test_closure(struct isl_ctx *ctx)
@@ -1034,6 +1078,17 @@ void test_closure(struct isl_ctx *ctx)
        isl_map_free(map2);
 }
 
+void test_lex(struct isl_ctx *ctx)
+{
+       isl_dim *dim;
+       isl_map *map;
+
+       dim = isl_dim_alloc(ctx, 0, 0, 0);
+       map = isl_map_lex_le(dim);
+       assert(!isl_map_is_empty(map));
+       isl_map_free(map);
+}
+
 void test_lexmin(struct isl_ctx *ctx)
 {
        const char *str;
@@ -1340,6 +1395,61 @@ void test_bijective(struct isl_ctx *ctx)
        test_bijective_case(ctx, "[N,M]->{[i,j] -> [x,y] : 2x=i & y =j}", 1);
 }
 
+void test_pwqp(struct isl_ctx *ctx)
+{
+       const char *str;
+       isl_pw_qpolynomial *pwqp1, *pwqp2;
+
+       str = "{ [i,j,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
+       pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
+
+       pwqp1 = isl_pw_qpolynomial_move_dims(pwqp1, isl_dim_param, 0,
+                                               isl_dim_set, 1, 1);
+
+       str = "[j] -> { [i,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
+       pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
+
+       pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2);
+
+       assert(isl_pw_qpolynomial_is_zero(pwqp1));
+
+       isl_pw_qpolynomial_free(pwqp1);
+}
+
+void test_split_periods(isl_ctx *ctx)
+{
+       const char *str;
+       isl_pw_qpolynomial *pwqp;
+
+       str = "{ [U,V] -> 1/3 * U + 2/3 * V - [(U + 2V)/3] + [U/2] : "
+               "U + 2V + 3 >= 0 and - U -2V  >= 0 and - U + 10 >= 0 and "
+               "U  >= 0; [U,V] -> U^2 : U >= 100 }";
+       pwqp = isl_pw_qpolynomial_read_from_str(ctx, str);
+
+       pwqp = isl_pw_qpolynomial_split_periods(pwqp, 2);
+       assert(pwqp);
+
+       isl_pw_qpolynomial_free(pwqp);
+}
+
+void test_union(isl_ctx *ctx)
+{
+       const char *str;
+       isl_union_set *uset;
+       isl_union_map *umap1, *umap2;
+
+       str = "{ [i] : 0 <= i <= 1 }";
+       uset = isl_union_set_from_set(isl_set_read_from_str(ctx, str, -1));
+       str = "{ [1] -> [0] }";
+       umap1 = isl_union_map_from_map(isl_map_read_from_str(ctx, str, -1));
+
+       umap2 = isl_union_set_lex_gt_union_set(isl_union_set_copy(uset), uset);
+       assert(isl_union_map_is_equal(umap1, umap2));
+
+       isl_union_map_free(umap1);
+       isl_union_map_free(umap2);
+}
+
 int main()
 {
        struct isl_ctx *ctx;
@@ -1348,6 +1458,11 @@ int main()
        assert(srcdir);
 
        ctx = isl_ctx_alloc();
+       test_union(ctx);
+       test_split_periods(ctx);
+       test_parse(ctx);
+       test_pwqp(ctx);
+       test_lex(ctx);
        test_sv(ctx);
        test_bijective(ctx);
        test_dep(ctx);