42#include <gtest/gtest.h>
57 struct DynArrayHeapWithoutMemory :
public ::testing::Test
62 GTEST_SKIP() <<
"ThreadSanitizer replaces the global operator new";
69 std::string item(
const size_t k)
71 return std::string(40,
'x') + std::to_string(
k);
75 std::vector<std::string> layout(
const Heap &
h)
77 std::vector<std::string>
out;
78 h.traverse([&
out](
const std::string & s) {
out.push_back(s);
return true; });
86 size_t allocations_as_it_was(
const size_t n, Add add)
88 for (
size_t k = 1; ; ++
k)
90 SCOPED_TRACE(testing::Message() <<
"size " << n <<
", allocation " <<
k);
92 for (
size_t i = 1; i <= n; ++i)
94 const std::vector<std::string> before = layout(heap);
95 std::string key = item(0);
104 catch (
const std::bad_alloc &)
112 EXPECT_EQ(heap.size(), n + 1);
115 EXPECT_EQ(heap.size(), n);
116 EXPECT_EQ(layout(heap), before);
117 EXPECT_EQ(key, item(0));
119 EXPECT_EQ(heap.size(), n + 1);
120 EXPECT_EQ(heap.top(), item(0));
129 void expect_as_it_was(Add add)
131 size_t in_the_block = 0;
132 for (
size_t n = 0; n <= 70; ++n)
133 in_the_block = allocations_as_it_was(n, add);
136 ASSERT_GT(block_size, 71U);
137 EXPECT_GT(allocations_as_it_was(block_size - 1, add), in_the_block);
141TEST_F(DynArrayHeapWithoutMemory, InsertOfACopyLeavesTheHeapAsItWas)
143 expect_as_it_was([](Heap &
h, std::string & key) {
h.insert(key); });
146TEST_F(DynArrayHeapWithoutMemory, InsertOfAMoveLeavesTheHeapAsItWas)
148 expect_as_it_was([](Heap &
h, std::string & key) {
h.insert(std::move(key)); });
A global operator new that a test can make fail.
#define ALEPH_ALLOCATION_FAILURE_UNDER_TSAN
size_t size_t int32_t * out
Dynamic heap (priority queue) backed by DynArray.
size_t get_block_size() const noexcept
Return the block size.
TEST_F(DynArrayHeapWithoutMemory, InsertOfACopyLeavesTheHeapAsItWas)
Main namespace for Aleph-w library functions.
double add(double a, double b)
Array-based dynamic binary heap.