summaryrefslogtreecommitdiff
path: root/unittests
diff options
context:
space:
mode:
authorTalin <viridia@gmail.com>2012-02-18 21:00:49 +0000
committerTalin <viridia@gmail.com>2012-02-18 21:00:49 +0000
commit1a4b19ef9b870d8c914bcd5ceb520a64a9a2cc52 (patch)
tree1565245621888b72e8961943ec306b4cecf78a7e /unittests
parentb155c23f98e45bf5a1f5e6329b46e8138dfef9ce (diff)
Hashing.h - utilities for hashing various data types.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@150890 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests')
-rw-r--r--unittests/ADT/HashingTest.cpp57
-rw-r--r--unittests/CMakeLists.txt1
2 files changed, 58 insertions, 0 deletions
diff --git a/unittests/ADT/HashingTest.cpp b/unittests/ADT/HashingTest.cpp
new file mode 100644
index 0000000000..18bfb722f4
--- /dev/null
+++ b/unittests/ADT/HashingTest.cpp
@@ -0,0 +1,57 @@
+//===- llvm/unittest/ADT/HashingTest.cpp ----------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// Hashing.h unit tests.
+//
+//===----------------------------------------------------------------------===//
+
+#include "gtest/gtest.h"
+#include "llvm/ADT/Hashing.h"
+
+using namespace llvm;
+
+namespace {
+
+TEST(HashingTest, EmptyHashTest) {
+ GeneralHash Hash;
+ ASSERT_EQ(0u, Hash.finish());
+}
+
+TEST(HashingTest, IntegerHashTest) {
+ ASSERT_TRUE(GeneralHash().add(1).finish() == GeneralHash().add(1).finish());
+ ASSERT_TRUE(GeneralHash().add(1).finish() != GeneralHash().add(2).finish());
+}
+
+TEST(HashingTest, StringHashTest) {
+ ASSERT_TRUE(
+ GeneralHash().add("abc").finish() == GeneralHash().add("abc").finish());
+ ASSERT_TRUE(
+ GeneralHash().add("abc").finish() != GeneralHash().add("abcd").finish());
+}
+
+TEST(HashingTest, FloatHashTest) {
+ ASSERT_TRUE(
+ GeneralHash().add(1.0f).finish() == GeneralHash().add(1.0f).finish());
+ ASSERT_TRUE(
+ GeneralHash().add(1.0f).finish() != GeneralHash().add(2.0f).finish());
+}
+
+TEST(HashingTest, DoubleHashTest) {
+ ASSERT_TRUE(GeneralHash().add(1.).finish() == GeneralHash().add(1.).finish());
+ ASSERT_TRUE(GeneralHash().add(1.).finish() != GeneralHash().add(2.).finish());
+}
+
+TEST(HashingTest, IntegerArrayHashTest) {
+ int a[] = { 1, 2 };
+ int b[] = { 1, 3 };
+ ASSERT_TRUE(GeneralHash().add(a).finish() == GeneralHash().add(a).finish());
+ ASSERT_TRUE(GeneralHash().add(a).finish() != GeneralHash().add(b).finish());
+}
+
+}
diff --git a/unittests/CMakeLists.txt b/unittests/CMakeLists.txt
index 977efd790b..8420cd4e10 100644
--- a/unittests/CMakeLists.txt
+++ b/unittests/CMakeLists.txt
@@ -60,6 +60,7 @@ add_llvm_unittest(ADT
ADT/DenseMapTest.cpp
ADT/DenseSetTest.cpp
ADT/FoldingSet.cpp
+ ADT/HashingTest.cpp
ADT/ilistTest.cpp
ADT/ImmutableSetTest.cpp
ADT/IntEqClassesTest.cpp