Aleph-w
7.10.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
ran_array_test.cc
Go to the documentation of this file.
1
/*
2
Aleph_w
3
4
Data structures & Algorithms
5
version 2.0.0b
6
https://github.com/lrleon/Aleph-w
7
8
This file is part of Aleph-w library
9
10
Copyright (c) 2002-2026 Leandro Rabindranath Leon
11
12
Permission is hereby granted, free of charge, to any person obtaining a copy
13
of this software and associated documentation files (the "Software"), to deal
14
in the Software without restriction, including without limitation the rights
15
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16
copies of the Software, and to permit persons to whom the Software is
17
furnished to do so, subject to the following conditions:
18
19
The above copyright notice and this permission notice shall be included in all
20
copies or substantial portions of the Software.
21
22
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28
SOFTWARE.
29
*/
30
37
#include <gtest/gtest.h>
38
39
#include <vector>
40
41
// ran_array.h is deprecated, but supported until 8.0.0; this test is its
42
// coverage.
43
#if defined(_MSC_VER) && !defined(__clang__)
44
# pragma warning(push)
45
# pragma warning(disable : 4996)
46
#else
47
# pragma GCC diagnostic push
48
# pragma GCC diagnostic ignored "-Wdeprecated-declarations"
49
#endif
50
51
#include <
ran_array.h
>
52
53
// The check of rng.c: after ran_start(310952), the first number of the 2010th
54
// batch of 1009 is 995235265. ran_arr_next() gives the first 100 numbers of
55
// each batch, so that number is its draw 200900, counted from 0
56
TEST
(RanArray, GivesTheNumberOfTheCheckOfKnuth)
57
{
58
ran_start
(310952L);
59
for
(
long
i = 0; i < 200900; ++i)
60
static_cast<
void
>
(
ran_arr_next
());
61
EXPECT_EQ(
ran_arr_next
(), 995235265L);
62
}
63
64
// The same seed gives the same numbers, in [0, 2^30)
65
TEST
(RanArray, TheSameSeedGivesTheSameNumbers)
66
{
67
ran_start
(4357L);
68
std::vector<long> first;
69
for
(
int
i = 0; i < 1000; ++i)
70
first.push_back(
ran_arr_next
());
71
72
ran_start
(4357L);
73
for
(
const
long
x : first)
74
{
75
EXPECT_GE(x, 0L);
76
EXPECT_LT(x, 1L << 30);
77
EXPECT_EQ(
ran_arr_next
(), x);
78
}
79
}
80
81
#if defined(_MSC_VER) && !defined(__clang__)
82
# pragma warning(pop)
83
#else
84
# pragma GCC diagnostic pop
85
#endif
TEST
#define TEST(name)
Definition
disjoint_sparse_table_test.cc:95
ran_start
void ran_start(long seed)
Starts the generator with seed: do this before using it.
Definition
ran_array.c:66
ran_array.h
Knuth's random number generator, from his rng.c (The Art of Computer Programming, Volume 2,...
ran_arr_next
#define ran_arr_next()
The next random number.
Definition
ran_array.h:99
Tests
ran_array_test.cc
Generated by
1.9.8