29#include <gtest/gtest.h>
48 const int num_sampled_ids = 3;
53 for (
int id = 0;
id < 64;
id++) {
54 ASSERT_FALSE(dueler.
isSample(1ULL <<
id, team));
59 for (
int id = 0;
id < num_sampled_ids;
id++) {
65 bool expected_team =
false;
66 for (
int id = 0;
id < 64;
id++) {
67 expected_team = !expected_team;
68 const bool is_sample = dueler.
isSample(1ULL <<
id, team);
69 if (
id < num_sampled_ids) {
70 ASSERT_TRUE(is_sample);
71 ASSERT_EQ(team, expected_team);
73 ASSERT_FALSE(is_sample);
84 std::tuple<unsigned, std::size_t, std::size_t, unsigned, double, double>>
111 const unsigned num_entries = std::get<0>(GetParam());
114 numBits = std::get<3>(GetParam());
143 const int expected_num_samples =
144 (entries.size() / constituencySize) * teamSize;
148 int count_samples_true = 0;
149 int count_samples_false = 0;
151 for (
auto& entry : entries) {
152 if (entry.isSample(1ULL <<
monitor_id, team)) {
154 count_samples_true++;
156 count_samples_false++;
160 ASSERT_EQ(count_samples_true, count_samples_false);
161 ASSERT_EQ(count_samples_true, expected_num_samples);
169 expected_selector >>= 1;
173 int team_true_index = -1;
174 int team_false_index = -1;
175 int no_sample_index = -1;
180 team_true_index =
index;
182 team_false_index =
index;
185 no_sample_index =
index;
188 ASSERT_TRUE(team_true_index >= 0);
189 ASSERT_TRUE(team_false_index >= 0);
195 bool current_winner = monitor->getWinner();
196 double threshold = current_winner ? lowThreshold : highThreshold;
198 expected_selector++) {
200 monitor->getWinner());
201 monitor->sample(&entries[team_true_index]);
203 current_winner = monitor->getWinner();
204 ASSERT_TRUE(current_winner);
207 if (no_sample_index >= 0) {
208 for (
int i = 0;
i < 200;
i++) {
209 monitor->sample(&entries[no_sample_index]);
211 ASSERT_EQ(current_winner, monitor->getWinner());
217 threshold = lowThreshold;
219 expected_selector--) {
221 monitor->getWinner());
222 monitor->sample(&entries[team_false_index]);
224 current_winner = monitor->getWinner();
225 ASSERT_FALSE(current_winner);
228 if (no_sample_index >= 0) {
229 for (
int i = 0;
i < 200;
i++) {
230 monitor->sample(&entries[no_sample_index]);
232 ASSERT_EQ(current_winner, monitor->getWinner());
243 std::make_tuple(32, 2, 1, 1, 0.5, 0.5),
244 std::make_tuple(32, 4, 1, 1, 0.5, 0.5),
245 std::make_tuple(32, 4, 2, 1, 0.5, 0.5),
246 std::make_tuple(32, 8, 1, 1, 0.5, 0.5),
247 std::make_tuple(32, 8, 2, 1, 0.5, 0.5),
248 std::make_tuple(32, 8, 4, 1, 0.5, 0.5),
249 std::make_tuple(32, 16, 1, 1, 0.5, 0.5),
250 std::make_tuple(32, 16, 2, 1, 0.5, 0.5),
251 std::make_tuple(32, 16, 4, 1, 0.5, 0.5),
252 std::make_tuple(32, 16, 8, 1, 0.5, 0.5),
255 std::make_tuple(16, 4, 1, 3, 0.5, 0.5),
256 std::make_tuple(16, 4, 1, 3, 0.1, 0.7),
257 std::make_tuple(16, 4, 1, 3, 0.4, 0.6),
258 std::make_tuple(16, 4, 1, 3, 0.8, 0.9),
261 std::make_tuple(2048, 32, 4, 4, 0.4, 0.6))
double highThreshold
The high threshold to change winner, acquired from params.
std::size_t constituencySize
The constituency size, acquired from params.
std::vector< Dueler > entries
A vector simulating a table-like structure.
std::unique_ptr< DuelingMonitor > monitor
The monitor instance being tested.
std::size_t teamSize
The size of a team, acquired from params.
double lowThreshold
The low threshold to change winner, acquired from params.
unsigned numBits
The number of bits in the selector, acquired from params.
A dueler is an entry that may or may not be accounted for sampling.
void setSample(uint64_t id, bool team)
Make this entry a sampling entry for a specific Dueling instance.
bool isSample(uint64_t id, bool &team) const
Check if entry is a sample for the given instance.
Duel between two sampled options to determine which is the winner.
static uint64_t monitor_id
INSTANTIATE_TEST_CASE_P(DuelingMonitorTests, DuelingMonitorTest, ::testing::Values(std::make_tuple(32, 2, 1, 1, 0.5, 0.5), std::make_tuple(32, 4, 1, 1, 0.5, 0.5), std::make_tuple(32, 4, 2, 1, 0.5, 0.5), std::make_tuple(32, 8, 1, 1, 0.5, 0.5), std::make_tuple(32, 8, 2, 1, 0.5, 0.5), std::make_tuple(32, 8, 4, 1, 0.5, 0.5), std::make_tuple(32, 16, 1, 1, 0.5, 0.5), std::make_tuple(32, 16, 2, 1, 0.5, 0.5), std::make_tuple(32, 16, 4, 1, 0.5, 0.5), std::make_tuple(32, 16, 8, 1, 0.5, 0.5), std::make_tuple(16, 4, 1, 3, 0.5, 0.5), std::make_tuple(16, 4, 1, 3, 0.1, 0.7), std::make_tuple(16, 4, 1, 3, 0.4, 0.6), std::make_tuple(16, 4, 1, 3, 0.8, 0.9), std::make_tuple(2048, 32, 4, 4, 0.4, 0.6)))
TEST_P(DuelingMonitorTest, CountSamples)
Test whether entry initialization creates exactly the amount of samples requested.
TEST(DuelerTest, SetSample)
Test whether dueler provides correct sampling functionality and assigns teams correctly.
double calcSaturation() const
Calculate saturation percentile of the current counter's value with regard to its maximum possible va...
T saturate()
Saturate the counter.
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.