blob: f06f6de527408469641486744da41c69ca800b7b [file] [log] [blame]
James Kuszmaul05ccb272023-07-13 10:58:14 -07001#include <set>
2#include <unordered_set>
3
4#include "glog/logging.h"
5#include "gtest/gtest.h"
6
7#include "aos/uuid.h"
8
9namespace aos {
10namespace testing {
11
12// Tests that modest numbers of UUID::Random() calls cannot create UUID
13// collisions (to test that we have not *completely* messed up the random number
14// generation).
15TEST(UUIDTest, CollisionTest) {
16 std::set<UUID> uuids;
17 // When we only had ~32 bits of randomness in our UUIDs, we could generate
18 // issues with only ~sqrt(2 ** 32) (aka 2 ** 16) UUIDs.
19 // Just go up to 2 ** 22, since too much longer just makes this test take
20 // obnoxiously long.
21 for (size_t ii = 0; ii < (1UL << 22); ++ii) {
22 UUID uuid = UUID::Random();
23 ASSERT_FALSE(uuids.count(uuid) > 0) << ii;
24 uuids.insert(uuid);
25 }
26}
27} // namespace testing
28} // namespace aos