#include #include "gtest/gtest.h" #include namespace mm { TEST(Utils, RandGetSeed) { assert(get_seed() != get_seed()); } TEST(Utils, RandChoice) { // random choice -- deterministic tests Range elements = {1, 2, 3}; Range weights = {0, 3, 0}; EXPECT_EQ(random_choice(elements, weights), 2); weights = {0, 1, 0}; EXPECT_EQ(random_choice(elements, weights, true), 2); elements = {0, 1, 2}; std::mt19937 generator(42); std::vector counts = {0, 0, 0}; for (int i = 0; i < 100; ++i) { int c = random_choice(elements, {1, 1, 1}, false, generator); EXPECT_LE(0, c); EXPECT_LE(c, 2); counts[c]++; } EXPECT_LE(30, counts[0]); EXPECT_LE(counts[0], 37); EXPECT_LE(30, counts[1]); EXPECT_LE(counts[1], 37); EXPECT_LE(30, counts[2]); EXPECT_LE(counts[2], 37); } } // namespace mm