Skip to content

Commit 4d020fb

Browse files
authored
Merge pull request #5882 from hjmjohnson/convert-itkhashtabletest-to-itkhashtablegtest
ENH: Convert itkHashTableTest to itkHashTableGTest
2 parents faae8a2 + 0b7842f commit 4d020fb

2 files changed

Lines changed: 14 additions & 13 deletions

File tree

Modules/Core/Common/test/CMakeLists.txt

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ set(
7474
itkSparseFieldLayerTest.cxx
7575
itkDataObjectTest.cxx
7676
itkAtanRegularizedHeavisideStepFunctionTest1.cxx
77-
itkHashTableTest.cxx
7877
itkHeavisideStepFunctionTest1.cxx
7978
itkSinRegularizedHeavisideStepFunctionTest1.cxx
8079
itkPixelAccessTest.cxx
@@ -772,12 +771,6 @@ itk_add_test(
772771
ITKCommon1TestDriver
773772
itkAtanRegularizedHeavisideStepFunctionTest1
774773
)
775-
itk_add_test(
776-
NAME itkHashTableTest
777-
COMMAND
778-
ITKCommon1TestDriver
779-
itkHashTableTest
780-
)
781774
itk_add_test(
782775
NAME itkHeavisideStepFunctionTest1
783776
COMMAND
@@ -1736,6 +1729,7 @@ set(
17361729
itkBresenhamLineGTest.cxx
17371730
itkFilterDispatchGTest.cxx
17381731
itkThreadedIndexedContainerPartitionerGTest.cxx
1732+
itkHashTableGTest.cxx
17391733
)
17401734
creategoogletestdriver(ITKCommon "${ITKCommon-Test_LIBRARIES}" "${ITKCommonGTests}")
17411735
# If `-static` was passed to CMAKE_EXE_LINKER_FLAGS, compilation fails. No need to

Modules/Core/Common/test/itkHashTableTest.cxx renamed to Modules/Core/Common/test/itkHashTableGTest.cxx

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
*
1717
*=========================================================================*/
1818

19+
#include "itkGTest.h"
20+
1921
#include <unordered_set>
2022
#include <unordered_map>
2123
#include <iostream>
@@ -51,8 +53,7 @@ println(const char * s)
5153
std::cout << std::endl << s << std::endl;
5254
}
5355

54-
int
55-
itkHashTableTest(int, char *[])
56+
TEST(HashTable, StdHash)
5657
{
5758
println("Testing std::hash");
5859
constexpr std::hash<const char *> H;
@@ -64,7 +65,10 @@ itkHashTableTest(int, char *[])
6465
constexpr std::hash<char> H2;
6566
std::cout << "a -> " << H2('a') << std::endl;
6667
std::cout << "Z -> " << H2('Z') << std::endl;
68+
}
6769

70+
TEST(HashTable, UnorderedSet)
71+
{
6872
println("Testing std::unordered_set");
6973
using HashSetType = std::unordered_set<const char *, std::hash<const char *>, eqstr>;
7074
HashSetType Set;
@@ -76,8 +80,11 @@ itkHashTableTest(int, char *[])
7680
Set.insert("banana");
7781

7882
lookup(Set, "mango");
83+
EXPECT_GT(Set.count("mango"), 0u);
7984
lookup(Set, "apple");
85+
EXPECT_GT(Set.count("apple"), 0u);
8086
lookup(Set, "durian");
87+
EXPECT_EQ(Set.count("durian"), 0u);
8188

8289
// CppCheck gives us a warning if the return value isn't used.
8390
// This is to prevent the user from calling empty() when they mean clear().
@@ -89,7 +96,11 @@ itkHashTableTest(int, char *[])
8996
Set.insert("the horror");
9097
auto hsh_it = Set.begin();
9198
const HashSetType SetCopy = Set;
99+
IgnoreUnusedVariable(hsh_it);
100+
}
92101

102+
TEST(HashTable, UnorderedMap)
103+
{
93104
println("Testing std::unordered_map");
94105
using HashMapType = std::unordered_map<const char *, int, std::hash<const char *>, eqstr>;
95106

@@ -123,9 +134,5 @@ itkHashTableTest(int, char *[])
123134
months.insert(p);
124135
auto map_it = months.begin();
125136
const HashMapType MapCopy = months;
126-
127-
IgnoreUnusedVariable(hsh_it);
128137
IgnoreUnusedVariable(map_it);
129-
130-
return EXIT_SUCCESS;
131138
}

0 commit comments

Comments
 (0)