aboutsummaryrefslogtreecommitdiffstats
path: root/unittests/ADT
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/ADT
parentb155c23f98e45bf5a1f5e6329b46e8138dfef9ce (diff)
downloadexternal_llvm-1a4b19ef9b870d8c914bcd5ceb520a64a9a2cc52.zip
external_llvm-1a4b19ef9b870d8c914bcd5ceb520a64a9a2cc52.tar.gz
external_llvm-1a4b19ef9b870d8c914bcd5ceb520a64a9a2cc52.tar.bz2
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/ADT')
-rw-r--r--unittests/ADT/HashingTest.cpp57
1 files changed, 57 insertions, 0 deletions
diff --git a/unittests/ADT/HashingTest.cpp b/unittests/ADT/HashingTest.cpp
new file mode 100644
index 0000000..18bfb72
--- /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());
+}
+
+}