| 33 | }; |
| 34 | |
| 35 | TEST_F(gorillas_test, test_gorillas) { |
| 36 | for (auto& dataset : alp_bench::get_alp_dataset()) { |
| 37 | std::ifstream ifile(dataset.csv_file_path, std::ios::in); |
| 38 | ASSERT_EQ(ifile.fail(), false); |
| 39 | |
| 40 | // Read Data |
| 41 | double num = 0.0; |
| 42 | // keep storing values from the text file so long as data exists: |
| 43 | size_t c {0}; |
| 44 | while (ifile >> num) { |
| 45 | dbl_arr[c] = num; |
| 46 | c = c + 1; |
| 47 | } |
| 48 | |
| 49 | // Init Encoding |
| 50 | state.Reset(); |
| 51 | state.output.SetStream(data_arr); |
| 52 | state.flag_buffer.SetBuffer(flags_arr); |
| 53 | |
| 54 | /* |
| 55 | * |
| 56 | * Encode |
| 57 | * |
| 58 | */ |
| 59 | uint64_p = reinterpret_cast<uint64_t*>(dbl_arr); |
| 60 | for (size_t i {0}; i < 1024; ++i) { |
| 61 | alp_bench::GorillasCompression<uint64_t, false>::Store(uint64_p[i], state); |
| 62 | } |
| 63 | |
| 64 | state.Flush(); |
| 65 | state.output.Flush(); |
| 66 | |
| 67 | // Init decoding |
| 68 | gorillas_de_state.input.SetStream(data_arr); |
| 69 | flag_buffer.SetBuffer(flags_arr); |
| 70 | |
| 71 | /* |
| 72 | * |
| 73 | * DECODE |
| 74 | * |
| 75 | */ |
| 76 | flags[0] = alp_bench::GorillasConstants::Flags::VALUE_IDENTICAL; // First value doesn't require a flag |
| 77 | for (idx_t i = 0; i < 1023; i++) { |
| 78 | flags[1 + i] = (alp_bench::GorillasConstants::Flags)flag_buffer.Extract(); |
| 79 | } |
| 80 | |
| 81 | for (idx_t i = 0; i < 1024; i++) { |
| 82 | dec_arr[i] = alp_bench::GorillasDecompression<uint64_t>::Load(flags[i], gorillas_de_state); |
| 83 | } |
| 84 | gorillas_de_state.Reset(); |
| 85 | |
| 86 | dec_dbl_p = reinterpret_cast<double*>(dec_arr); |
| 87 | |
| 88 | for (size_t i = 0; i < 1024; ++i) { |
| 89 | auto l = dbl_arr[i]; |
| 90 | auto r = dec_dbl_p[i]; |
| 91 | if (l != r) { std::cerr << l << ", " << r << dataset.name << "\n"; } |
| 92 | |