Teuchos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Hashtable_UnitTests.cpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Teuchos: Common Tools Package
4 //
5 // Copyright 2004 NTESS and the Teuchos contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
11 #include "Teuchos_as.hpp"
12 #include "Teuchos_Hashtable.hpp"
13 
14 
15 namespace {
16 
17 
18 TEUCHOS_UNIT_TEST_TEMPLATE_2_DECL( Hashtable, test0, Key, Value )
19 {
20  using Teuchos::as;
21 
23 
24  hashtable.put(as<Key>(1), as<Value>(1));
25  hashtable.put(as<Key>(3), as<Value>(9));
26  hashtable.put(as<Key>(5), as<Value>(7));
27 
28  TEST_EQUALITY( hashtable.size(), 3 );
29 
30  TEST_EQUALITY( hashtable.containsKey(as<Key>(3)), true );
31  TEST_EQUALITY( hashtable.containsKey(as<Key>(4)), false );
32 
33  TEST_EQUALITY( hashtable.get(as<Key>(5)), as<Value>(7) );
34 }
35 
36 //
37 // Instantiations
38 //
39 
40 
41 #define UNIT_TEST_GROUP( K, V ) \
42  TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( Hashtable, test0, K, V )
43 
44 UNIT_TEST_GROUP(int, int)
45 UNIT_TEST_GROUP(int, float)
46 
47 } // namespace
Templated hashtable class.
#define TEST_EQUALITY(v1, v2)
Assert the equality of v1 and v2.
#define UNIT_TEST_GROUP(K, V)
#define TEUCHOS_UNIT_TEST_TEMPLATE_2_DECL(TEST_GROUP, TEST_NAME, TYPE1, TYPE2)
Macro for defining a templated unit test with two template parameters.
Templated hashtable class.
Unit testing support.
bool containsKey(const Key &key) const
Check for the presence of a key.
TypeTo as(const TypeFrom &t)
Convert from one value type to another.
void put(const Key &key, const Value &value)
Put a new (key, value) pair in the table.
const Value & get(const Key &key) const
Get the value indexed by key.
Definition of Teuchos::as, for conversions between types.
int size() const
Get the number of elements in the table.