flint-sys 0.9.0

Bindings to the FLINT C library
Documentation
/*
    Copyright (C) 2011 Fredrik Johansson
    Copyright (C) 2014 William Hart

    This file is part of FLINT.

    FLINT is free software: you can redistribute it and/or modify it under
    the terms of the GNU Lesser General Public License (LGPL) as published
    by the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.  See <https://www.gnu.org/licenses/>.
*/

#include "test_helpers.h"
#include "long_extras.h"
#include "fmpq.h"

TEST_FUNCTION_START(fmpq_add_si, state)
{
    int i, result;

    for (i = 0; i < 10000 * flint_test_multiplier(); i++)
    {
        fmpq_t a;
        slong b;
        fmpq_t c, d, e, f;
        int aliasing;

        fmpq_init(a);
        fmpq_init(c);
        fmpq_init(d);
        fmpq_init(e);
        fmpq_init(f);

        fmpq_randtest(a, state, 200);
        b = z_randtest(state);

        fmpq_set(d, a);
        fmpq_set_si(e, b, 1);

        aliasing = n_randint(state, 2);

        if (aliasing == 0)
        {
            fmpq_add_si(c, a, b);
        }
        else
        {
            fmpq_set(c, a);
            fmpq_add_si(c, c, b);
        }

        fmpq_add(f, d, e);

        result = (fmpq_cmp(f, c) == 0) && fmpq_is_canonical(c);
        if (!result)
        {
            flint_printf("FAIL:\n");
            printf("c = "); fmpq_print(c);
            printf(", d = "); fmpq_print(d);
            printf(", e = "); fmpq_print(e);
            printf(", f = "); fmpq_print(f); printf("\n");
            fflush(stdout);
            flint_abort();
        }

        fmpq_clear(a);
        fmpq_clear(c);
        fmpq_clear(d);
        fmpq_clear(e);
        fmpq_clear(f);
    }

    TEST_FUNCTION_END(state);
}