16
16
*
17
17
*****************************************************************************/
18
18
19
- #include < stdexcept>
20
19
#include < cxxtest/TestSuite.h>
21
20
22
- #include < diffpy/serialization.hpp>
23
21
#include < diffpy/srreal/BVParametersTable.hpp>
22
+ #include " serialization_helpers.hpp"
24
23
25
24
using namespace std ;
26
25
using namespace diffpy ::srreal;
@@ -71,6 +70,16 @@ class TestBVParametersTable : public CxxTest::TestSuite
71
70
}
72
71
73
72
73
+ void test_atomvalence ()
74
+ {
75
+ TS_ASSERT_EQUALS (0 , mbvtb->getAtomValence (" O" ));
76
+ mbvtb->setAtomValence (" O" , -2 );
77
+ TS_ASSERT_EQUALS (-2 , mbvtb->getAtomValence (" O" ));
78
+ mbvtb->resetAtomValences ();
79
+ TS_ASSERT_EQUALS (0 , mbvtb->getAtomValence (" O" ));
80
+ }
81
+
82
+
74
83
void test_lookup ()
75
84
{
76
85
BVParam bp = mbvtb->lookup (" Xx" , 0 , " Yy" , 3 );
@@ -91,6 +100,11 @@ class TestBVParametersTable : public CxxTest::TestSuite
91
100
const BVParam& bnacl0 = mbvtb->lookup (" Na" , 1 , " Cl" , -1 );
92
101
TS_ASSERT_EQUALS (&bnacl0, &mbvtb->lookup (" Na+" , " Cl-" ));
93
102
TS_ASSERT_EQUALS (&bnacl0, &mbvtb->lookup (" Cl1-" , " Na1+" ));
103
+ const BVParam& bpnone = BVParametersTable::none ();
104
+ TS_ASSERT_EQUALS (&bpnone, &mbvtb->lookup (" Na" , " Cl" ));
105
+ mbvtb->setAtomValence (" Na" , +1 );
106
+ mbvtb->setAtomValence (" Cl" , -1 );
107
+ TS_ASSERT_EQUALS (&bnacl0, &mbvtb->lookup (" Na" , " Cl" ));
94
108
}
95
109
96
110
@@ -135,6 +149,25 @@ class TestBVParametersTable : public CxxTest::TestSuite
135
149
}
136
150
137
151
152
+ void test_getAllCustom ()
153
+ {
154
+ TS_ASSERT (mbvtb->getAllCustom ().empty ());
155
+ BVParam mymgo (" Mg" , 2 , " O" , -2 );
156
+ mbvtb->setCustom (mymgo);
157
+ TS_ASSERT_EQUALS (1u , mbvtb->getAllCustom ().size ());
158
+ const BVParam& bp = mbvtb->lookup (" O2-" , " Mg2+" );
159
+ BVParametersTable::SetOfBVParam::const_iterator ii;
160
+ ii = mbvtb->getAllCustom ().find (mymgo);
161
+ TS_ASSERT_DIFFERS (ii, mbvtb->getAllCustom ().end ());
162
+ TS_ASSERT_DIFFERS (&mymgo, &(*ii));
163
+ TS_ASSERT_EQUALS (&bp, &(*ii));
164
+ TS_ASSERT_EQUALS (mymgo, *ii);
165
+ // erase the only custom parameter
166
+ mbvtb->resetCustom (*ii);
167
+ TS_ASSERT (mbvtb->getAllCustom ().empty ());
168
+ }
169
+
170
+
138
171
void test_getAll ()
139
172
{
140
173
BVParametersTable::SetOfBVParam allpars0, allpars1;
@@ -164,13 +197,8 @@ class TestBVParametersTable : public CxxTest::TestSuite
164
197
BVParam mymgo (" O" , -2 , " Mg" , 2 , 3.456 , 0.55 , " pj2" );
165
198
mbvtb->setCustom (mynacl);
166
199
mbvtb->setCustom (mymgo);
167
- stringstream storage (ios::in | ios::out | ios::binary);
168
- diffpy::serialization::oarchive oa (storage, ios::binary);
169
- oa << mbvtb;
170
- diffpy::serialization::iarchive ia (storage, ios::binary);
171
- BVParametersTablePtr bvtb1;
172
- TS_ASSERT (!bvtb1.get ());
173
- ia >> bvtb1;
200
+ // check serialization of shared pointers
201
+ BVParametersTablePtr bvtb1 = dumpandload (mbvtb);
174
202
TS_ASSERT_DIFFERS (mbvtb.get (), bvtb1.get ());
175
203
TS_ASSERT_EQUALS (2.345 ,
176
204
bvtb1->lookup (" Cl" , -1 , " Na" , 1 ).mRo );
@@ -184,6 +212,17 @@ class TestBVParametersTable : public CxxTest::TestSuite
184
212
bvtb1->lookup (" O" , -2 , " Mg" , 2 ).mB );
185
213
TS_ASSERT_EQUALS (string (" pj2" ),
186
214
bvtb1->lookup (" O" , -2 , " Mg" , 2 ).mref_id );
215
+ // check serialization of instances
216
+ BVParametersTable tb2 = dumpandload (*mbvtb);
217
+ TS_ASSERT_EQUALS (2u , tb2.getAllCustom ().size ());
218
+ TS_ASSERT_EQUALS (mynacl, tb2.lookup (" Cl-" , " Na+" ));
219
+ // check serialization of customized valences
220
+ tb2.setAtomValence (" Na" , 1 );
221
+ tb2.setAtomValence (" Cl" , -1 );
222
+ BVParametersTable tb3 = dumpandload (tb2);
223
+ TS_ASSERT_EQUALS (mynacl, tb3.lookup (" Cl" , " Na" ));
224
+ const BVParam& bpnone = BVParametersTable::none ();
225
+ TS_ASSERT_EQUALS (bpnone, mbvtb->lookup (" Cl" , " Na" ));
187
226
}
188
227
189
228
}; // class TestBVParametersTable
0 commit comments