10 #include "testing/testing.h"
19 EXPECT_TRUE(
map.is_empty());
26 EXPECT_TRUE(
map.is_empty());
29 EXPECT_FALSE(
map.is_empty());
32 EXPECT_FALSE(
map.is_empty());
38 EXPECT_FALSE(
map.contains(4));
40 EXPECT_FALSE(
map.contains(4));
42 EXPECT_TRUE(
map.contains(4));
66 for (
int i = 0; i < 100; i++) {
77 EXPECT_TRUE(
map.contains(2));
78 EXPECT_TRUE(
map.contains(1));
81 EXPECT_TRUE(
map.contains(2));
82 EXPECT_FALSE(
map.contains(1));
85 EXPECT_FALSE(
map.contains(2));
86 EXPECT_FALSE(
map.contains(1));
95 std::optional<int> value =
map.pop_try(4);
97 EXPECT_FALSE(value.has_value());
98 value =
map.pop_try(2);
100 EXPECT_TRUE(value.has_value());
128 for (
int i = 0; i < 100; i++) {
131 for (
int i = 25; i < 80; i++) {
134 for (
int i = 0; i < 100; i++) {
149 for (
float value :
map.values()) {
156 EXPECT_TRUE(values.
contains(-2.0f));
170 for (
int key :
map.keys()) {
193 for (
auto item : const_map.
items()) {
195 values.
add(item.value);
214 for (
int &value :
map.values()) {
228 for (
auto item :
map.items()) {
229 item.value += item.key;
245 values.
append(item.value);
273 auto lambda1 = []() {
return 11.0f; };
275 auto lambda2 = []() {
return 20.0f; };
289 auto modify_func = [](
float *value) {
302 auto create_func = [](std::unique_ptr<int> *value) ->
int & {
303 new (value) std::unique_ptr<int>(
new int{10});
306 auto modify_func = [](std::unique_ptr<int> *value) ->
int & {
320 EXPECT_FALSE(
map.contains(3));
321 EXPECT_TRUE(
map.add_overwrite(3, 6.0f));
323 EXPECT_FALSE(
map.add_overwrite(3, 7.0f));
325 EXPECT_FALSE(
map.add(3, 8.0f));
332 map.lookup_or_add_default(3) = 6;
334 map.lookup_or_add_default(5) = 2;
336 map.lookup_or_add_default(3) += 4;
345 map.lookup_or_add(6, 4) += 10;
365 for (
int i = 0; i < 100; i++) {
382 map2 = std::move(map1);
411 EXPECT_TRUE(
map.contains(1));
412 EXPECT_TRUE(
map.contains(2));
417 EXPECT_FALSE(
map.contains(1));
418 EXPECT_FALSE(
map.contains(2));
423 auto value1 = std::make_unique<int>();
424 auto value2 = std::make_unique<int>();
425 auto value3 = std::make_unique<int>();
427 int *value1_ptr = value1.get();
430 map.add_new(1, std::move(value1));
431 map.add(2, std::move(value2));
432 map.add_overwrite(3, std::move(value3));
433 map.lookup_or_add_cb(4, []() {
return std::make_unique<int>(); });
434 map.add_new(5, std::make_unique<int>());
435 map.add(6, std::make_unique<int>());
436 map.add_overwrite(7, std::make_unique<int>());
437 map.lookup_or_add(8, std::make_unique<int>());
438 map.pop_default(9, std::make_unique<int>());
449 EXPECT_FALSE(
map.remove(3));
451 EXPECT_TRUE(
map.remove(2));
460 EXPECT_TRUE(
map.add(&
a, 5));
461 EXPECT_FALSE(
map.add(&
a, 4));
465 EXPECT_TRUE(
map.remove(&
b));
466 EXPECT_TRUE(
map.add(&
b, 8));
467 EXPECT_FALSE(
map.remove(&d));
468 EXPECT_TRUE(
map.remove(&
a));
469 EXPECT_TRUE(
map.remove(&
b));
470 EXPECT_TRUE(
map.remove(&
c));
471 EXPECT_TRUE(
map.is_empty());
478 map.add(
"45",
"643");
479 EXPECT_TRUE(
map.contains(
"45"));
480 EXPECT_FALSE(
map.contains(
"54"));
491 map.foreach_item([&](
int key,
int value) {
508 map.lookup(2).throw_during_copy =
true;
509 EXPECT_ANY_THROW({ MapType map_copy(
map); });
518 map.lookup(1).throw_during_move =
true;
519 EXPECT_ANY_THROW({ MapType map_moved(std::move(
map)); });
529 EXPECT_ANY_THROW({
map.add_new(key1, value1); });
534 EXPECT_ANY_THROW({
map.add_new(key2, value2); });
543 map.lookup(2).throw_during_move =
true;
544 EXPECT_ANY_THROW({
map.reserve(100); });
553 map.lookup(3).throw_during_move =
true;
554 EXPECT_ANY_THROW({
map.pop(3); });
565 EXPECT_ANY_THROW({
map.add_or_modify(3, create_fn, modify_fn); });
569 enum class TestEnum {
598 EXPECT_TRUE(std::any_of(
map.keys().begin(),
map.keys().end(), [](
int v) { return v == 1; }));
599 EXPECT_TRUE(std::any_of(
map.values().begin(),
map.values().end(), [](
int v) { return v == 1; }));
600 EXPECT_TRUE(std::any_of(
601 map.items().begin(),
map.items().end(), [](
auto item) { return item.value == 1; }));
610 map.add_as(3,
"hello", 2);
611 map.add_as(2,
"test", 1);
628 Iter begin =
map.items().begin();
629 Iter end =
map.items().end();
630 for (Iter iter = begin; iter != end; ++iter) {
632 if (item.value == 2) {
660 template<
typename MapT>
665 for (
int i = 0; i < amount; i++) {
673 for (
int value : values) {
674 map.add(value, value);
680 for (
int value : values) {
686 for (
int value : values) {
692 std::cout <<
"Count: " <<
count <<
"\n";
697 for (
int i = 0; i < 3; i++) {
698 benchmark_random_ints<blender::Map<int, int>>(
"blender::Map ", 1000000, 1);
699 benchmark_random_ints<blender::StdUnorderedMapWrapper<int, int>>(
"std::unordered_map", 1000000, 1);
702 for (
int i = 0; i < 3; i++) {
704 benchmark_random_ints<blender::Map<int, int>>(
"blender::Map ", 1000000, factor);
705 benchmark_random_ints<blender::StdUnorderedMapWrapper<int, int>>(
706 "std::unordered_map", 1000000, 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 add(const Key &key, const Value &value)
const Value & lookup(const Key &key) const
void add_new(const Key &key, const Value &value)
ItemIterator items() const
const Value * lookup_ptr(const Key &key) const
bool contains(const Key &key) const
bool contains(const T &value) const
void append(const T &value)
int64_t first_index_of(const T &value) const
TEST(any, DefaultConstructor)
static const pxr::TfToken b("b", pxr::TfToken::Immortal)
SocketIndexByIdentifierMap * map
static PyObject * create_func(PyObject *, PyObject *args)
BLI_INLINE float D(const float *data, const int res[3], int x, int y, int z)