Ejemplo n.º 1
0
int main()
{
    slong iter;
    flint_rand_t state;

    flint_printf("mul_2exp_si....");
    fflush(stdout);

    flint_randinit(state);

    for (iter = 0; iter < 100000 * arb_test_multiplier(); iter++)
    {
        fmpr_t x, y, z;
        mag_t xb, yb;
        slong e;

        fmpr_init(x);
        fmpr_init(y);
        fmpr_init(z);

        mag_init(xb);
        mag_init(yb);

        mag_randtest_special(xb, state, 100);
        e = z_randtest(state);
        mag_get_fmpr(x, xb);

        mag_mul_2exp_si(yb, xb, e);

        fmpr_mul_2exp_si(y, x, e);

        mag_get_fmpr(z, yb);

        MAG_CHECK_BITS(yb)

        if (!fmpr_equal(z, y))
        {
            flint_printf("FAIL\n\n");
            flint_printf("x = "); fmpr_printd(x, 15); flint_printf("\n\n");
            flint_printf("y = "); fmpr_printd(y, 15); flint_printf("\n\n");
            flint_printf("z = "); fmpr_printd(z, 15); flint_printf("\n\n");
            abort();
        }

        fmpr_clear(x);
        fmpr_clear(y);
        fmpr_clear(z);

        mag_clear(xb);
        mag_clear(yb);
    }

    flint_randclear(state);
    flint_cleanup();
    flint_printf("PASS\n");
    return EXIT_SUCCESS;
}
Ejemplo n.º 2
0
int
main(void)
{
    int i, result;
    FLINT_TEST_INIT(state);

    flint_printf("scalar_submul_si_2exp....");
    fflush(stdout);

    

    /* Compare with alternative method of computation */
    for (i = 0; i < 1000 * flint_test_multiplier(); i++)
    {
        fmpz *a, *b, *c, *d;
        slong len = n_randint(state, 100), x;
        mp_bitcnt_t exp;

        a = _fmpz_vec_init(len);
        b = _fmpz_vec_init(len);
        c = _fmpz_vec_init(len);
        d = _fmpz_vec_init(len);

        _fmpz_vec_randtest(a, state, len, 200);
        _fmpz_vec_randtest(b, state, len, 200);
        _fmpz_vec_set(c, b, len);

        x = z_randtest(state);
        exp = n_randint(state, 200);

        _fmpz_vec_scalar_submul_si_2exp(b, a, len, x, exp);
        _fmpz_vec_scalar_mul_2exp(d, a, len, exp);
        _fmpz_vec_scalar_submul_si(c, d, len, x);

        result = (_fmpz_vec_equal(b, c, len));
        if (!result)
        {
            flint_printf("FAIL:\n");
            flint_printf("x = %wd, exp = %wu\n", x, exp);
            _fmpz_vec_print(b, len), flint_printf("\n\n");
            _fmpz_vec_print(c, len), flint_printf("\n\n");
            abort();
        }

        _fmpz_vec_clear(a, len);
        _fmpz_vec_clear(b, len);
        _fmpz_vec_clear(c, len);
        _fmpz_vec_clear(d, len);
    }

    FLINT_TEST_CLEANUP(state);
    
    flint_printf("PASS\n");
    return 0;
}
Ejemplo n.º 3
0
int
main(void)
{
    int i;
    FLINT_TEST_INIT(state);
    

    flint_printf("set_si....");
    fflush(stdout);

    for (i = 0; i < 10000; i++)
    {
        fmpq_t x, y;
        fmpz_t p, q;
        slong P, Q;

        fmpq_init(x);
        fmpq_init(y);
        fmpz_init(p);
        fmpz_init(q);

        P = z_randtest(state);
        Q = n_randtest_not_zero(state);

        fmpz_set_si(p, P);
        fmpz_set_ui(q, Q);

        fmpq_set_fmpz_frac(x, p, q);
        fmpq_set_si(y, P, Q);

        if (!fmpq_is_canonical(y) || !fmpq_equal(x, y))
        {
            flint_printf("FAIL");
            flint_printf("p: "); fmpz_print(p); flint_printf("\n"); 
            flint_printf("q: "); fmpz_print(q); flint_printf("\n"); 
            flint_printf("x: "); fmpq_print(x); flint_printf("\n"); 
            flint_printf("y: "); fmpq_print(y); flint_printf("\n"); 
            abort();
        }

        fmpq_clear(x);
        fmpq_clear(y);
        fmpz_clear(p);
        fmpz_clear(q);
    }

    

    FLINT_TEST_CLEANUP(state);
    flint_printf("PASS\n");
    return 0;
}
Ejemplo n.º 4
0
int
main(void)
{
    int i, j, result;
    FLINT_TEST_INIT(state);

    flint_printf("get/set_coeff_si....");
    fflush(stdout);

    

    for (i = 0; i < 100 * flint_test_multiplier(); i++)
    {
        fmpz_poly_t a;
        slong coeff, len;
        slong n1, n2;

        fmpz_poly_init(a);
        len = n_randint(state, 100) + 1;

        for (j = 0; j < 1000; j++)
        {
            n1 = z_randtest(state);
            coeff = n_randint(state, len);
            fmpz_poly_set_coeff_si(a, coeff, n1);
            n2 = fmpz_poly_get_coeff_si(a, coeff);

            result = (n1 == n2);
            if (!result)
            {
                flint_printf("FAIL: n1 = %wd, n2 = %wd, coeff = %wd, length = %wd\n",
                       n1, n2, coeff, len);
                abort();
            }
        }

        fmpz_poly_clear(a);
    }

    FLINT_TEST_CLEANUP(state);
    
    flint_printf("PASS\n");
    return 0;
}
Ejemplo n.º 5
0
int
main(void)
{
    int i, result;
    FLINT_TEST_INIT(state);

    flint_printf("sizeinbase....");
    fflush(stdout);

    

    for (i = 0; i < 100000; i++)
    {
        slong a;
        mpz_t b;
        int base;
        size_t r1, r2;

        a = z_randtest(state);
        flint_mpz_init_set_si(b, a);
        base = (int) (n_randint(state, 61) + 2);

        r1 = z_sizeinbase(a, base);
        r2 = mpz_sizeinbase(b, base);
        result = (r1 == r2 || r1 + 1 == r2);

        if (!result)
        {
            flint_printf("FAIL:\n");
            gmp_printf("b = %Zd\n", b);
            flint_printf("base = %d\n", base);
            flint_printf("r1 = %wu\n, r2 = %wu\n", (ulong) r1, (ulong) r2);
            abort();
        }

        mpz_clear(b);
    }

    FLINT_TEST_CLEANUP(state);
    
    flint_printf("PASS\n");
    return 0;
}
Ejemplo n.º 6
0
int main()
{
    slong iter, iter2;
    flint_rand_t state;

    flint_printf("addmul_si....");
    fflush(stdout);

    flint_randinit(state);

    for (iter = 0; iter < 1000 * arb_test_multiplier(); iter++)
    {
        arf_t x, z, v;
        slong y;
        slong prec, r1, r2;
        arf_rnd_t rnd;

        arf_init(x);
        arf_init(z);
        arf_init(v);

        for (iter2 = 0; iter2 < 100; iter2++)
        {
            arf_randtest_special(x, state, 2000, 100);
            y = z_randtest(state);
            arf_randtest_special(z, state, 2000, 100);
            arf_set(v, z);

            prec = 2 + n_randint(state, 2000);

            if (n_randint(state, 10) == 0 &&
                fmpz_bits(ARF_EXPREF(x)) < 10 &&
                fmpz_bits(ARF_EXPREF(z)) < 10)
            {
                prec = ARF_PREC_EXACT;
            }

            switch (n_randint(state, 5))
            {
                case 0:  rnd = ARF_RND_DOWN; break;
                case 1:  rnd = ARF_RND_UP; break;
                case 2:  rnd = ARF_RND_FLOOR; break;
                case 3:  rnd = ARF_RND_CEIL; break;
                default: rnd = ARF_RND_NEAR; break;
            }

            switch (n_randint(state, 2))
            {
            case 0:
                r1 = arf_addmul_si(z, x, y, prec, rnd);
                r2 = arf_addmul_si_naive(v, x, y, prec, rnd);
                if (!arf_equal(z, v) || r1 != r2)
                {
                    flint_printf("FAIL!\n");
                    flint_printf("prec = %wd, rnd = %d\n\n", prec, rnd);
                    flint_printf("x = "); arf_print(x); flint_printf("\n\n");
                    flint_printf("y = %wd", y); flint_printf("\n\n");
                    flint_printf("z = "); arf_debug(z); flint_printf("\n\n");
                    flint_printf("v = "); arf_debug(v); flint_printf("\n\n");
                    flint_printf("r1 = %wd, r2 = %wd\n", r1, r2);
                    abort();
                }
                break;

            default:
                r2 = arf_addmul_si_naive(v, v, y, prec, rnd);
                r1 = arf_addmul_si(z, z, y, prec, rnd);
                if (!arf_equal(v, z) || r1 != r2)
                {
                    flint_printf("FAIL (aliasing)!\n");
                    flint_printf("prec = %wd, rnd = %d\n\n", prec, rnd);
                    flint_printf("y = %wd", y); flint_printf("\n\n");
                    flint_printf("v = "); arf_print(v); flint_printf("\n\n");
                    flint_printf("z = "); arf_print(z); flint_printf("\n\n");
                    flint_printf("r1 = %wd, r2 = %wd\n", r1, r2);
                    abort();
                }
                break;
            }
        }

        arf_clear(x);
        arf_clear(z);
        arf_clear(v);
    }

    flint_randclear(state);
    flint_cleanup();
    flint_printf("PASS\n");
    return EXIT_SUCCESS;
}
Ejemplo n.º 7
0
int main()
{
    slong iter;
    flint_rand_t state;

    flint_printf("sub_si....");
    fflush(stdout);

    flint_randinit(state);

    for (iter = 0; iter < 10000; iter++)
    {
        arb_t a, b, c, d;
        slong x;
        slong prec;

        arb_init(a);
        arb_init(b);
        arb_init(c);
        arb_init(d);

        arb_randtest_special(a, state, 1 + n_randint(state, 2000), 100);
        arb_randtest_special(b, state, 1 + n_randint(state, 2000), 100);
        arb_randtest_special(c, state, 1 + n_randint(state, 2000), 100);
        x = z_randtest(state);

        prec = 2 + n_randint(state, 2000);

        arb_set_si(b, x);
        arb_sub_si(c, a, x, prec);
        arb_sub(d, a, b, prec);

        if (!arb_equal(c, d))
        {
            flint_printf("FAIL\n\n");
            flint_printf("a = "); arb_print(a); flint_printf("\n\n");
            flint_printf("b = "); arb_print(b); flint_printf("\n\n");
            flint_printf("c = "); arb_print(c); flint_printf("\n\n");
            flint_printf("d = "); arb_print(d); flint_printf("\n\n");
            abort();
        }

        arb_clear(a);
        arb_clear(b);
        arb_clear(c);
        arb_clear(d);
    }

    /* aliasing */
    for (iter = 0; iter < 10000; iter++)
    {
        arb_t a, b, c;
        slong x;
        slong prec;

        arb_init(a);
        arb_init(b);
        arb_init(c);

        arb_randtest_special(a, state, 1 + n_randint(state, 2000), 100);
        arb_randtest_special(b, state, 1 + n_randint(state, 2000), 100);
        arb_randtest_special(c, state, 1 + n_randint(state, 2000), 100);
        x = z_randtest(state);

        prec = 2 + n_randint(state, 2000);

        arb_set_si(b, x);
        arb_sub_si(c, a, x, prec);
        arb_sub_si(a, a, x, prec);

        if (!arb_equal(a, c))
        {
            flint_printf("FAIL (aliasing)\n\n");
            flint_printf("a = "); arb_print(a); flint_printf("\n\n");
            flint_printf("b = "); arb_print(b); flint_printf("\n\n");
            flint_printf("c = "); arb_print(c); flint_printf("\n\n");
            abort();
        }

        arb_clear(a);
        arb_clear(b);
        arb_clear(c);
    }

    flint_randclear(state);
    flint_cleanup();
    flint_printf("PASS\n");
    return EXIT_SUCCESS;
}
Ejemplo n.º 8
0
Archivo: t-root.c Proyecto: certik/arb
int main()
{
    long iter;
    flint_rand_t state;

    printf("root....");
    fflush(stdout);

    flint_randinit(state);

    /* check (a^(1/m))^m = a */
    for (iter = 0; iter < 10000; iter++)
    {
        fmpcb_t a, b, c;
        long prec;
        ulong m, index;

        fmpcb_init(a);
        fmpcb_init(b);
        fmpcb_init(c);

        m = z_randtest_not_zero(state);
        index = z_randtest(state);

        fmpcb_randtest(a, state, 1 + n_randint(state, 2000), 3);
        fmpcb_randtest(b, state, 1 + n_randint(state, 2000), 3);

        prec = 2 + n_randint(state, 2000);

        fmpcb_root(b, a, m, index, prec);
        fmpcb_pow_si(c, b, m, prec);

        if (!fmpcb_contains(c, a))
        {
            printf("FAIL: containment\n\n");
            printf("m = %ld\n\n", m);
            printf("index = %ld\n\n", index);
            printf("a = "); fmpcb_print(a); printf("\n\n");
            printf("b = "); fmpcb_print(b); printf("\n\n");
            printf("c = "); fmpcb_print(c); printf("\n\n");
            abort();
        }

        fmpcb_root(a, a, m, index, prec);
        if (!fmpcb_equal(a, b))
        {
            printf("FAIL: aliasing\n\n");
            printf("m = %ld\n\n", m);
            printf("index = %ld\n\n", index);
            printf("a = "); fmpcb_print(a); printf("\n\n");
            printf("b = "); fmpcb_print(b); printf("\n\n");
            abort();
        }

        fmpcb_clear(a);
        fmpcb_clear(b);
        fmpcb_clear(c);
    }

    flint_randclear(state);
    flint_cleanup();
    printf("PASS\n");
    return EXIT_SUCCESS;
}
Ejemplo n.º 9
0
int
main(void)
{
    int i, result;
    FLINT_TEST_INIT(state);

    flint_printf("derivative... ");
    fflush(stdout);

    

    /* Check aliasing */
    for (i = 0; i < 100; i++)
    {
        fmpz_poly_q_t a, b;

        fmpz_poly_q_init(a);
        fmpz_poly_q_init(b);
        fmpz_poly_q_randtest(a, state, n_randint(state, 50), 50, n_randint(state, 50), 50);

        fmpz_poly_q_derivative(b, a);
        fmpz_poly_q_derivative(a, a);

        result = fmpz_poly_q_equal(a, b);
        if (!result)
        {
            flint_printf("FAIL:\n");
            fmpz_poly_q_print(a), flint_printf("\n\n");
            fmpz_poly_q_print(b), flint_printf("\n\n");
            abort();
        }

        fmpz_poly_q_clear(a);
        fmpz_poly_q_clear(b);
    }

    /* Check constants have derivative zero */
    for (i = 0; i < 100; i++)
    {
        fmpz_poly_q_t a, b;

        fmpz_poly_q_init(a);
        fmpz_poly_q_init(b);

        fmpz_poly_q_set_si(a, z_randtest(state));

        fmpz_poly_q_derivative(b, a);

        result = fmpz_poly_q_is_zero(b);
        if (!result)
        {
            flint_printf("FAIL:\n");
            fmpz_poly_q_print(a), flint_printf("\n\n");
            fmpz_poly_q_print(b), flint_printf("\n\n");
            abort();
        }

        fmpz_poly_q_clear(a);
        fmpz_poly_q_clear(b);
    }

    /* Check (f g)' = f' g + f g' */
    for (i = 0; i < 100; i++)
    {
        fmpz_poly_q_t a, b, c, d, lhs, rhs;

        fmpz_poly_q_init(a);
        fmpz_poly_q_init(b);
        fmpz_poly_q_init(c);
        fmpz_poly_q_init(d);
        fmpz_poly_q_init(lhs);
        fmpz_poly_q_init(rhs);
        fmpz_poly_q_randtest(a, state, n_randint(state, 20), 20, n_randint(state, 20), 20);
        fmpz_poly_q_randtest(b, state, n_randint(state, 20), 20, n_randint(state, 20), 20);

        fmpz_poly_q_mul(lhs, a, b);
        fmpz_poly_q_derivative(lhs, lhs);
        fmpz_poly_q_derivative(c, a);
        fmpz_poly_q_derivative(d, b);
        fmpz_poly_q_mul(c, c, b);
        fmpz_poly_q_mul(d, a, d);
        fmpz_poly_q_add(rhs, c, d);

        result = fmpz_poly_q_equal(lhs, rhs) && fmpz_poly_q_is_canonical(lhs) 
                                             && fmpz_poly_q_is_canonical(rhs);
        if (!result)
        {
            flint_printf("FAIL:\n");
            fmpz_poly_q_print(a), flint_printf("\n\n");
            fmpz_poly_q_print(b), flint_printf("\n\n");
            fmpz_poly_q_print(lhs), flint_printf("\n\n");
            fmpz_poly_q_print(rhs), flint_printf("\n\n");
            abort();
        }

        fmpz_poly_q_clear(a);
        fmpz_poly_q_clear(b);
        fmpz_poly_q_clear(c);
        fmpz_poly_q_clear(d);
        fmpz_poly_q_clear(lhs);
        fmpz_poly_q_clear(rhs);
    }

    FLINT_TEST_CLEANUP(state);
    
    flint_printf("PASS\n");
    return EXIT_SUCCESS;
}
Ejemplo n.º 10
0
int
main(void)
{
    int i, result;
    flint_rand_t state;

    printf("set_si_equal....");
    fflush(stdout);

    flint_randinit(state);

    /* equal polynomials */
    for (i = 0; i < 10000; i++)
    {
        fmpz_poly_t a, b;
        long n;

        fmpz_poly_init(a);
        fmpz_poly_init(b);
        n = z_randtest(state);

        fmpz_poly_set_si(a, n);
        fmpz_poly_set(b, a);

        result = (fmpz_poly_equal(a, b));
        if (!result)
        {
            printf("FAIL:\n");
            printf("n = %ld\n\n", n);
            printf("a = "), fmpz_poly_print(a), printf("\n\n");
            printf("b = "), fmpz_poly_print(b), printf("\n\n");
            abort();
        }

        fmpz_poly_clear(a);
        fmpz_poly_clear(b);
    }

    for (i = 0; i < 10000; i++)
    {
        fmpz_poly_t a, b;
        long m, n;

        fmpz_poly_init(a);
        fmpz_poly_init(b);

        m = z_randtest(state);
        n = z_randtest(state);
        while (m == n)
            n = z_randtest(state);
        fmpz_poly_set_si(a, m);
        fmpz_poly_set_si(b, n);

        result = (!fmpz_poly_equal(a, b));
        if (!result)
        {
            printf("FAIL:\n");
            printf("m = %ld\n\n", m);
            printf("n = %ld\n\n", n);
            printf("a = "), fmpz_poly_print(a), printf("\n\n");
            printf("b = "), fmpz_poly_print(b), printf("\n\n");
            abort();
        }

        fmpz_poly_clear(a);
        fmpz_poly_clear(b);
    }

    flint_randclear(state);
    _fmpz_cleanup();
    printf("PASS\n");
    return 0;
}
Ejemplo n.º 11
0
int main()
{
    slong iter, iter2;
    flint_rand_t state;

    flint_printf("mul_si....");
    fflush(stdout);

    flint_randinit(state);

    for (iter = 0; iter < 3000; iter++)
    {
        fmpr_t x, z, v;
        slong y;
        slong prec, r1, r2;
        fmpr_rnd_t rnd;

        fmpr_init(x);
        fmpr_init(z);
        fmpr_init(v);

        for (iter2 = 0; iter2 < 30; iter2++)
        {
            fmpr_randtest_special(x, state, 2000, 200);
            y = z_randtest(state);
            prec = 2 + n_randint(state, 2000);

            switch (n_randint(state, 4))
            {
                case 0:  rnd = FMPR_RND_DOWN; break;
                case 1:  rnd = FMPR_RND_UP; break;
                case 2:  rnd = FMPR_RND_FLOOR; break;
                default: rnd = FMPR_RND_CEIL; break;
            }

            switch (n_randint(state, 2))
            {
            case 0:
                r1 = fmpr_mul_si(z, x, y, prec, rnd);
                r2 = fmpr_mul_si_naive(v, x, y, prec, rnd);
                if (!fmpr_equal(z, v) || r1 != r2 || !fmpr_check_ulp(z, r1, prec))
                {
                    flint_printf("FAIL!\n");
                    flint_printf("x = "); fmpr_print(x); flint_printf("\n\n");
                    flint_printf("y = %wd\n\n", y);
                    flint_printf("z = "); fmpr_print(z); flint_printf("\n\n");
                    flint_printf("v = "); fmpr_print(v); flint_printf("\n\n");
                    flint_printf("r1 = %wd, r2 = %wd\n", r1, r2);
                    abort();
                }
                break;

            default:
                fmpr_set(v, x);
                fmpr_set(z, x);
                r1 = fmpr_mul_si(z, z, y, prec, rnd);
                r2 = fmpr_mul_si_naive(v, v, y, prec, rnd);
                if (!fmpr_equal(z, v) || r1 != r2 || !fmpr_check_ulp(z, r1, prec))
                {
                    flint_printf("FAIL (aliasing 1)!\n");
                    flint_printf("x = "); fmpr_print(x); flint_printf("\n\n");
                    flint_printf("y = %wd\n\n", y);
                    flint_printf("z = "); fmpr_print(z); flint_printf("\n\n");
                    flint_printf("v = "); fmpr_print(v); flint_printf("\n\n");
                    flint_printf("r1 = %wd, r2 = %wd\n", r1, r2);
                    abort();
                }
                break;
            }
        }

        fmpr_clear(x);
        fmpr_clear(z);
        fmpr_clear(v);
    }

    flint_randclear(state);
    flint_cleanup();
    flint_printf("PASS\n");
    return EXIT_SUCCESS;
}
Ejemplo n.º 12
0
int main(void)
{
    long i, N = 1000, result;

    flint_rand_t state;

    _randinit(state);

    printf("int_rbtree... ");
    fflush(stdout);

    /* Initialise a tree, add 5N entries, remove 6N entries */
    {
        int_rbtree_t T;

        int_rbtree_init(T);

        for (i = 0; i < 5 * N; i++)
        {
            int ins;
            int a, b, c2, c4, c5;
            int x = z_randtest(state);
            int y = z_randtest(state);

            ins = int_rbtree_insert(&a, &b, T, x, y, &int_cmp);

            c2 = int_rbtree_verify2(RBTREE_ROOT(T));
            c4 = int_rbtree_verify4(RBTREE_ROOT(T));
            c5 = int_rbtree_verify5(RBTREE_ROOT(T));

            if (!c2 || !c4 || !c5)
            {
                printf("FAIL:\n");
                printf("c2 c4 c5 = %d %d %d\n", c2, c4, c5);
                abort();
            }
        }

        {
            int_rbtree_node * n;
            int_rbtree_iter_t iter;

            int_rbtree_iter_init(iter, T);
            while ((n = int_rbtree_iter_next(iter))) ;
            int_rbtree_iter_clear(iter);
        }

        for (i = 0; i < 6 * N; i++)
        {
            int del;
            int a, b, c2, c4, c5;
            int x = z_randtest(state);

            del = int_rbtree_delete(&a, &b, T, x, &int_cmp);

            c2 = int_rbtree_verify2(RBTREE_ROOT(T));
            c4 = int_rbtree_verify4(RBTREE_ROOT(T));
            c5 = int_rbtree_verify5(RBTREE_ROOT(T));

            if (!c2 || !c4 || !c5)
            {
                printf("FAIL:\n");
                printf("c2 c4 c5 = %d %d %d\n", c2, c4, c5);
                abort();
            }
        }

        int_rbtree_clear(T, NULL, NULL);
    }

    /*
        Create a tree, add elements from 0, ..., L, check that 
        we can remove them one at a time, finally ending up with 
        an empty tree
     */
    {
        int_rbtree_t T;
        int L = 1000;

        int_rbtree_init(T);

        for (i = 0; i < L; i++)
        {
            int ins;
            int a, b, c2, c4, c5;
            int x = i;
            int y = z_randtest(state);

            ins = int_rbtree_insert(&a, &b, T, x, y, &int_cmp);

            c2 = int_rbtree_verify2(RBTREE_ROOT(T));
            c4 = int_rbtree_verify4(RBTREE_ROOT(T));
            c5 = int_rbtree_verify5(RBTREE_ROOT(T));

            if (!c2 || !c4 || !c5)
            {
                printf("FAIL:\n");
                printf("c2 c4 c5 = %d %d %d\n", c2, c4, c5);
                abort();
            }
        }

        for (i = L - 1; i >= 0; i--)
        {
            int del;
            int a, b, c2, c4, c5;
            int x = i;

            del = int_rbtree_delete(&a, &b, T, x, &int_cmp);

            result = (del == 1);
            if (!result)
            {
                printf("FAIL:\n\n");
                printf("Could not remove %d from the tree.\n", x);
                abort();
            }

            c2 = int_rbtree_verify2(RBTREE_ROOT(T));
            c4 = int_rbtree_verify4(RBTREE_ROOT(T));
            c5 = int_rbtree_verify5(RBTREE_ROOT(T));

            if (!c2 || !c4 || !c5)
            {
                printf("FAIL:\n");
                printf("c2 c4 c5 = %d %d %d\n", c2, c4, c5);
                abort();
            }
        }

        result = int_rbtree_is_empty(T);
        if (!result)
        {
            printf("FAIL:\n\n");
            printf("Tree is not empty.\n");
            abort();
        }

        int_rbtree_clear(T, NULL, NULL);
    }


    _randclear(state);
    _fmpz_cleanup();
    printf("PASS\n");
    return EXIT_SUCCESS;
}
Ejemplo n.º 13
0
int
main(void)
{
    int i, result;
    FLINT_TEST_INIT(state);

    flint_printf("set_si_equal....");
    fflush(stdout);

    

    /* equal polynomials */
    for (i = 0; i < 1000 * flint_test_multiplier(); i++)
    {
        fmpz_poly_t a, b;
        slong n;

        fmpz_poly_init(a);
        fmpz_poly_init(b);
        n = z_randtest(state);

        fmpz_poly_set_si(a, n);
        fmpz_poly_set(b, a);

        result = (fmpz_poly_equal(a, b));
        if (!result)
        {
            flint_printf("FAIL:\n");
            flint_printf("n = %wd\n\n", n);
            flint_printf("a = "), fmpz_poly_print(a), flint_printf("\n\n");
            flint_printf("b = "), fmpz_poly_print(b), flint_printf("\n\n");
            abort();
        }

        fmpz_poly_clear(a);
        fmpz_poly_clear(b);
    }

    for (i = 0; i < 1000 * flint_test_multiplier(); i++)
    {
        fmpz_poly_t a, b;
        slong m, n;

        fmpz_poly_init(a);
        fmpz_poly_init(b);

        m = z_randtest(state);
        n = z_randtest(state);
        while (m == n)
            n = z_randtest(state);
        fmpz_poly_set_si(a, m);
        fmpz_poly_set_si(b, n);

        result = (!fmpz_poly_equal(a, b));
        if (!result)
        {
            flint_printf("FAIL:\n");
            flint_printf("m = %wd\n\n", m);
            flint_printf("n = %wd\n\n", n);
            flint_printf("a = "), fmpz_poly_print(a), flint_printf("\n\n");
            flint_printf("b = "), fmpz_poly_print(b), flint_printf("\n\n");
            abort();
        }

        fmpz_poly_clear(a);
        fmpz_poly_clear(b);
    }

    FLINT_TEST_CLEANUP(state);
    
    flint_printf("PASS\n");
    return 0;
}