libMesh
vectormap_test.C
Go to the documentation of this file.
1 #include "libmesh/vectormap.h"
2 
3 #include "libmesh_cppunit.h"
4 
5 
6 #define VECTORMAPOBJECTTEST \
7  CPPUNIT_TEST( testCreate ); \
8 
9 using namespace libMesh;
10 
11 class VectormapTest : public CppUnit::TestCase
12 {
13 public:
14  CPPUNIT_TEST_SUITE ( VectormapTest );
15 
16  CPPUNIT_TEST( testCreate );
17  CPPUNIT_TEST( testInsert );
18  CPPUNIT_TEST( testIterate );
19  CPPUNIT_TEST( testFind );
20 
21  CPPUNIT_TEST_SUITE_END();
22 
23 private:
24 
25  template <typename Key, typename Val>
26  void create()
27  {
29  }
30 
31  template <typename Key, typename Val>
32  void insert()
33  {
35 
36  Val val(0); // requires default constructor for val type.
37 
38  for (Key key=1; key<32; key*=2)
39  vm.insert (std::make_pair(key,val));
40 
41  vm.sort();
42  }
43 
44  template <typename Key, typename Val>
45  void iterate(const Val &default_value=0)
46  {
48 
49  Val val(default_value); // requires default constructor for val type.
50 
51  for (Key key=1; key<32; key*=2)
52  vm.insert (std::make_pair(key,val));
53 
54  vm.sort();
55 
56  for (typename vectormap<Key,Val>::const_iterator it=vm.begin();
57  it != vm.end(); ++it)
58  {
59  const Key &ikey = it->first;
60  const Val &ival = it->second;
61 
62  CPPUNIT_ASSERT ( vm.count(ikey) == 1 );
63  CPPUNIT_ASSERT_EQUAL (vm[ikey], ival);
64  CPPUNIT_ASSERT_EQUAL (ival, val);
65  }
66  }
67 
68 public:
69 
70  // virtual void setUp()
71  // {}
72 
73  // virtual void tearDown()
74  // {}
75 
76 
77  void testCreate()
78  {
79  create<int, int> ();
80  create<int*,int> ();
81  create<int*,int*>();
82  create<int, std::vector<int>>();
83  }
84 
85  void testInsert()
86  {
87  insert<int, int> ();
88  insert<char,int> ();
89  insert<long,int*>();
90  insert<int, std::vector<int>>();
91  }
92 
93  void testIterate()
94  {
95  iterate<int, int> ();
96  iterate<char,int> ();
97  iterate<long,int*>();
98  iterate<int, std::string>("test_string");
99  }
100 
101  void testFind()
102  {
104  for (int i=16; i<32; ++i)
105  vm.insert(std::make_pair(i,i));
106 
108  it1 = vm.find(24),
109  it2 = vm.find(4);
110 
111  CPPUNIT_ASSERT(it1 != vm.end());
112  CPPUNIT_ASSERT(it2 == vm.end());
113  CPPUNIT_ASSERT(vm.count(24) == 1);
114  CPPUNIT_ASSERT(vm.count(4) == 0);
115  }
116 };
117 
VectormapTest::testFind
void testFind()
Definition: vectormap_test.C:101
libMesh::vectormap
This vectormap templated class is intended to provide the performance characteristics of a sorted std...
Definition: vectormap.h:61
libMesh::vectormap::const_iterator
vector_type::const_iterator const_iterator
Definition: vectormap.h:72
libMesh
The libMesh namespace provides an interface to certain functionality in the library.
Definition: factoryfunction.C:55
VectormapTest
Definition: vectormap_test.C:11
VectormapTest::insert
void insert()
Definition: vectormap_test.C:32
VectormapTest::testIterate
void testIterate()
Definition: vectormap_test.C:93
libMesh::vectormap::count
difference_type count(const key_type &key) const
Definition: vectormap.h:210
VectormapTest::testCreate
void testCreate()
Definition: vectormap_test.C:77
CPPUNIT_TEST_SUITE_REGISTRATION
CPPUNIT_TEST_SUITE_REGISTRATION(VectormapTest)
libMesh::vectormap::find
iterator find(const key_type &key)
Definition: vectormap.h:160
libMesh::vectormap::iterator
vector_type::iterator iterator
Definition: vectormap.h:71
libMesh::vectormap::insert
void insert(const value_type &x)
Inserts x into the vectormap.
Definition: vectormap.h:116
VectormapTest::create
void create()
Definition: vectormap_test.C:26
libMesh::vectormap::sort
void sort()
Sort & unique the vectormap, preparing for use.
Definition: vectormap.h:125
libmesh_cppunit.h
VectormapTest::testInsert
void testInsert()
Definition: vectormap_test.C:85
VectormapTest::iterate
void iterate(const Val &default_value=0)
Definition: vectormap_test.C:45