From 8035fc11627f1739125066bee3951627adfce61e Mon Sep 17 00:00:00 2001 From: Hans Fugal Date: Wed, 17 Jul 2013 17:40:41 -0700 Subject: [PATCH] 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 --- folly/test/HashTest.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/folly/test/HashTest.cpp b/folly/test/HashTest.cpp index 6ed9a280..5b8840f5 100644 --- a/folly/test/HashTest.cpp +++ b/folly/test/HashTest.cpp @@ -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 tuple3; + tuple3 t1(42, "foo", 1); + tuple3 t2(9, "bar", 3); + tuple3 t3(42, "foo", 3); + + EXPECT_NE(std::hash()(t1), + std::hash()(t2)); + EXPECT_NE(std::hash()(t1), + std::hash()(t3)); +} -- 2.34.1