add trivial affine hull test
[platform/upstream/isl.git] / isl_test.c
1 #include <assert.h>
2 #include <stdio.h>
3 #include <limits.h>
4 #include <isl_ctx.h>
5 #include <isl_set.h>
6
7 static char *srcdir;
8
9 void test_affine_hull(struct isl_ctx *ctx)
10 {
11         char filename[PATH_MAX];
12         FILE *input;
13         int n;
14         struct isl_basic_set *bset1, *bset2;
15
16         n = snprintf(filename, sizeof(filename),
17                         "%s/test_inputs/affine.polylib", srcdir);
18         assert(n < sizeof(filename));
19         input = fopen(filename, "r");
20         assert(input);
21
22         bset1 = isl_basic_set_read_from_file(ctx, input, ISL_FORMAT_POLYLIB);
23         bset2 = isl_basic_set_read_from_file(ctx, input, ISL_FORMAT_POLYLIB);
24
25         bset1 = isl_basic_set_affine_hull(ctx, bset1);
26
27         assert(isl_basic_set_is_equal(ctx, bset1, bset2) == 1);
28
29         isl_basic_set_free(ctx, bset1);
30         isl_basic_set_free(ctx, bset2);
31
32         fclose(input);
33 }
34
35 void test_convex_hull_case(struct isl_ctx *ctx, const char *name)
36 {
37         char filename[PATH_MAX];
38         FILE *input;
39         int n;
40         struct isl_basic_set *bset1, *bset2;
41         struct isl_set *set;
42
43         n = snprintf(filename, sizeof(filename),
44                         "%s/test_inputs/%s.polylib", srcdir, name);
45         assert(n < sizeof(filename));
46         input = fopen(filename, "r");
47         assert(input);
48
49         bset1 = isl_basic_set_read_from_file(ctx, input, ISL_FORMAT_POLYLIB);
50         bset2 = isl_basic_set_read_from_file(ctx, input, ISL_FORMAT_POLYLIB);
51
52         set = isl_basic_set_union(ctx, bset1, bset2);
53         bset1 = isl_set_convex_hull(ctx, set);
54
55         bset2 = isl_basic_set_read_from_file(ctx, input, ISL_FORMAT_POLYLIB);
56
57         assert(isl_basic_set_is_equal(ctx, bset1, bset2) == 1);
58
59         isl_basic_set_free(ctx, bset1);
60         isl_basic_set_free(ctx, bset2);
61
62         fclose(input);
63 }
64
65 void test_convex_hull(struct isl_ctx *ctx)
66 {
67         test_convex_hull_case(ctx, "convex0");
68         test_convex_hull_case(ctx, "convex1");
69         test_convex_hull_case(ctx, "convex2");
70         test_convex_hull_case(ctx, "convex3");
71         test_convex_hull_case(ctx, "convex4");
72         test_convex_hull_case(ctx, "convex5");
73         test_convex_hull_case(ctx, "convex6");
74         test_convex_hull_case(ctx, "convex7");
75 }
76
77 int main()
78 {
79         struct isl_ctx *ctx;
80
81         srcdir = getenv("srcdir");
82
83         ctx = isl_ctx_alloc();
84         test_affine_hull(ctx);
85         test_convex_hull(ctx);
86         isl_ctx_free(ctx);
87         return 0;
88 }