Commit 8035fc11 authored by Hans Fugal's avatar Hans Fugal Committed by Sara Golemon

folly/Hash.h add a test to ensure different hashes

Summary:
"Wouldn't this test case still pass if the hash function didn't depend on the value?

It would be nice to verify that different tuple values produce different hash values (or maybe there's another test that verifies that), especially since this is a tricky thing to get right."

I think there's not much chance of this failing since it's just leveraging hash_combine and that's already tested. But it's easy to add another sanity check, so here we are.

Test Plan: runtests

Reviewed By: tulloch@fb.com

FB internal diff: D890448

Blame Revision: D888796
parent b71e31a5
......@@ -237,3 +237,15 @@ TEST(Hash, std_tuple) {
m[t] = "bar";
EXPECT_EQ("bar", m[t]);
}
TEST(Hash, std_tuple_different_hash) {
typedef std::tuple<int64_t, std::string, int32_t> tuple3;
tuple3 t1(42, "foo", 1);
tuple3 t2(9, "bar", 3);
tuple3 t3(42, "foo", 3);
EXPECT_NE(std::hash<tuple3>()(t1),
std::hash<tuple3>()(t2));
EXPECT_NE(std::hash<tuple3>()(t1),
std::hash<tuple3>()(t3));
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment