[llvm-commits] [llvm] r150890 - in /llvm/trunk: include/llvm/ADT/Hashing.h lib/Support/CMakeLists.txt lib/Support/Hashing.cpp unittests/ADT/HashingTest.cpp unittests/CMakeLists.txt
Bill Wendling
wendling at apple.com
Sun Feb 19 11:57:19 PST 2012
On Feb 18, 2012, at 1:00 PM, Talin wrote:
> Author: talin
> Date: Sat Feb 18 15:00:49 2012
> New Revision: 150890
>
> URL: http://llvm.org/viewvc/llvm-project?rev=150890&view=rev
> Log:
> Hashing.h - utilities for hashing various data types.
>
Yay!
> Added: llvm/trunk/unittests/ADT/HashingTest.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ADT/HashingTest.cpp?rev=150890&view=auto
> ==============================================================================
> --- llvm/trunk/unittests/ADT/HashingTest.cpp (added)
> +++ llvm/trunk/unittests/ADT/HashingTest.cpp Sat Feb 18 15:00:49 2012
> @@ -0,0 +1,57 @@
> +//===- llvm/unittest/ADT/HashingTest.cpp ----------------------------------===//
Could you add more tests, especially ones which add multiple items to the hash? As Chandler mentioned, there was a nasty bug (recently fixed) that would hopefully be caught by more testing...
-bw
> +//
> +// 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());
> +}
> +
> +}
>
> Modified: llvm/trunk/unittests/CMakeLists.txt
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/CMakeLists.txt?rev=150890&r1=150889&r2=150890&view=diff
> ==============================================================================
> --- llvm/trunk/unittests/CMakeLists.txt (original)
> +++ llvm/trunk/unittests/CMakeLists.txt Sat Feb 18 15:00:49 2012
> @@ -60,6 +60,7 @@
> ADT/DenseMapTest.cpp
> ADT/DenseSetTest.cpp
> ADT/FoldingSet.cpp
> + ADT/HashingTest.cpp
> ADT/ilistTest.cpp
> ADT/ImmutableSetTest.cpp
> ADT/IntEqClassesTest.cpp
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
More information about the llvm-commits
mailing list