Changes after review feedback
@@ -331,29 +331,33 @@ TEST("test move assignment")
struct UnreserveFixture {
Array<int> arr;
- UnreserveFixture() : arr(1025, 7, alloc::Alloc::allocMMap(0))
+ UnreserveFixture() : arr(page_ints() + 1, 7, alloc::Alloc::allocMMap(0))
{
- EXPECT_EQUAL(1025u, arr.size());
- EXPECT_EQUAL(round_up_to_page_size(1) == 64_Ki ? 16_Ki : 2_Ki, arr.capacity());
+ EXPECT_EQUAL(page_ints() + 1, arr.size());
+ EXPECT_EQUAL(2 * page_ints(), arr.capacity());
+ }
+
+ static size_t page_ints() {
+ return round_up_to_page_size(1) / sizeof(int);
}
};
TEST_F("require that try_unreserve() fails if wanted capacity >= current capacity", UnreserveFixture)
{
- EXPECT_FALSE(f.arr.try_unreserve(32_Ki));
+ EXPECT_FALSE(f.arr.try_unreserve(2 * UnreserveFixture::page_ints()));
}
TEST_F("require that try_unreserve() fails if wanted capacity < current size", UnreserveFixture)
{
- EXPECT_FALSE(f.arr.try_unreserve(1_Ki));
+ EXPECT_FALSE(f.arr.try_unreserve(UnreserveFixture::page_ints()));
}
TEST_F("require that try_unreserve() succeedes if mmap can be shrinked", UnreserveFixture)
{
int *oldPtr = &f.arr[0];
f.arr.resize(512);
- EXPECT_TRUE(f.arr.try_unreserve(1023));
- EXPECT_EQUAL(round_up_to_page_size(1) == 64_Ki ? 16_Ki : 1_Ki, f.arr.capacity());
+ EXPECT_TRUE(f.arr.try_unreserve(UnreserveFixture::page_ints() - 1));
+ EXPECT_EQUAL(UnreserveFixture::page_ints(), f.arr.capacity());
int *newPtr = &f.arr[0];
EXPECT_EQUAL(oldPtr, newPtr);
}
