| 22 | #include "gandiva/hash_utils.h" |
| 23 | |
| 24 | TEST(TestShaHashUtils, TestSha1Numeric) { |
| 25 | gandiva::ExecutionContext ctx; |
| 26 | |
| 27 | auto ctx_ptr = reinterpret_cast<int64_t>(&ctx); |
| 28 | |
| 29 | std::vector<uint64_t> values_to_be_hashed; |
| 30 | |
| 31 | // Generate a list of values to obtains the SHA1 hash |
| 32 | values_to_be_hashed.push_back(gandiva::gdv_double_to_long(0.0)); |
| 33 | values_to_be_hashed.push_back(gandiva::gdv_double_to_long(0.1)); |
| 34 | values_to_be_hashed.push_back(gandiva::gdv_double_to_long(0.2)); |
| 35 | values_to_be_hashed.push_back(gandiva::gdv_double_to_long(-0.10000001)); |
| 36 | values_to_be_hashed.push_back(gandiva::gdv_double_to_long(-0.0000001)); |
| 37 | values_to_be_hashed.push_back(gandiva::gdv_double_to_long(1.000000)); |
| 38 | values_to_be_hashed.push_back(gandiva::gdv_double_to_long(-0.0000002)); |
| 39 | values_to_be_hashed.push_back(gandiva::gdv_double_to_long(0.999999)); |
| 40 | |
| 41 | // Checks if the hash value is different for each one of the values |
| 42 | std::unordered_set<std::string> sha_values; |
| 43 | |
| 44 | int sha1_size = 40; |
| 45 | |
| 46 | for (auto value : values_to_be_hashed) { |
| 47 | int out_length; |
| 48 | const char* sha_1 = |
| 49 | gandiva::gdv_sha1_hash(ctx_ptr, &value, sizeof(value), &out_length); |
| 50 | std::string sha1_as_str(sha_1, out_length); |
| 51 | EXPECT_EQ(sha1_as_str.size(), sha1_size); |
| 52 | |
| 53 | // The value cannot exists inside the set with the hash results |
| 54 | EXPECT_EQ(sha_values.find(sha1_as_str), sha_values.end()); |
| 55 | sha_values.insert(sha1_as_str); |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | TEST(TestShaHashUtils, TestSha512Numeric) { |
| 60 | gandiva::ExecutionContext ctx; |
nothing calls this directly
no test coverage detected