10 #include "testing/testing.h"
15 TEST(map, DefaultConstructor)
22 TEST(map, AddIncreasesSize)
54 TEST(map, LookupNotExisting)
66 for (
int i = 0; i < 100; i++) {
95 std::optional<int> value = map.
pop_try(4);
97 EXPECT_FALSE(value.has_value());
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);
208 TEST(map, MutableValueIterator)
214 for (
int &value : map.
values()) {
228 for (
auto item : map.
items()) {
229 item.value += item.key;
236 TEST(map, MutableItemToItemConversion)
245 values.
append(item.value);
261 TEST(map, LookupOrAddCB_SeparateFunction)
270 TEST(map, LookupOrAddCB_Lambdas)
273 auto lambda1 = []() {
return 11.0f; };
275 auto lambda2 = []() {
return 20.0f; };
289 auto modify_func = [](
float *value) {
299 TEST(map, AddOrModifyReference)
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 & {
325 EXPECT_FALSE(map.
add(3, 8.0f));
349 TEST(map, MoveConstructorSmall)
362 TEST(map, MoveConstructorLarge)
365 for (
int i = 0; i < 100; i++) {
382 map2 = std::move(map1);
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));
434 map.
add_new(5, std::make_unique<int>());
435 map.
add(6, 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));
469 EXPECT_TRUE(map.
remove(&b));
478 map.
add(
"45",
"643");
502 TEST(map, CopyConstructorExceptions)
508 map.lookup(2).throw_during_copy =
true;
509 EXPECT_ANY_THROW({ MapType map_copy(map); });
512 TEST(map, MoveConstructorExceptions)
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); });
560 TEST(map, AddOrModifyExceptions)
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; }));
600 EXPECT_TRUE(std::any_of(
611 template<
typename MapT>
616 for (
int i = 0; i < amount; i++) {
624 for (
int value : values) {
625 map.add(value, value);
631 for (
int value : values) {
632 count += map.contains(value);
637 for (
int value : values) {
638 count += map.remove(value);
643 std::cout <<
"Count: " <<
count <<
"\n";
648 for (
int i = 0; i < 3; i++) {
649 benchmark_random_ints<blender::Map<int, int>>(
"blender::Map ", 1000000, 1);
650 benchmark_random_ints<blender::StdUnorderedMapWrapper<int, int>>(
"std::unordered_map", 1000000, 1);
653 for (
int i = 0; i < 3; i++) {
655 benchmark_random_ints<blender::Map<int, int>>(
"blender::Map ", 1000000, factor);
656 benchmark_random_ints<blender::StdUnorderedMapWrapper<int, int>>(
657 "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)
static PyObject * create_func(PyObject *, PyObject *args)
ATTR_WARN_UNUSED_RESULT const BMVert * v
Value pop(const Key &key)
bool add_overwrite(const Key &key, const Value &value)
bool add(const Key &key, const Value &value)
ValueIterator values() const
const Value & lookup(const Key &key) const
Value & lookup_or_add_cb(const Key &key, const CreateValueF &create_value)
void foreach_item(const FuncT &func) const
Value & lookup_or_add_default(const Key &key)
void add_new(const Key &key, const Value &value)
Value & lookup_or_add(const Key &key, const Value &value)
bool remove(const Key &key)
ItemIterator items() const
bool contains(const Key &key) const
const Value * lookup_ptr(const Key &key) const
auto add_or_modify(const Key &key, const CreateValueF &create_value, const ModifyValueF &modify_value) -> decltype(create_value(nullptr))
Value pop_default(const Key &key, const Value &default_value)
std::optional< Value > pop_try(const Key &key)
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(array, DefaultConstructor)
SubIterator begin() const
BLI_INLINE float D(const float *data, const int res[3], int x, int y, int z)