diff options
Diffstat (limited to 'Tools/TestWebKitAPI/Tests/WTF/HashMap.cpp')
-rw-r--r-- | Tools/TestWebKitAPI/Tests/WTF/HashMap.cpp | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/Tools/TestWebKitAPI/Tests/WTF/HashMap.cpp b/Tools/TestWebKitAPI/Tests/WTF/HashMap.cpp index b9f4c1fdd..db6ca814f 100644 --- a/Tools/TestWebKitAPI/Tests/WTF/HashMap.cpp +++ b/Tools/TestWebKitAPI/Tests/WTF/HashMap.cpp @@ -49,4 +49,36 @@ TEST(WTF, HashTableIteratorComparison) ASSERT_FALSE(map.end() == begin); } +struct TestDoubleHashTraits : HashTraits<double> { + static const int minimumTableSize = 8; +}; + +typedef HashMap<double, int64_t, DefaultHash<double>::Hash, TestDoubleHashTraits> DoubleHashMap; + +static int bucketForKey(double key) +{ + return DefaultHash<double>::Hash::hash(key) & (TestDoubleHashTraits::minimumTableSize - 1); +} + +TEST(WTF, DoubleHashCollisions) +{ + // The "clobber" key here is one that ends up stealing the bucket that the -0 key + // originally wants to be in. This makes the 0 and -0 keys collide and the test then + // fails unless the FloatHash::equals() implementation can distinguish them. + const double clobberKey = 6; + const double zeroKey = 0; + const double negativeZeroKey = -zeroKey; + + DoubleHashMap map; + + map.add(clobberKey, 1); + map.add(zeroKey, 2); + map.add(negativeZeroKey, 3); + + ASSERT_EQ(bucketForKey(clobberKey), bucketForKey(negativeZeroKey)); + ASSERT_EQ(map.get(clobberKey), 1); + ASSERT_EQ(map.get(zeroKey), 2); + ASSERT_EQ(map.get(negativeZeroKey), 3); +} + } // namespace TestWebKitAPI |