11
11
12
12
13
13
#include " catch.hpp"
14
- #include " complex_approx.hpp"
15
14
16
15
#include " VariableSet.h"
17
16
#include " io/hdf/hdf_archive.h"
20
19
#include < string>
21
20
22
21
using std::string;
23
- using qmcplusplus::ValueApprox;
24
22
25
23
namespace optimize
26
24
{
@@ -37,7 +35,7 @@ TEST_CASE("VariableSet empty", "[optimize]")
37
35
TEST_CASE (" VariableSet one" , " [optimize]" )
38
36
{
39
37
VariableSet vs;
40
- VariableSet::value_type first_val (1.123456789 );
38
+ VariableSet::real_type first_val (1.123456789 );
41
39
vs.insert (" first" , first_val);
42
40
std::vector<std::string> names{" first" };
43
41
vs.activate (names.begin (), names.end (), true );
@@ -47,44 +45,31 @@ TEST_CASE("VariableSet one", "[optimize]")
47
45
REQUIRE (vs.getIndex (" first" ) == 0 );
48
46
REQUIRE (vs.name (0 ) == " first" );
49
47
double first_val_real = 1.123456789 ;
50
- CHECK (std::real ( vs[0 ] ) == Approx (first_val_real));
48
+ CHECK (vs[0 ] == Approx (first_val_real));
51
49
52
50
std::ostringstream o;
53
51
vs.print (o, 0 , false );
54
52
// std::cout << o.str() << std::endl;
55
- #ifdef QMC_COMPLEX
56
- REQUIRE (o.str () == " first (1.123457e+00,0.000000e+00) 0 1 ON 0\n " );
57
- #else
58
53
REQUIRE (o.str () == " first 1.123457e+00 0 1 ON 0\n " );
59
- #endif
60
54
61
55
std::ostringstream o2;
62
56
vs.print (o2, 1 , true );
63
57
// std::cout << o2.str() << std::endl;
64
58
65
- #ifdef QMC_COMPLEX
66
- char formatted_output[] = " Name Value Type Recompute Use Index\n "
67
- " ----- ---------------------------- ---- --------- --- -----\n "
68
- " first (1.123457e+00,0.000000e+00) 0 1 ON 0\n " ;
69
-
70
-
71
- REQUIRE (o2.str () == formatted_output);
72
- #else
73
59
char formatted_output[] = " Name Value Type Recompute Use Index\n "
74
60
" ----- ---------------------------- ---- --------- --- -----\n "
75
61
" first 1.123457e+00 0 1 ON 0\n " ;
76
62
77
63
78
64
REQUIRE (o2.str () == formatted_output);
79
- #endif
80
65
}
81
66
82
67
TEST_CASE (" VariableSet output" , " [optimize]" )
83
68
{
84
69
VariableSet vs;
85
- VariableSet::value_type first_val (11234.56789 );
86
- VariableSet::value_type second_val (0.000256789 );
87
- VariableSet::value_type third_val (-1.2 );
70
+ VariableSet::real_type first_val (11234.56789 );
71
+ VariableSet::real_type second_val (0.000256789 );
72
+ VariableSet::real_type third_val (-1.2 );
88
73
vs.insert (" s" , first_val);
89
74
vs.insert (" second" , second_val);
90
75
vs.insert (" really_long_name" , third_val);
@@ -95,29 +80,21 @@ TEST_CASE("VariableSet output", "[optimize]")
95
80
vs.print (o, 0 , true );
96
81
// std::cout << o.str() << std::endl;
97
82
98
- #ifdef QMC_COMPLEX
99
- char formatted_output[] = " Name Value Type Recompute Use Index\n "
100
- " ---------------- ---------------------------- ---- --------- --- -----\n "
101
- " s (1.123457e+04,0.000000e+00) 0 1 ON 0\n "
102
- " second (2.567890e-04,0.000000e+00) 0 1 ON 1\n "
103
- " really_long_name (-1.200000e+00,0.000000e+00) 0 1 ON 2\n " ;
104
- #else
105
83
char formatted_output[] = " Name Value Type Recompute Use Index\n "
106
84
" ---------------- ---------------------------- ---- --------- --- -----\n "
107
85
" s 1.123457e+04 0 1 ON 0\n "
108
86
" second 2.567890e-04 0 1 ON 1\n "
109
87
" really_long_name -1.200000e+00 0 1 ON 2\n " ;
110
- #endif
111
88
112
89
REQUIRE (o.str () == formatted_output);
113
90
}
114
91
115
92
TEST_CASE (" VariableSet HDF output and input" , " [optimize]" )
116
93
{
117
94
VariableSet vs;
118
- VariableSet::value_type first_val (11234.56789 );
119
- VariableSet::value_type second_val (0.000256789 );
120
- VariableSet::value_type third_val (-1.2 );
95
+ VariableSet::real_type first_val (11234.56789 );
96
+ VariableSet::real_type second_val (0.000256789 );
97
+ VariableSet::real_type third_val (-1.2 );
121
98
vs.insert (" s" , first_val);
122
99
vs.insert (" second" , second_val);
123
100
vs.insert (" really_really_really_long_name" , third_val);
@@ -129,8 +106,8 @@ TEST_CASE("VariableSet HDF output and input", "[optimize]")
129
106
vs2.insert (" second" , 0.0 );
130
107
qmcplusplus::hdf_archive hin;
131
108
vs2.readFromHDF (" vp.h5" , hin);
132
- CHECK (vs2.find (" s" )->second == ValueApprox (first_val));
133
- CHECK (vs2.find (" second" )->second == ValueApprox (second_val));
109
+ CHECK (vs2.find (" s" )->second == Approx (first_val));
110
+ CHECK (vs2.find (" second" )->second == Approx (second_val));
134
111
// This value as in the file, but not in the VariableSet that loaded the file,
135
112
// so the value does not get added.
136
113
CHECK (vs2.find (" really_really_really_long_name" ) == vs2.end ());
0 commit comments