-
Notifications
You must be signed in to change notification settings - Fork 5.3k
runtime: added standard library compatibility to RandomGenerator #9053
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,6 +48,23 @@ TEST(Random, SanityCheckOfUniquenessRandom) { | |
| EXPECT_EQ(num_of_results, results.size()); | ||
| } | ||
|
|
||
| TEST(Random, SanityCheckOfStdLibRandom) { | ||
| Runtime::RandomGeneratorImpl random; | ||
|
|
||
| static const auto num_of_items = 100; | ||
| std::vector<uint64_t> v(num_of_items); | ||
| std::iota(v.begin(), v.end(), 0); | ||
|
|
||
| static const auto num_of_checks = 10000; | ||
| for (size_t i = 0; i < num_of_checks; ++i) { | ||
| const auto prev = v; | ||
| std::shuffle(v.begin(), v.end(), random); | ||
| EXPECT_EQ(v.size(), prev.size()); | ||
| EXPECT_NE(v, prev); | ||
| EXPECT_FALSE(std::is_sorted(v.begin(), v.end())); | ||
|
||
| } | ||
| } | ||
|
|
||
| TEST(UUID, CheckLengthOfUUID) { | ||
| RandomGeneratorImpl random; | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this also implicitly exercise
min()andmax()?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah,
std::uniform_int_distribution[1] used underneathstd::shuffleuses min() and max()[1] https://en.cppreference.com/w/cpp/numeric/random/uniform_int_distribution.