test/util/TestIntrusiveTreeSet: do not add duplicates in the LargeRandom tests
This can fail randomly if the order of identical values is different in the std::deque and the IntrusiveTreeSet.
This commit is contained in:
parent
dd59db2be2
commit
ca5580a560
@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
#include <cstdlib> // for std::rand()
|
#include <cstdlib> // for std::rand()
|
||||||
#include <deque>
|
#include <deque>
|
||||||
|
#include <set>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
@ -207,13 +208,24 @@ TEST(IntrusiveTreeSet, RandomOrder)
|
|||||||
|
|
||||||
TEST(IntrusiveTreeSet, LargeRandom)
|
TEST(IntrusiveTreeSet, LargeRandom)
|
||||||
{
|
{
|
||||||
|
std::set<int> dedup;
|
||||||
std::deque<std::unique_ptr<IntItem>> items;
|
std::deque<std::unique_ptr<IntItem>> items;
|
||||||
IntrusiveTreeSet<IntItem,
|
IntrusiveTreeSet<IntItem,
|
||||||
IntrusiveTreeSetOperators<IntItem, IntItem::GetKey>> set;
|
IntrusiveTreeSetOperators<IntItem, IntItem::GetKey>> set;
|
||||||
|
|
||||||
std::srand(42);
|
std::srand(42);
|
||||||
for (unsigned i = 0; i < 1024; ++i) {
|
for (unsigned i = 0; i < 1024; ++i) {
|
||||||
items.emplace_back(std::make_unique<IntItem>(std::rand()));
|
/* prevent duplicates to avoid different ordering of
|
||||||
|
identical values in the std::deque and in the
|
||||||
|
IntrusiveTreeSet */
|
||||||
|
int value;
|
||||||
|
while (true) {
|
||||||
|
value = std::rand();
|
||||||
|
if (dedup.insert(value).second)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
items.emplace_back(std::make_unique<IntItem>(value));
|
||||||
set.insert(*items.back());
|
set.insert(*items.back());
|
||||||
|
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
|
Loading…
x
Reference in New Issue
Block a user