libMesh
Loading...
Searching...
No Matches
parameters_test.C
Go to the documentation of this file.
1#include <libmesh/parameters.h>
2
3#include "libmesh_cppunit.h"
4
5#include <map>
6#include <string>
7
8using namespace libMesh;
9
10class ParametersTest : public CppUnit::TestCase {
11public:
13
17
19
21
22private:
23
24public:
25 void setUp()
26 {}
27
28 void tearDown()
29 {}
30
31 template <typename T>
32 void testScalar ()
33 {
34 [[maybe_unused]] // nvc++ has some issues...
35 Parameters param;
36
37 T t = 10, t_orig = 10;
38
39 param.set<T>("first") = t;
40
41 ++t;
42
43 param.set<T>("second") = t;
44
45 CPPUNIT_ASSERT_EQUAL(t_orig, param.get<T>("first"));
46 CPPUNIT_ASSERT_EQUAL(t, param.get<T>("second"));
47 }
48
49 void testMap ()
50 {
51 LOG_UNIT_TEST;
52
53 Parameters param;
54
55 std::map<int, std::string> m;
56 m[2] = "two";
57 m[4] = "four";
58 param.set<std::map<int, std::string>>("mymap") = m;
59 const std::map<int, std::string> & gotten =
60 param.get<std::map<int, std::string>>("mymap");
61
62 CPPUNIT_ASSERT_EQUAL(gotten.size(), std::size_t(2));
63 CPPUNIT_ASSERT_EQUAL(gotten.at(2), std::string("two"));
64 CPPUNIT_ASSERT_EQUAL(gotten.at(4), std::string("four"));
65 }
66
67 void testInt () { LOG_UNIT_TEST; testScalar<int>(); }
68 void testFloat () { LOG_UNIT_TEST; testScalar<float>(); }
69 void testDouble () { LOG_UNIT_TEST; testScalar<double>(); }
70};
71
LIBMESH_CPPUNIT_TEST_SUITE(ParametersTest)
CPPUNIT_TEST(testInt)
CPPUNIT_TEST(testDouble)
CPPUNIT_TEST(testFloat)
CPPUNIT_TEST(testMap)
This class provides the ability to map between arbitrary, user-defined strings and several data types...
Definition parameters.h:75
T & set(const std::string &)
Definition parameters.h:494
const T & get(std::string_view) const
Definition parameters.h:451
The libMesh namespace provides an interface to certain functionality in the library.
CPPUNIT_TEST_SUITE_REGISTRATION(ParametersTest)