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