A version of ValidateRle that round-trips the values and returns false if the returned values are not all the same
| 691 | // A version of ValidateRle that round-trips the values and returns false if |
| 692 | // the returned values are not all the same |
| 693 | bool CheckRoundTrip(const std::vector<int>& values, int bit_width) { |
| 694 | const int len = 64 * 1024; |
| 695 | #ifdef __EMSCRIPTEN__ |
| 696 | // don't make this on the stack as it is |
| 697 | // too big for emscripten |
| 698 | std::vector<uint8_t> buffer_vec(static_cast<size_t>(len)); |
| 699 | uint8_t* buffer = buffer_vec.data(); |
| 700 | #else |
| 701 | uint8_t buffer[len]; |
| 702 | #endif |
| 703 | RleBitPackedEncoder encoder(buffer, len, bit_width); |
| 704 | for (size_t i = 0; i < values.size(); ++i) { |
| 705 | bool result = encoder.Put(values[i]); |
| 706 | if (!result) { |
| 707 | return false; |
| 708 | } |
| 709 | } |
| 710 | int encoded_len = encoder.Flush(); |
| 711 | int out = 0; |
| 712 | |
| 713 | { |
| 714 | RleBitPackedDecoder<int> decoder(buffer, encoded_len, bit_width); |
| 715 | for (size_t i = 0; i < values.size(); ++i) { |
| 716 | EXPECT_TRUE(decoder.Get(&out)); |
| 717 | if (values[i] != out) { |
| 718 | return false; |
| 719 | } |
| 720 | } |
| 721 | } |
| 722 | |
| 723 | // Verify batch read |
| 724 | { |
| 725 | RleBitPackedDecoder<int> decoder(buffer, encoded_len, bit_width); |
| 726 | std::vector<int> values_read(values.size()); |
| 727 | if (static_cast<int>(values.size()) != |
| 728 | decoder.GetBatch(values_read.data(), static_cast<int>(values.size()))) { |
| 729 | return false; |
| 730 | } |
| 731 | |
| 732 | if (values != values_read) { |
| 733 | return false; |
| 734 | } |
| 735 | } |
| 736 | |
| 737 | return true; |
| 738 | } |
| 739 | |
| 740 | TEST(RleBitPacked, SpecificSequences) { |
| 741 | const int len = 1024; |
no test coverage detected