A version of ValidateRle that round-trips the values and returns false if the returned values are not all the same
| 717 | // A version of ValidateRle that round-trips the values and returns false if |
| 718 | // the returned values are not all the same |
| 719 | bool CheckRoundTrip(const std::vector<int>& values, int bit_width) { |
| 720 | const int len = 64 * 1024; |
| 721 | #ifdef __EMSCRIPTEN__ |
| 722 | // don't make this on the stack as it is |
| 723 | // too big for emscripten |
| 724 | std::vector<uint8_t> buffer_vec(static_cast<size_t>(len)); |
| 725 | uint8_t* buffer = buffer_vec.data(); |
| 726 | #else |
| 727 | uint8_t buffer[len]; |
| 728 | #endif |
| 729 | RleBitPackedEncoder encoder(buffer, len, bit_width); |
| 730 | for (size_t i = 0; i < values.size(); ++i) { |
| 731 | bool result = encoder.Put(values[i]); |
| 732 | if (!result) { |
| 733 | return false; |
| 734 | } |
| 735 | } |
| 736 | int encoded_len = encoder.Flush(); |
| 737 | int out = 0; |
| 738 | |
| 739 | { |
| 740 | RleBitPackedDecoder<int> decoder(buffer, encoded_len, bit_width); |
| 741 | for (size_t i = 0; i < values.size(); ++i) { |
| 742 | EXPECT_TRUE(decoder.Get(&out)); |
| 743 | if (values[i] != out) { |
| 744 | return false; |
| 745 | } |
| 746 | } |
| 747 | } |
| 748 | |
| 749 | // Verify batch read |
| 750 | { |
| 751 | RleBitPackedDecoder<int> decoder(buffer, encoded_len, bit_width); |
| 752 | std::vector<int> values_read(values.size()); |
| 753 | if (static_cast<int>(values.size()) != |
| 754 | decoder.GetBatch(values_read.data(), static_cast<int>(values.size()))) { |
| 755 | return false; |
| 756 | } |
| 757 | |
| 758 | if (values != values_read) { |
| 759 | return false; |
| 760 | } |
| 761 | } |
| 762 | |
| 763 | return true; |
| 764 | } |
| 765 | |
| 766 | TEST(RleBitPacked, SpecificSequences) { |
| 767 | const int len = 1024; |
no test coverage detected