From 39a7dc7a2d498c0eb24335efb55a6f19eaa3599c Mon Sep 17 00:00:00 2001 From: "A.J. Beamon" Date: Wed, 26 Jan 2022 15:35:37 -0800 Subject: [PATCH] Add two unit tests for the new hashing functionality --- flow/Arena.cpp | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/flow/Arena.cpp b/flow/Arena.cpp index 77ea8f1055..ae4a0fb2ca 100644 --- a/flow/Arena.cpp +++ b/flow/Arena.cpp @@ -613,3 +613,40 @@ TEST_CASE("/flow/Arena/SmallVectorRef10") { testVectorLike(); return Void(); } + +TEST_CASE("/flow/Arena/OptionalHash") { + std::hash> hashFunc{}; + Optional a; + Optional b; + Optional c = 1; + Optional d = 1; + Optional e = 2; + + ASSERT(hashFunc(a) == hashFunc(b)); + ASSERT(hashFunc(a) != hashFunc(c)); + ASSERT(hashFunc(c) == hashFunc(d)); + ASSERT(hashFunc(c) != hashFunc(e)); + ASSERT(hashFunc(a) == hashFunc(a)); + ASSERT(hashFunc(c) == hashFunc(c)); + + return Void(); +} + +TEST_CASE("/flow/Arena/DefaultBoostHash") { + boost::hash, StringRef>> hashFunc; + + auto a = std::make_pair(Optional(), "foo"_sr); + auto b = std::make_pair(Optional(), "foo"_sr); + auto c = std::make_pair(Optional(), "bar"_sr); + auto d = std::make_pair(Optional(1), "foo"_sr); + auto e = std::make_pair(Optional(1), "foo"_sr); + + ASSERT(hashFunc(a) == hashFunc(b)); + ASSERT(hashFunc(a) != hashFunc(c)); + ASSERT(hashFunc(a) != hashFunc(d)); + ASSERT(hashFunc(d) == hashFunc(e)); + ASSERT(hashFunc(a) == hashFunc(a)); + ASSERT(hashFunc(d) == hashFunc(d)); + + return Void(); +} \ No newline at end of file