diff --git a/tests/allocator_test.cc b/tests/allocator_test.cc index 2f8213b814..501e50a6c6 100644 --- a/tests/allocator_test.cc +++ b/tests/allocator_test.cc @@ -11,65 +11,65 @@ #include struct allocation { - size_t n; - std::unique_ptr data; - char poison; - allocation(size_t n, char poison) : n(n), data(new char[n]), poison(poison) { - std::fill_n(data.get(), n, poison); - } - ~allocation() { - verify(); - } - allocation(allocation&& x) noexcept = default; - void verify() { - if (data) { - assert(std::find_if(data.get(), data.get() + n, [this] (char c) { - return c != poison; - }) == data.get() + n); - } - } - allocation& operator=(allocation&& x) { - verify(); - if (this != &x) { - data = std::move(x.data); - n = x.n; - poison = x.poison; - } - return *this; - } + size_t n; + std::unique_ptr data; + char poison; + allocation(size_t n, char poison) : n(n), data(new char[n]), poison(poison) { + std::fill_n(data.get(), n, poison); + } + ~allocation() { + verify(); + } + allocation(allocation&& x) noexcept = default; + void verify() { + if (data) { + assert(std::find_if(data.get(), data.get() + n, [this] (char c) { + return c != poison; + }) == data.get() + n); + } + } + allocation& operator=(allocation&& x) { + verify(); + if (this != &x) { + data = std::move(x.data); + n = x.n; + poison = x.poison; + } + return *this; + } }; int main(int ac, char** av) { - std::default_random_engine random_engine; - std::exponential_distribution<> distr(0.2); - std::uniform_int_distribution<> type(0, 1); - std::uniform_int_distribution poison(-128, 127); - std::uniform_real_distribution<> which(0, 1); - std::vector allocations; - for (auto i = 0; i < 200000; ++i) { - auto typ = type(random_engine); - switch (typ) { - case 0: { - auto n = std::min(std::exp(distr(random_engine)), 1 << 25); - try { - allocations.emplace_back(n, poison(random_engine)); - } catch (std::bad_alloc&) { + std::default_random_engine random_engine; + std::exponential_distribution<> distr(0.2); + std::uniform_int_distribution<> type(0, 1); + std::uniform_int_distribution poison(-128, 127); + std::uniform_real_distribution<> which(0, 1); + std::vector allocations; + for (auto i = 0; i < 200000; ++i) { + auto typ = type(random_engine); + switch (typ) { + case 0: { + auto n = std::min(std::exp(distr(random_engine)), 1 << 25); + try { + allocations.emplace_back(n, poison(random_engine)); + } catch (std::bad_alloc&) { - } - break; - } - case 1: { - if (allocations.empty()) { - continue; - } - size_t i = which(random_engine) * allocations.size(); - allocations[i] = std::move(allocations.back()); - allocations.pop_back(); - break; - } - } - } - return 0; + } + break; + } + case 1: { + if (allocations.empty()) { + continue; + } + size_t i = which(random_engine) * allocations.size(); + allocations[i] = std::move(allocations.back()); + allocations.pop_back(); + break; + } + } + } + return 0; }