libstdc++: Fix test that fails randomly [PR101866]
This test assumes that the same sequence of three values cannot occur, which is incorect. It's unlikely, but not impossible. Perform the check in a loop, so that in the unlikely event of an identical sequence, we retry. If the library code is buggy it will keep producing the same sequence and the test will time out. If the code is working correctly then we will usually break out of the loop after one iteration, or very rarely after two or three. libstdc++-v3/ChangeLog: PR libstdc++/101866 * testsuite/experimental/random/randint.cc: Loop and retry if reseed() produces the same sequence.
This commit is contained in:
parent
873273449a
commit
93f1dbc7cd
1 changed files with 9 additions and 9 deletions
|
@ -34,7 +34,7 @@ test01()
|
|||
}
|
||||
|
||||
std::experimental::reseed(99u);
|
||||
const long n1[] = {
|
||||
const int n1[] = {
|
||||
std::experimental::randint(0, 100),
|
||||
std::experimental::randint(0, 100),
|
||||
std::experimental::randint(0, 100),
|
||||
|
@ -42,7 +42,7 @@ test01()
|
|||
std::experimental::randint(0, 100)
|
||||
};
|
||||
std::experimental::reseed(99u);
|
||||
const long n2[] = {
|
||||
const int n2[] = {
|
||||
std::experimental::randint(0, 100),
|
||||
std::experimental::randint(0, 100),
|
||||
std::experimental::randint(0, 100),
|
||||
|
@ -52,13 +52,13 @@ test01()
|
|||
for (int i = 0; i < 5; ++i)
|
||||
VERIFY( n1[i] == n2[i] );
|
||||
|
||||
std::experimental::reseed();
|
||||
const long n3[] = {
|
||||
std::experimental::randint(0, 100),
|
||||
std::experimental::randint(0, 100),
|
||||
std::experimental::randint(0, 100)
|
||||
};
|
||||
VERIFY( !(n3[0] == n1[0] && n3[1] == n1[1] && n3[2] == n1[2]) );
|
||||
do
|
||||
{
|
||||
std::experimental::reseed();
|
||||
}
|
||||
while (std::experimental::randint(0, 100) == n1[0]
|
||||
&& std::experimental::randint(0, 100) == n1[1]
|
||||
&& std::experimental::randint(0, 100) == n1[2]);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
Loading…
Add table
Reference in a new issue