29 #include <gtest/gtest.h>
46 TEST(DuelerTest, SetSample)
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());
112 constituencySize = std::get<1>(GetParam());
113 teamSize = std::get<2>(GetParam());
114 numBits = std::get<3>(GetParam());
115 lowThreshold = std::get<4>(GetParam());
116 highThreshold = std::get<5>(GetParam());
118 monitor.reset(
new DuelingMonitor(constituencySize, teamSize, numBits,
119 lowThreshold, highThreshold));
122 entries.resize(num_entries);
123 for (
auto& entry : entries) {
124 monitor->initEntry(&entry);
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))