pw_varint: Make the varint tests faster

Change-Id: Icb0e3590100d56e1e4a7bf039eb9affe188c4110
This commit is contained in:
Wyatt Hepler 2020-02-13 13:19:46 -08:00
parent 495b6ee5ce
commit 4681e15135

View File

@ -426,10 +426,11 @@ TEST_F(Varint, EncodeSizeSigned64_MultiByte_C) {
std::memcmp("\xfe\xff\xff\xff\xff\xff\xff\xff\xff\x01", buffer_, 10), 0); std::memcmp("\xfe\xff\xff\xff\xff\xff\xff\xff\xff\x01", buffer_, 10), 0);
} }
TEST_F(Varint, EncodeDecodeSigned32) { // How much to increment by for each iteration of the exhaustive encode/decode
// Set the increment to 1 to test every number (this is slow) // tests. Set the increment to 1 to test every number (this is slow).
static constexpr int kIncrement = 1'000'009; constexpr int kIncrement = 100'000'009;
TEST_F(Varint, EncodeDecodeSigned32) {
int32_t i = std::numeric_limits<int32_t>::min(); int32_t i = std::numeric_limits<int32_t>::min();
while (true) { while (true) {
size_t encoded = Encode(i, buffer_); size_t encoded = Encode(i, buffer_);
@ -449,9 +450,6 @@ TEST_F(Varint, EncodeDecodeSigned32) {
} }
TEST_F(Varint, EncodeDecodeSigned32_C) { TEST_F(Varint, EncodeDecodeSigned32_C) {
// Set the increment to 1 to test every number (this is slow)
static constexpr int kIncrement = 1'000'009;
int32_t i = std::numeric_limits<int32_t>::min(); int32_t i = std::numeric_limits<int32_t>::min();
while (true) { while (true) {
size_t encoded = pw_VarintCallZigZagEncode(i, buffer_, sizeof(buffer_)); size_t encoded = pw_VarintCallZigZagEncode(i, buffer_, sizeof(buffer_));
@ -472,9 +470,6 @@ TEST_F(Varint, EncodeDecodeSigned32_C) {
} }
TEST_F(Varint, EncodeDecodeUnsigned32) { TEST_F(Varint, EncodeDecodeUnsigned32) {
// Set the increment to 1 to test every number (this is slow)
static constexpr int kIncrement = 1'000'009;
uint32_t i = 0; uint32_t i = 0;
while (true) { while (true) {
size_t encoded = Encode(i, buffer_); size_t encoded = Encode(i, buffer_);
@ -494,9 +489,6 @@ TEST_F(Varint, EncodeDecodeUnsigned32) {
} }
TEST_F(Varint, EncodeDecodeUnsigned32_C) { TEST_F(Varint, EncodeDecodeUnsigned32_C) {
// Set the increment to 1 to test every number (this is slow)
static constexpr int kIncrement = 1'000'009;
uint32_t i = 0; uint32_t i = 0;
while (true) { while (true) {
size_t encoded = pw_VarintCallEncode(i, buffer_, sizeof(buffer_)); size_t encoded = pw_VarintCallEncode(i, buffer_, sizeof(buffer_));