Enable bug workaround also for MSVC 2017.4
[folly.git] / folly / test / HashTest.cpp
index 070cf78f68ab27967cca065a7ff414bd776eca8c..759f9975984cc9bf6c01504253683a491d93f6fc 100644 (file)
@@ -19,6 +19,7 @@
 #include <folly/portability/GTest.h>
 #include <stdint.h>
 #include <unordered_map>
+#include <unordered_set>
 #include <utility>
 
 using namespace folly::hash;
@@ -129,7 +130,7 @@ void checkTWang(uint64_t r) {
   uint64_t result = twang_mix64(r);
   EXPECT_EQ(r, twang_unmix64(result));
 }
-}  // namespace
+} // namespace
 
 TEST(Hash, TWang_Unmix64) {
   // We'll try (1 << i), (1 << i) + 1, (1 << i) - 1
@@ -167,7 +168,7 @@ void checkJenkins(uint32_t r) {
   uint32_t result = jenkins_rev_mix32(r);
   EXPECT_EQ(r, jenkins_rev_unmix32(result));
 }
-}  // namespace
+} // namespace
 
 TEST(Hash, Jenkins_Rev_Unmix32) {
   // We'll try (1 << i), (1 << i) + 1, (1 << i) - 1
@@ -185,6 +186,37 @@ TEST(Hash, hasher) {
   EXPECT_EQ(get_default(m, 4), 5);
 }
 
+TEST(Hash, integral_types) {
+  // Basically just confirms that things compile ok.
+  std::unordered_set<size_t> hashes;
+  folly::Hash hasher;
+  hashes.insert(hasher((char)1));
+  hashes.insert(hasher((signed char)2));
+  hashes.insert(hasher((unsigned char)3));
+  hashes.insert(hasher((short)4));
+  hashes.insert(hasher((signed short)5));
+  hashes.insert(hasher((unsigned short)6));
+  hashes.insert(hasher((int)7));
+  hashes.insert(hasher((signed int)8));
+  hashes.insert(hasher((unsigned int)9));
+  hashes.insert(hasher((long)10));
+  hashes.insert(hasher((signed long)11));
+  hashes.insert(hasher((unsigned long)12));
+  hashes.insert(hasher((long long)13));
+  hashes.insert(hasher((signed long long)14));
+  hashes.insert(hasher((unsigned long long)15));
+  hashes.insert(hasher((int8_t)16));
+  hashes.insert(hasher((uint8_t)17));
+  hashes.insert(hasher((int16_t)18));
+  hashes.insert(hasher((uint16_t)19));
+  hashes.insert(hasher((int32_t)20));
+  hashes.insert(hasher((uint32_t)21));
+  hashes.insert(hasher((int64_t)22));
+  hashes.insert(hasher((uint64_t)23));
+  hashes.insert(hasher((size_t)24));
+  EXPECT_EQ(24, hashes.size());
+}
+
 // Not a full hasher since only handles one type
 class TestHasher {
  public: