interface/python.cc: document order of superclasses
[isl.git] / isl_test_imath.c
blobfdb07774884cfd4ee087619dc124545415627be3
1 /*
2 * Copyright 2015 INRIA Paris-Rocquencourt
4 * Use of this software is governed by the MIT license
6 * Written by Michael Kruse, INRIA Paris-Rocquencourt,
7 * Domaine de Voluceau, Rocquenqourt, B.P. 105,
8 * 78153 Le Chesnay Cedex France
9 */
11 #include <limits.h>
12 #include <assert.h>
13 #include <isl_imath.h>
15 /* This constant is not defined in limits.h, but IMath uses it */
16 #define ULONG_MIN 0ul
18 /* Test the IMath internals assumed by the imath implementation of isl_int.
20 * In particular, we test the ranges of IMath-defined types.
22 * Also, isl uses the existence and function of imath's struct
23 * fields. The digits are stored with less significant digits at lower array
24 * indices. Where they are stored (on the heap or in the field 'single') does
25 * not matter.
27 int test_imath_internals()
29 mpz_t val;
30 mp_result retval;
32 assert(sizeof(mp_small) == sizeof(long));
33 assert(MP_SMALL_MIN == LONG_MIN);
34 assert(MP_SMALL_MAX == LONG_MAX);
36 assert(sizeof(mp_usmall) == sizeof(unsigned long));
37 assert(MP_USMALL_MIN == ULONG_MIN);
38 assert(MP_USMALL_MAX == ULONG_MAX);
40 retval = mp_int_init_value(&val, 0);
41 assert(retval == MP_OK);
42 assert(val.alloc >= val.used);
43 assert(val.used == 1);
44 assert(val.sign == MP_ZPOS);
45 assert(val.digits[0] == 0);
47 retval = mp_int_set_value(&val, -1);
48 assert(retval == MP_OK);
49 assert(val.alloc >= val.used);
50 assert(val.used == 1);
51 assert(val.sign == MP_NEG);
52 assert(val.digits[0] == 1);
54 retval = mp_int_set_value(&val, 1);
55 assert(retval == MP_OK);
56 assert(val.alloc >= val.used);
57 assert(val.used == 1);
58 assert(val.sign == MP_ZPOS);
59 assert(val.digits[0] == 1);
61 retval = mp_int_mul_pow2(&val, sizeof(mp_digit) * CHAR_BIT, &val);
62 assert(retval == MP_OK);
63 assert(val.alloc >= val.used);
64 assert(val.used == 2);
65 assert(val.sign == MP_ZPOS);
66 assert(val.digits[0] == 0);
67 assert(val.digits[1] == 1);
69 mp_int_clear(&val);
70 return 0;
73 int main()
75 if (test_imath_internals() < 0)
76 return -1;
78 return 0;