Commit 73044d85 authored by Nathan Bronson's avatar Nathan Bronson Committed by Facebook Github Bot

use conditional compilation rather than skip for unsupported tests

Reviewed By: mengz0

Differential Revision: D13580163

fbshipit-source-id: 195e3007c6cbf4bf7281435c48a9b6f6c6eada5b
parent 19febc92
......@@ -23,7 +23,6 @@
#include <folly/FBString.h>
#include <folly/container/test/F14TestUtil.h>
#include <folly/portability/GTest.h>
#include <folly/test/TestUtils.h>
template <template <typename, typename, typename, typename, typename>
class TMap>
......@@ -127,90 +126,6 @@ TEST(F14Map, getAllocatedMemorySize) {
runAllocatedMemorySizeTests<folly::fbstring, long>();
}
template <typename M>
void runContinuousCapacityTest(std::size_t minSize, std::size_t maxSize) {
SKIP_IF(
folly::f14::detail::getF14IntrinsicsMode() ==
folly::f14::detail::F14IntrinsicsMode::None);
using K = typename M::key_type;
for (std::size_t n = minSize; n <= maxSize; ++n) {
M m1;
m1.reserve(n);
auto cap = m1.bucket_count();
double ratio = cap * 1.0 / n;
// worst case scenario is that rehash just occurred and capacityScale
// is 5*2^12
EXPECT_TRUE(ratio < 1 + 1.0 / (5 << 12))
<< ratio << ", " << cap << ", " << n;
m1[0];
M m2;
m2 = m1;
EXPECT_LE(m2.bucket_count(), 2);
for (K i = 1; i < n; ++i) {
m1[i];
}
EXPECT_EQ(m1.bucket_count(), cap);
M m3 = m1;
EXPECT_EQ(m3.bucket_count(), cap);
for (K i = n; i <= cap; ++i) {
m1[i];
}
EXPECT_GT(m1.bucket_count(), cap);
EXPECT_LE(m1.bucket_count(), 3 * cap);
M m4;
for (K i = 0; i < n; ++i) {
m4[i];
}
// reserve(0) works like shrink_to_fit. Note that tight fit (1/8
// waste bound) only applies for vector policy or single-chunk, which
// might not apply to m1. m3 should already have been optimally sized.
m1.reserve(0);
m3.reserve(0);
m4.reserve(0);
EXPECT_GT(m1.load_factor(), 0.5);
EXPECT_GE(m3.load_factor(), 0.875);
EXPECT_EQ(m3.bucket_count(), cap);
EXPECT_GE(m4.load_factor(), 0.875);
}
}
TEST(F14Map, continuousCapacitySmall) {
runContinuousCapacityTest<folly::F14NodeMap<std::size_t, std::string>>(1, 14);
runContinuousCapacityTest<folly::F14ValueMap<std::size_t, std::string>>(
1, 14);
runContinuousCapacityTest<folly::F14VectorMap<std::size_t, std::string>>(
1, 100);
runContinuousCapacityTest<folly::F14FastMap<std::size_t, std::string>>(
1, 100);
}
TEST(F14Map, continuousCapacityBig0) {
runContinuousCapacityTest<folly::F14VectorMap<std::size_t, std::string>>(
1000000 - 1, 1000000 - 1);
}
TEST(F14Map, continuousCapacityBig1) {
runContinuousCapacityTest<folly::F14VectorMap<std::size_t, std::string>>(
1000000, 1000000);
}
TEST(F14Map, continuousCapacityBig2) {
runContinuousCapacityTest<folly::F14VectorMap<std::size_t, std::string>>(
1000000 + 1, 1000000 + 1);
}
TEST(F14Map, continuousCapacityBig3) {
runContinuousCapacityTest<folly::F14VectorMap<std::size_t, std::string>>(
1000000 + 2, 1000000 + 2);
}
TEST(F14Map, continuousCapacityF12) {
runContinuousCapacityTest<folly::F14VectorMap<uint16_t, uint16_t>>(
0xfff0, 0xfffe);
}
template <typename M>
void runVisitContiguousRangesTest(int n) {
M map;
......@@ -1700,6 +1615,86 @@ TEST(F14Map, randomInsertOrder) {
runRandomInsertOrderTest<F14FastMap<char, std::string>>();
}
template <typename M>
void runContinuousCapacityTest(std::size_t minSize, std::size_t maxSize) {
using K = typename M::key_type;
for (std::size_t n = minSize; n <= maxSize; ++n) {
M m1;
m1.reserve(n);
auto cap = m1.bucket_count();
double ratio = cap * 1.0 / n;
// worst case scenario is that rehash just occurred and capacityScale
// is 5*2^12
EXPECT_TRUE(ratio < 1 + 1.0 / (5 << 12))
<< ratio << ", " << cap << ", " << n;
m1[0];
M m2;
m2 = m1;
EXPECT_LE(m2.bucket_count(), 2);
for (K i = 1; i < n; ++i) {
m1[i];
}
EXPECT_EQ(m1.bucket_count(), cap);
M m3 = m1;
EXPECT_EQ(m3.bucket_count(), cap);
for (K i = n; i <= cap; ++i) {
m1[i];
}
EXPECT_GT(m1.bucket_count(), cap);
EXPECT_LE(m1.bucket_count(), 3 * cap);
M m4;
for (K i = 0; i < n; ++i) {
m4[i];
}
// reserve(0) works like shrink_to_fit. Note that tight fit (1/8
// waste bound) only applies for vector policy or single-chunk, which
// might not apply to m1. m3 should already have been optimally sized.
m1.reserve(0);
m3.reserve(0);
m4.reserve(0);
EXPECT_GT(m1.load_factor(), 0.5);
EXPECT_GE(m3.load_factor(), 0.875);
EXPECT_EQ(m3.bucket_count(), cap);
EXPECT_GE(m4.load_factor(), 0.875);
}
}
TEST(F14Map, continuousCapacitySmall) {
runContinuousCapacityTest<folly::F14NodeMap<std::size_t, std::string>>(1, 14);
runContinuousCapacityTest<folly::F14ValueMap<std::size_t, std::string>>(
1, 14);
runContinuousCapacityTest<folly::F14VectorMap<std::size_t, std::string>>(
1, 100);
runContinuousCapacityTest<folly::F14FastMap<std::size_t, std::string>>(
1, 100);
}
TEST(F14Map, continuousCapacityBig0) {
runContinuousCapacityTest<folly::F14VectorMap<std::size_t, std::string>>(
1000000 - 1, 1000000 - 1);
}
TEST(F14Map, continuousCapacityBig1) {
runContinuousCapacityTest<folly::F14VectorMap<std::size_t, std::string>>(
1000000, 1000000);
}
TEST(F14Map, continuousCapacityBig2) {
runContinuousCapacityTest<folly::F14VectorMap<std::size_t, std::string>>(
1000000 + 1, 1000000 + 1);
}
TEST(F14Map, continuousCapacityBig3) {
runContinuousCapacityTest<folly::F14VectorMap<std::size_t, std::string>>(
1000000 + 2, 1000000 + 2);
}
TEST(F14Map, continuousCapacityF12) {
runContinuousCapacityTest<folly::F14VectorMap<uint16_t, uint16_t>>(
0xfff0, 0xfffe);
}
///////////////////////////////////
#endif // FOLLY_F14_VECTOR_INTRINSICS_AVAILABLE
///////////////////////////////////
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment