libMesh
Loading...
Searching...
No Matches
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
9using namespace libMesh;
10
11class VectormapTest : public CppUnit::TestCase
12{
13public:
15
21
23
24private:
25
26 template <typename Key, typename Val>
27 void create()
28 {
30 }
31
32 template <typename Key, typename Val>
33 void insert()
34 {
36
37 Val val(0); // requires default constructor for val type.
38
39 for (Key key=1; key<32; key*=2)
40 vm.insert (std::make_pair(key,val));
41
42 vm.sort();
43 }
44
45 template <typename Key, typename Val>
46 void emplace()
47 {
49
50 Val val(0); // requires default constructor for val type.
51
52 for (Key key=1; key<32; key*=2)
53 vm.emplace(key, val);
54
55 vm.sort();
56 }
57
58 template <typename Key, typename Val>
59 void iterate(const Val &default_value=0)
60 {
62
63 Val val(default_value); // requires default constructor for val type.
64
65 for (Key key=1; key<32; key*=2)
66 vm.insert (std::make_pair(key,val));
67
68 vm.sort();
69
70 for (typename vectormap<Key,Val>::const_iterator it=vm.begin();
71 it != vm.end(); ++it)
72 {
73 const Key &ikey = it->first;
74 const Val &ival = it->second;
75
76 CPPUNIT_ASSERT ( vm.count(ikey) == 1 );
77 CPPUNIT_ASSERT_EQUAL (vm[ikey], ival);
78 CPPUNIT_ASSERT_EQUAL (ival, val);
79 }
80 }
81
82public:
83
84 // virtual void setUp()
85 // {}
86
87 // virtual void tearDown()
88 // {}
89
90
92 {
93 LOG_UNIT_TEST;
94
95 create<int, int> ();
96 create<int*,int> ();
97 create<int*,int*>();
98 create<int, std::vector<int>>();
99 }
100
102 {
103 LOG_UNIT_TEST;
104
105 insert<int, int> ();
106 insert<char,int> ();
107 insert<long,int*>();
108 insert<int, std::vector<int>>();
109 }
110
112 {
113 LOG_UNIT_TEST;
114
115 emplace<int, int> ();
116 emplace<char,int> ();
117 emplace<long,int*>();
118 emplace<int, std::vector<int>>();
119 }
120
122 {
123 LOG_UNIT_TEST;
124
125 iterate<int, int> ();
126 iterate<char,int> ();
127 iterate<long,int*>();
128 iterate<int, std::string>("test_string");
129 }
130
131 void testFind()
132 {
133 LOG_UNIT_TEST;
134
136 for (int i=16; i<32; ++i)
137 vm.insert(std::make_pair(i,i));
138
140 it1 = vm.find(24),
141 it2 = vm.find(4);
142
143 CPPUNIT_ASSERT(it1 != vm.end());
144 CPPUNIT_ASSERT(it2 == vm.end());
145 CPPUNIT_ASSERT(vm.count(24) == 1);
146 CPPUNIT_ASSERT(vm.count(4) == 0);
147 }
148};
149
void iterate(const Val &default_value=0)
CPPUNIT_TEST(testIterate)
CPPUNIT_TEST(testInsert)
LIBMESH_CPPUNIT_TEST_SUITE(VectormapTest)
CPPUNIT_TEST(testEmplace)
CPPUNIT_TEST(testCreate)
CPPUNIT_TEST(testFind)
This vectormap templated class is intended to provide the performance characteristics of a sorted std...
Definition vectormap.h:62
void insert(const value_type &x)
Inserts x into the vectormap.
Definition vectormap.h:116
difference_type count(const key_type &key) const
Definition vectormap.h:221
vector_type::const_iterator const_iterator
Definition vectormap.h:72
void emplace(Args &&... args)
Inserts x into the vector map, using "args" to construct it in-place.
Definition vectormap.h:127
void sort()
Sort & unique the vectormap, preparing for use.
Definition vectormap.h:136
iterator find(const key_type &key)
Definition vectormap.h:171
vector_type::iterator iterator
Definition vectormap.h:71
The libMesh namespace provides an interface to certain functionality in the library.
CPPUNIT_TEST_SUITE_REGISTRATION(VectormapTest)