diff options
author | Alon Zakai <azakai@google.com> | 2022-09-28 16:01:58 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-28 23:01:58 +0000 |
commit | e74a63076b7c21bd45f5156fc028d41db8aa5eb0 (patch) | |
tree | b54ce00a756c2483226ce4429866a9c13d218976 /test/gtest/possible-contents.cpp | |
parent | e8915d2a0f8ab592d5da2d572c971a65b753c87c (diff) | |
download | binaryen-e74a63076b7c21bd45f5156fc028d41db8aa5eb0.tar.gz binaryen-e74a63076b7c21bd45f5156fc028d41db8aa5eb0.tar.bz2 binaryen-e74a63076b7c21bd45f5156fc028d41db8aa5eb0.zip |
[GUFA] Improve hashing (#5091)
Avoid manually doing bitshifts etc. - leave combining to the core hash
logic, which can do a better job.
Diffstat (limited to 'test/gtest/possible-contents.cpp')
-rw-r--r-- | test/gtest/possible-contents.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/test/gtest/possible-contents.cpp b/test/gtest/possible-contents.cpp index 933e220bb..0bb1ecafa 100644 --- a/test/gtest/possible-contents.cpp +++ b/test/gtest/possible-contents.cpp @@ -146,6 +146,28 @@ TEST_F(PossibleContentsTest, TestComparisons) { assertNotEqualSymmetric(exactNonNullAnyref, exactAnyref); } +TEST_F(PossibleContentsTest, TestHash) { + // Hashes should be deterministic. + EXPECT_EQ(none.hash(), none.hash()); + EXPECT_EQ(many.hash(), many.hash()); + + // Hashes should be different. (In theory hash collisions could appear here, + // but if such simple things collide and the test fails then we should really + // rethink our hash functions!) + EXPECT_NE(none.hash(), many.hash()); + EXPECT_NE(none.hash(), i32Zero.hash()); + EXPECT_NE(none.hash(), i32One.hash()); + EXPECT_NE(none.hash(), anyGlobal.hash()); + EXPECT_NE(none.hash(), funcGlobal.hash()); + EXPECT_NE(none.hash(), exactAnyref.hash()); + EXPECT_NE(none.hash(), exactFuncSignatureType.hash()); + // TODO: cones + + EXPECT_NE(i32Zero.hash(), i32One.hash()); + EXPECT_NE(anyGlobal.hash(), funcGlobal.hash()); + EXPECT_NE(exactAnyref.hash(), exactFuncSignatureType.hash()); +} + TEST_F(PossibleContentsTest, TestCombinations) { // None with anything else becomes the other thing. assertCombination(none, none, none); |