diff options
author | David Malcolm <dmalcolm@redhat.com> | 2019-12-19 15:01:49 +0000 |
---|---|---|
committer | David Malcolm <dmalcolm@gcc.gnu.org> | 2019-12-19 15:01:49 +0000 |
commit | aa0e90e7bff935856212b64236cd540acccc66a0 (patch) | |
tree | 801ab8174fc8ac7da6326dc361cf2b41c93f0ab9 /gcc/hash-map-tests.c | |
parent | 0e7b6a51df1f5ffa81bebbe492ce1418c9fdceab (diff) | |
download | gcc-aa0e90e7bff935856212b64236cd540acccc66a0.zip gcc-aa0e90e7bff935856212b64236cd540acccc66a0.tar.gz gcc-aa0e90e7bff935856212b64236cd540acccc66a0.tar.bz2 |
hash-map-tests.c: add a selftest involving int_hash
gcc/ChangeLog:
* hash-map-tests.c (selftest::test_map_of_int_to_strings): New
selftest.
(selftest::hash_map_tests_c_tests): Call it.
From-SVN: r279582
Diffstat (limited to 'gcc/hash-map-tests.c')
-rw-r--r-- | gcc/hash-map-tests.c | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/gcc/hash-map-tests.c b/gcc/hash-map-tests.c index a42eac2..9a13a80 100644 --- a/gcc/hash-map-tests.c +++ b/gcc/hash-map-tests.c @@ -103,6 +103,46 @@ test_map_of_strings_to_int () ASSERT_EQ (1, string_map.elements ()); } +/* Construct a hash_map using int_hash and verify that + various operations work correctly. */ + +static void +test_map_of_int_to_strings () +{ + const int EMPTY = -1; + const int DELETED = -2; + typedef int_hash <int, EMPTY, DELETED> int_hash_t; + hash_map <int_hash_t, const char *> m; + + const char *ostrich = "ostrich"; + const char *elephant = "elephant"; + const char *ant = "ant"; + const char *spider = "spider"; + const char *millipede = "Illacme plenipes"; + const char *eric = "half a bee"; + + /* A fresh hash_map should be empty. */ + ASSERT_EQ (0, m.elements ()); + ASSERT_EQ (NULL, m.get (2)); + + /* Populate the hash_map. */ + ASSERT_EQ (false, m.put (2, ostrich)); + ASSERT_EQ (false, m.put (4, elephant)); + ASSERT_EQ (false, m.put (6, ant)); + ASSERT_EQ (false, m.put (8, spider)); + ASSERT_EQ (false, m.put (750, millipede)); + ASSERT_EQ (false, m.put (3, eric)); + + /* Verify that we can recover the stored values. */ + ASSERT_EQ (6, m.elements ()); + ASSERT_EQ (*m.get (2), ostrich); + ASSERT_EQ (*m.get (4), elephant); + ASSERT_EQ (*m.get (6), ant); + ASSERT_EQ (*m.get (8), spider); + ASSERT_EQ (*m.get (750), millipede); + ASSERT_EQ (*m.get (3), eric); +} + typedef class hash_map_test_val_t { public: @@ -244,6 +284,7 @@ void hash_map_tests_c_tests () { test_map_of_strings_to_int (); + test_map_of_int_to_strings (); test_map_of_type_with_ctor_and_dtor (); } |