4 #include <unordered_set>
13 #include "testing/testing.h"
18 TEST(set, DefaultConstructor)
25 TEST(set, ContainsNotExistant)
31 TEST(set, ContainsExistant)
44 for (
int i = 0; i < 100; i++) {
48 for (
int i = 50; i < 100; i++) {
51 for (
int i = 100; i < 150; i++) {
56 TEST(set, InitializerListConstructor)
110 set2 = std::move(set);
138 for (
int i = 0; i < 1000; i++) {
141 for (
int i = 100; i < 1000; i++) {
144 for (
int i = 900; i < 1000; i++) {
148 for (
int i = 0; i < 1000; i++) {
149 if (i < 100 || i >= 900) {
177 a.add_multiple({5, 7});
178 EXPECT_TRUE(
a.contains(5));
179 EXPECT_TRUE(
a.contains(7));
180 EXPECT_FALSE(
a.contains(4));
181 a.add_multiple({2, 4, 7});
182 EXPECT_TRUE(
a.contains(4));
183 EXPECT_TRUE(
a.contains(2));
190 a.add_multiple_new({5, 6});
191 EXPECT_TRUE(
a.contains(5));
192 EXPECT_TRUE(
a.contains(6));
199 for (
int value : set) {
210 TEST(set, OftenAddRemoveContained)
213 for (
int i = 0; i < 100; i++) {
224 set.
add_new(std::make_unique<int>());
225 auto value1 = std::make_unique<int>();
226 set.
add_new(std::move(value1));
227 set.
add(std::make_unique<int>());
248 EXPECT_FALSE(set.
contains(
"world2"));
267 EXPECT_TRUE(set.
remove(2));
270 EXPECT_FALSE(set.
remove(2));
272 EXPECT_TRUE(set.
remove(5));
286 return a.value ==
b.value;
290 return a.value ==
b.value;
355 EXPECT_TRUE(set.
add_as(
"test"));
358 EXPECT_FALSE(set.
add_as(
"qwe"));
364 return (
a %
N) == (
b %
N);
375 TEST(set, CustomizeHashAndEquality)
399 EXPECT_TRUE(set.add(4));
400 EXPECT_TRUE(set.add(3));
401 EXPECT_TRUE(set.add(11));
402 EXPECT_TRUE(set.add(8));
403 EXPECT_FALSE(set.add(3));
404 EXPECT_FALSE(set.add(4));
405 EXPECT_TRUE(set.remove(4));
406 EXPECT_FALSE(set.remove(7));
407 EXPECT_TRUE(set.add(4));
408 EXPECT_TRUE(set.remove(4));
422 return a.key ==
b.key;
475 EXPECT_FALSE(set.
contains(
"worlds"));
480 TEST(set, SpanConstructorExceptions)
482 std::array<ExceptionThrower, 5>
array = {1, 2, 3, 4, 5};
483 array[3].throw_during_copy =
true;
489 TEST(set, CopyConstructorExceptions)
496 TEST(set, MoveConstructorExceptions)
499 SetType set = {1, 2, 3};
501 EXPECT_ANY_THROW({ SetType set_moved(std::move(set)); });
503 set.add_multiple({3, 6, 7});
512 EXPECT_ANY_THROW({ set.
add_new(value); });
514 EXPECT_ANY_THROW({ set.
add_new(value); });
523 EXPECT_ANY_THROW({ set.
add(value); });
525 EXPECT_ANY_THROW({ set.
add(value); });
542 EXPECT_FALSE(std::any_of(set.
begin(), set.
end(), [](
int v) { return v == 5; }));
543 EXPECT_TRUE(std::any_of(set.
begin(), set.
end(), [](
int v) { return v == 30; }));
547 TEST(set, RemoveDuringIteration)
558 Iter begin = set.
begin();
559 Iter end = set.
end();
560 for (Iter iter = begin; iter != end; ++iter) {
577 template<
typename SetT>
582 for (
int i = 0; i < amount; i++) {
590 for (
int value : values) {
597 for (
int value : values) {
598 count += set.contains(value);
603 for (
int value : values) {
604 count += set.remove(value);
609 std::cout <<
"Count: " <<
count <<
"\n";
614 for (
int i = 0; i < 3; i++) {
615 benchmark_random_ints<blender::Set<int>>(
"blender::Set ", 100000, 1);
616 benchmark_random_ints<blender::StdUnorderedSetWrapper<int>>(
"std::unordered_set", 100000, 1);
619 for (
int i = 0; i < 3; i++) {
621 benchmark_random_ints<blender::Set<int>>(
"blender::Set ", 100000, factor);
622 benchmark_random_ints<blender::StdUnorderedSetWrapper<int>>(
"std::unordered_set", 100000, factor);
EXPECT_EQ(BLI_expr_pylike_eval(expr, nullptr, 0, &result), EXPR_PYLIKE_INVALID)
void int BLI_rng_get_int(struct RNG *rng) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
void BLI_rng_free(struct RNG *rng) ATTR_NONNULL(1)
struct RNG * BLI_rng_new(unsigned int seed)
Strict compiler flags for areas of code we want to ensure don't do conversions without us knowing abo...
#define SCOPED_TIMER(name)
ATTR_WARN_UNUSED_RESULT const BMVert * v
bool remove_as(const ForwardKey &key)
const Key * lookup_key_ptr(const Key &key) const
const Key & lookup_key(const Key &key) const
bool add_as(ForwardKey &&key)
bool contains_as(const ForwardKey &key) const
void remove_contained(const Key &key)
bool contains(const Key &key) const
const Key & lookup_key_or_add(const Key &key)
void add_new(const Key &key)
void remove_contained_as(const ForwardKey &key)
const Key & lookup_key_default(const Key &key, const Key &default_value) const
bool remove(const Key &key)
bool contains(const T &value) const
void append(const T &value)
static bool operator==(const Type1 &a, const Type1 &b)
TEST(any, DefaultConstructor)
PythonProbingStrategy<> DefaultProbingStrategy
static const pxr::TfToken b("b", pxr::TfToken::Immortal)
unsigned __int64 uint64_t
uint32_t operator()(const tests::Type1 &value) const
uint32_t operator()(const tests::Type2 &value) const
bool operator()(uint a, uint b) const
uint64_t operator()(uint value) const
friend bool operator==(const MyKeyType &a, const MyKeyType &b)