From: Hans Fugal Date: Thu, 18 Jul 2013 00:40:41 +0000 (-0700) Subject: folly/Hash.h add a test to ensure different hashes X-Git-Tag: v0.22.0~923 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=8035fc11627f1739125066bee3951627adfce61e;p=folly.git 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 --- 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)); +}