1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*
Copyright (C) 2023 Albin Ahlbäck
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_equal_si_ui, state)
{
int i;
int res;
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
fmpq_t x;
slong y_si = 0; /* Silence warnings about maybe uninitialized */
ulong y_ui = 0;
int type;
fmpq_init(x);
type = n_randint(state, 4);
if (type == 0)
{
/* Let x be proper rational, y is slong */
do { fmpq_randtest(x, state, 200); } while (x->den == WORD(1));
y_si = z_randtest(state);
/* Then x != y */
res = (fmpq_equal_si(x, y_si) == 0);
}
else if (type == 1)
{
/* Let x be integer, y is slong */
fmpz_one(fmpq_denref(x));
y_si = z_randtest(state);
if (n_randint(state, 2))
{
/* Random numerator */
fmpz_randtest(fmpq_numref(x), state, 200);
res = (fmpq_equal_si(x, y_si) == fmpz_equal_si(fmpq_numref(x), y_si));
}
else
{
/* Numerator of x equals to y */
fmpz_set_si(fmpq_numref(x), y_si);
res = (fmpq_equal_si(x, y_si) == 1);
}
}
else if (type == 2)
{
/* Let x be proper rational, y is ulong */
do { fmpq_randtest(x, state, 200); } while (x->den == WORD(1));
y_ui = n_randtest(state);
/* Then x != y */
res = (fmpq_equal_ui(x, y_ui) == 0);
}
else
{
/* Let x be integer, y is ulong */
fmpz_one(fmpq_denref(x));
y_ui = n_randtest(state);
if (n_randint(state, 2))
{
/* Random numerator */
fmpz_randtest(fmpq_numref(x), state, 200);
res = (fmpq_equal_ui(x, y_ui) == fmpz_equal_ui(fmpq_numref(x), y_ui));
}
else
{
/* Numerator of x equals to y */
fmpz_set_ui(fmpq_numref(x), y_ui);
res = (fmpq_equal_ui(x, y_ui) == 1);
}
}
if (!res)
{
flint_printf("FAIL\n");
flint_printf("x = ");
fmpq_print(x);
flint_printf("\ntype = %d", type);
if (type <= 1)
flint_printf("y_si = %wd\n", y_si);
else
flint_printf("y_ui = %wu\n", y_ui);
fflush(stdout);
flint_abort();
}
fmpq_clear(x);
}
TEST_FUNCTION_END(state);
}