Added #undef G_DISABLE_ASSERT and #undef G_LOG_DOMAIN throughout the
[platform/upstream/glib.git] / tests / rand-test.c
1 #undef G_DISABLE_ASSERT
2 #undef G_LOG_DOMAIN
3
4 #include <glib.h>
5
6 const gint32 first_numbers[] = 
7 {
8   0x7a7a7a7a,
9   0x20aea82a,
10   0xcab337ab,
11   0xdcf770ea,
12   0xdf552b2f,
13   0x32d1ef7f,
14   0x6bed6dd9,
15   0x7222df44,
16   0x6b842128,
17   0x07f8579a,
18   0x9dad1004,
19   0x2df264f2,
20   0x13b48989,
21   0xf2929475,
22   0x30f30c97,
23   0x3f9a1ea7,
24   0x3bf04710,
25   0xb85bd69e,
26   0x790a48b0,
27   0xfa06b85f,
28   0xa64cc9e3
29 };
30
31 const gint length = sizeof (first_numbers) / sizeof (first_numbers[0]);
32
33 int main()
34 {
35   guint n;
36
37   GRand* rand = g_rand_new_with_seed (first_numbers[0]);
38
39   for (n = 1; n < length; n++)
40     g_assert (first_numbers[n] == g_rand_int (rand));
41
42   for (n = 1; n < 100000; n++)
43     {
44       gint32 i;
45       gdouble d;
46       gboolean b;
47
48       i = g_rand_int_range (rand, 8,16);
49       g_assert (i >= 8 && i < 16);
50       
51       i = g_random_int_range (8,16);
52       g_assert (i >= 8 && i < 16);
53
54       d = g_rand_double (rand);
55       g_assert (d >= 0 && d < 1);
56
57       d = g_random_double ();
58       g_assert (d >= 0 && d < 1);
59
60       d = g_rand_double_range (rand, -8, 32);
61       g_assert (d >= -8 && d < 32);
62  
63       d = g_random_double_range (-8, 32);
64       g_assert (d >= -8 && d < 32);
65  
66       b = g_random_boolean ();
67       g_assert (b == TRUE || b  == FALSE);
68  
69       b = g_rand_boolean (rand);
70       g_assert (b == TRUE || b  == FALSE);     
71     }
72
73   g_rand_free (rand);
74
75   return 0;
76 }
77