Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenlib/tests/BLI_map_test.cc
| Show First 20 Lines • Show All 598 Lines • ▼ Show 20 Lines | TEST(map, GenericAlgorithms) | ||||
| EXPECT_TRUE(std::any_of(map.values().begin(), map.values().end(), [](int v) { return v == 1; })); | EXPECT_TRUE(std::any_of(map.values().begin(), map.values().end(), [](int v) { return v == 1; })); | ||||
| EXPECT_TRUE(std::any_of( | EXPECT_TRUE(std::any_of( | ||||
| map.items().begin(), map.items().end(), [](auto item) { return item.value == 1; })); | map.items().begin(), map.items().end(), [](auto item) { return item.value == 1; })); | ||||
| EXPECT_EQ(std::count(map.values().begin(), map.values().end(), 2), 2); | EXPECT_EQ(std::count(map.values().begin(), map.values().end(), 2), 2); | ||||
| EXPECT_EQ(std::count(map.values().begin(), map.values().end(), 4), 1); | EXPECT_EQ(std::count(map.values().begin(), map.values().end(), 4), 1); | ||||
| EXPECT_EQ(std::count(map.keys().begin(), map.keys().end(), 7), 1); | EXPECT_EQ(std::count(map.keys().begin(), map.keys().end(), 7), 1); | ||||
| } | } | ||||
| TEST(map, AddAsVariadic) | |||||
| { | |||||
| Map<int, StringRef> map; | |||||
| map.add_as(3, "hello", 2); | |||||
| map.add_as(2, "test", 1); | |||||
| EXPECT_EQ(map.lookup(3), "he"); | |||||
| EXPECT_EQ(map.lookup(2), "t"); | |||||
| } | |||||
| /** | /** | ||||
| * Set this to 1 to activate the benchmark. It is disabled by default, because it prints a lot. | * Set this to 1 to activate the benchmark. It is disabled by default, because it prints a lot. | ||||
| */ | */ | ||||
| #if 0 | #if 0 | ||||
| template<typename MapT> | template<typename MapT> | ||||
| BLI_NOINLINE void benchmark_random_ints(StringRef name, int amount, int factor) | BLI_NOINLINE void benchmark_random_ints(StringRef name, int amount, int factor) | ||||
| { | { | ||||
| RNG *rng = BLI_rng_new(0); | RNG *rng = BLI_rng_new(0); | ||||
| ▲ Show 20 Lines • Show All 101 Lines • Show Last 20 Lines | |||||