ProteoWizard
Macros | Functions | Variables
diff_std_test.cpp File Reference
#include "diff_std.hpp"
#include "pwiz/utility/misc/unit.hpp"
#include "pwiz/utility/misc/Std.hpp"
#include <cstring>

Go to the source code of this file.

Macros

#define PWIZ_SOURCE
 

Functions

void testString (const string &a, const string &b)
 
template<typename integral_type >
void testIntegralReally (integral_type a, integral_type b)
 
template<typename integral_type >
void testIntegral ()
 
template<typename floating_type >
void testFloating (floating_type a, floating_type b, floating_type precision)
 
void testCV ()
 
void testUserParam ()
 
void testCVParam ()
 
void testParamContainer ()
 
void testParamGroup ()
 
void test ()
 
int main (int argc, char *argv[])
 

Variables

ostream * os_ = 0
 

Macro Definition Documentation

§ PWIZ_SOURCE

#define PWIZ_SOURCE

Definition at line 23 of file diff_std_test.cpp.

Function Documentation

§ testString()

void testString ( const string &  a,
const string &  b 
)

Definition at line 37 of file diff_std_test.cpp.

References pwiz::data::diff_string(), os_, and unit_assert.

Referenced by test().

38 {
39  if (os_) *os_ << "diff_string(\"" << a << "\", \"" << b << "\")" << endl;
40 
41  string a_b, b_a;
42  diff_string(a, b, a_b, b_a);
43  if (os_) *os_ << "a-b: " << a_b << "\nb-a: " << b_a << endl;
44 
45  if (a == b)
46  unit_assert(a_b.empty() && b_a.empty());
47  else
48  unit_assert(!a_b.empty() && !b_a.empty());
49 }
ostream * os_
std::string diff_string(const diff_type &diff)
Definition: diff_std.hpp:177
#define unit_assert(x)
Definition: unit.hpp:85

§ testIntegralReally()

template<typename integral_type >
void testIntegralReally ( integral_type  a,
integral_type  b 
)

Definition at line 52 of file diff_std_test.cpp.

References pwiz::data::diff_impl::diff_integral(), os_, and unit_assert.

53 {
54  if (os_) *os_ << "diff_integral(\"" << a << "\", \"" << b << "\")" << endl;
55 
56  integral_type a_b, b_a;
57  diff_integral(a, b, a_b, b_a, BaseDiffConfig());
58  if (a == b)
59  unit_assert(a_b == integral_type() && b_a == integral_type());
60  else
61  unit_assert(a_b != integral_type() || b_a != integral_type());
62 }
ostream * os_
#define unit_assert(x)
Definition: unit.hpp:85
void diff_integral(const integral_type &a, const integral_type &b, integral_type &a_b, integral_type &b_a, const BaseDiffConfig &config)
Definition: diff_std.hpp:258

§ testIntegral()

template<typename integral_type >
void testIntegral ( )

Definition at line 65 of file diff_std_test.cpp.

66 {
67  testIntegralReally<int>(1, 1);
68  testIntegralReally<int>(-1, 1);
69  testIntegralReally<int>(-1, -1);
70  testIntegralReally<int>(1, 0);
71  testIntegralReally<int>(-1, 0);
72 }

§ testFloating()

template<typename floating_type >
void testFloating ( floating_type  a,
floating_type  b,
floating_type  precision 
)

Definition at line 75 of file diff_std_test.cpp.

References pwiz::data::diff_impl::diff_floating(), epsilon, pwiz::data::BaseDiffConfig::precision, and unit_assert.

76 {
77  floating_type a_b, b_a;
78  BaseDiffConfig config((double) precision);
79 
80  diff_floating(a, b, a_b, b_a, config);
81  if (fabs(a - b) <= config.precision + std::numeric_limits<floating_type>::epsilon())
82  unit_assert(a_b == floating_type() && b_a == floating_type());
83  else
84  unit_assert(a_b == fabs(a - b) && b_a == fabs(a - b));
85 }
const double epsilon
Definition: DiffTest.cpp:41
void diff_floating(const floating_type &a, const floating_type &b, floating_type &a_b, floating_type &b_a, const BaseDiffConfig &config)
Definition: diff_std.hpp:276
#define unit_assert(x)
Definition: unit.hpp:85

§ testCV()

void testCV ( )

Definition at line 88 of file diff_std_test.cpp.

References pwiz::data::Diff< object_type, config_type, object_result_type >::a_b, pwiz::data::Diff< object_type, config_type, object_result_type >::b_a, diff(), pwiz::cv::CV::empty(), pwiz::cv::CV::fullName, pwiz::cv::CV::id, os_, unit_assert, pwiz::cv::CV::URI, and pwiz::cv::CV::version.

Referenced by test().

89 {
90  if (os_) *os_ << "testCV()\n";
91 
92  CV a, b;
93  a.URI = "uri";
94  a.id = "cvLabel";
95  a.fullName = "fullName";
96  a.version = "version";
97  b = a;
98 
99  Diff<CV> diff;
100  diff(a,b);
101 
102  unit_assert(diff.a_b.empty());
103  unit_assert(diff.b_a.empty());
104  unit_assert(!diff);
105 
106  a.version = "version_changed";
107 
108  diff(a,b);
109  if (os_) *os_ << diff << endl;
110  unit_assert(diff);
111  unit_assert(diff.a_b.URI.empty() && diff.b_a.URI.empty());
112  unit_assert(diff.a_b.id.empty() && diff.b_a.id.empty());
113  unit_assert(diff.a_b.fullName.empty() && diff.b_a.fullName.empty());
114  unit_assert(diff.a_b.version == "version_changed");
115  unit_assert(diff.b_a.version == "version");
116 }
std::string id
the short label to be used as a reference tag with which to refer to this particular Controlled Vocab...
Definition: cv.hpp:13356
bool empty() const
returns ture iff id, URI, fullName, and version are all empty
Calculate diffs of objects in a ProteoWizard data model hierarchy.
Definition: diff_std.hpp:142
ostream * os_
Information about an ontology or CV source and a short &#39;lookup&#39; tag to refer to.
Definition: cv.hpp:13353
void diff(const string &filename1, const string &filename2)
std::string fullName
the usual name for the resource (e.g. The PSI-MS Controlled Vocabulary).
Definition: cv.hpp:13362
object_result_type b_a
Definition: diff_std.hpp:157
std::string URI
the URI for the resource.
Definition: cv.hpp:13359
object_result_type a_b
Definition: diff_std.hpp:156
std::string version
the version of the CV from which the referred-to terms are drawn.
Definition: cv.hpp:13365
#define unit_assert(x)
Definition: unit.hpp:85

§ testUserParam()

void testUserParam ( )

Definition at line 119 of file diff_std_test.cpp.

References pwiz::data::Diff< object_type, config_type, object_result_type >::a_b, pwiz::data::Diff< object_type, config_type, object_result_type >::b_a, diff(), pwiz::data::UserParam::empty(), pwiz::data::UserParam::name, os_, pwiz::data::UserParam::type, unit_assert, pwiz::data::UserParam::units, UO_minute, UO_second, and pwiz::data::UserParam::value.

Referenced by test().

120 {
121  if (os_) *os_ << "testUserParam()\n";
122 
123  UserParam a, b;
124  a.name = "name";
125  a.value = "value";
126  a.type = "type";
127  a.units = UO_minute;
128  b = a;
129 
130  Diff<UserParam> diff(a, b);
131  unit_assert(!diff);
132  unit_assert(diff.a_b.empty());
133  unit_assert(diff.b_a.empty());
134 
135  b.value = "value_changed";
136  a.units = UO_second;
137  unit_assert(diff(a,b));
138  if (os_) *os_ << diff << endl;
139  unit_assert(diff.a_b.name == "name");
140  unit_assert(diff.b_a.name == "name");
141  unit_assert(diff.a_b.value == "value");
142  unit_assert(diff.b_a.value == "value_changed");
143  unit_assert(diff.a_b.type.empty() && diff.b_a.type.empty());
144  unit_assert(diff.a_b.units == UO_second);
145  unit_assert(diff.b_a.units == UO_minute);
146 }
std::string value
the value for the parameter, where appropriate.
Definition: ParamTypes.hpp:191
Calculate diffs of objects in a ProteoWizard data model hierarchy.
Definition: diff_std.hpp:142
ostream * os_
UO_second
second: A time unit which is equal to the duration of 9 192 631 770 periods of the radiation correspo...
Definition: cv.hpp:12526
void diff(const string &filename1, const string &filename2)
Uncontrolled user parameters (essentially allowing free text). Before using these, one should verify whether there is an appropriate CV term available, and if so, use the CV term instead.
Definition: ParamTypes.hpp:185
std::string type
the datatype of the parameter, where appropriate (e.g.: xsd:float).
Definition: ParamTypes.hpp:194
std::string name
the name for the parameter.
Definition: ParamTypes.hpp:188
UO_minute
minute: A time unit which is equal to 60 seconds.
Definition: cv.hpp:12589
CVID units
an optional CV parameter for the unit term associated with the value, if any (e.g. MS_electron_volt).
Definition: ParamTypes.hpp:197
#define unit_assert(x)
Definition: unit.hpp:85

§ testCVParam()

void testCVParam ( )

Definition at line 149 of file diff_std_test.cpp.

References pwiz::data::Diff< object_type, config_type, object_result_type >::a_b, pwiz::data::Diff< object_type, config_type, object_result_type >::b_a, pwiz::data::CVParam::cvid, diff(), pwiz::data::CVParam::empty(), MS_ionization_type, os_, unit_assert, and pwiz::data::CVParam::value.

Referenced by test().

150 {
151  if (os_) *os_ << "testCVParam()\n";
152 
153  CVParam a, b, c;
155  a.value = "420";
156  c = b = a;
157 
158  Diff<CVParam> diff(a, b);
159  unit_assert(!diff);
160  unit_assert(diff.a_b.empty());
161  unit_assert(diff.b_a.empty());
162 
163  b.value = "value_changed";
164  diff(a,b);
165  unit_assert(diff);
166  if (os_) *os_ << diff << endl;
167  unit_assert(diff.a_b.cvid == MS_ionization_type);
168  unit_assert(diff.b_a.cvid == MS_ionization_type);
169  unit_assert(diff.a_b.value == "420");
170  unit_assert(diff.b_a.value == "value_changed");
171 
172  c.value = "421"; // prove fix for bug that wouldn't catch diff in int values
173  diff(a,c);
174  unit_assert(diff);
175  if (os_) *os_ << diff << endl;
176  unit_assert(diff.a_b.cvid == MS_ionization_type);
177  unit_assert(diff.b_a.cvid == MS_ionization_type);
178  unit_assert(diff.a_b.value == "420");
179  unit_assert(diff.b_a.value == "421");
180 
181  a.value = "4.1e5"; // make sure we handle scientific notation properly
182  c.value = "4.1";
183  diff(a,c);
184  unit_assert(diff);
185  if (os_) *os_ << diff << endl;
186 
187  a.value = "4.1e5"; // make sure we handle scientific notation properly
188  c.value = "410000.0";
189  diff(a,c);
190  unit_assert(!diff);
191  if (os_) *os_ << diff << endl;
192 
193  a.value = "1a"; // make sure we aren't naive about things that start out as ints
194  c.value = "1b";
195  diff(a,c);
196  unit_assert(diff);
197  if (os_) *os_ << diff << endl;
198 
199 
200 }
std::string value
Definition: ParamTypes.hpp:47
Calculate diffs of objects in a ProteoWizard data model hierarchy.
Definition: diff_std.hpp:142
ostream * os_
void diff(const string &filename1, const string &filename2)
MS_ionization_type
ionization type: The method by which gas phase ions are generated from the sample.
Definition: cv.hpp:124
#define unit_assert(x)
Definition: unit.hpp:85
represents a tag-value pair, where the tag comes from the controlled vocabulary
Definition: ParamTypes.hpp:44

§ testParamContainer()

void testParamContainer ( )

Definition at line 203 of file diff_std_test.cpp.

References pwiz::data::Diff< object_type, config_type, object_result_type >::a_b, pwiz::data::Diff< object_type, config_type, object_result_type >::b_a, pwiz::data::ParamContainer::cvParams, diff(), MS_charge_state, MS_m_z, MS_peak_intensity, os_, pwiz::data::ParamContainer::paramGroupPtrs, unit_assert, and pwiz::data::ParamContainer::userParams.

Referenced by test().

204 {
205  if (os_) *os_ << "testParamContainer()\n";
206 
207  ParamGroupPtr pgp1(new ParamGroup("pg1"));
208  ParamGroupPtr pgp2(new ParamGroup("pg2"));
209  ParamGroupPtr pgp3(new ParamGroup("pg3"));
210 
211  ParamContainer a, b;
212  a.userParams.push_back(UserParam("common"));
213  b.userParams.push_back(UserParam("common"));
214  a.cvParams.push_back(MS_m_z);
215  b.cvParams.push_back(MS_m_z);
216  a.paramGroupPtrs.push_back(pgp1);
217  b.paramGroupPtrs.push_back(pgp1);
218 
220  unit_assert(!diff);
221 
222  a.userParams.push_back(UserParam("different", "1"));
223  b.userParams.push_back(UserParam("different", "2"));
224  a.cvParams.push_back(MS_charge_state);
225  b.cvParams.push_back(MS_peak_intensity);
226  a.paramGroupPtrs.push_back(pgp2);
227  b.paramGroupPtrs.push_back(pgp3);
228 
229  diff(a, b);
230  if (os_) *os_ << diff << endl;
231  unit_assert(diff);
232 
233  unit_assert(diff.a_b.userParams.size() == 1);
234  unit_assert(diff.a_b.userParams[0] == UserParam("different","1"));
235  unit_assert(diff.b_a.userParams.size() == 1);
236  unit_assert(diff.b_a.userParams[0] == UserParam("different","2"));
237 
238  unit_assert(diff.a_b.cvParams.size() == 1);
239  unit_assert(diff.a_b.cvParams[0] == MS_charge_state);
240  unit_assert(diff.b_a.cvParams.size() == 1);
241  unit_assert(diff.b_a.cvParams[0] == MS_peak_intensity);
242 
243  unit_assert(diff.a_b.paramGroupPtrs.size() == 1);
244  unit_assert(diff.a_b.paramGroupPtrs[0]->id == "pg2");
245  unit_assert(diff.b_a.paramGroupPtrs.size() == 1);
246  unit_assert(diff.b_a.paramGroupPtrs[0]->id == "pg3");
247 }
MS_charge_state
charge state: The charge state of the ion, single or multiple and positive or negatively charged...
Definition: cv.hpp:235
boost::shared_ptr< ParamGroup > ParamGroupPtr
Definition: ParamTypes.hpp:239
Calculate diffs of objects in a ProteoWizard data model hierarchy.
Definition: diff_std.hpp:142
ostream * os_
MS_peak_intensity
peak intensity: Intensity of ions as measured by the height or area of a peak in a mass spectrum...
Definition: cv.hpp:241
void diff(const string &filename1, const string &filename2)
Uncontrolled user parameters (essentially allowing free text). Before using these, one should verify whether there is an appropriate CV term available, and if so, use the CV term instead.
Definition: ParamTypes.hpp:185
std::vector< UserParam > userParams
a collection of uncontrolled user terms
Definition: ParamTypes.hpp:253
MS_m_z
m/z: Three-character symbol m/z is used to denote the quantity formed by dividing the mass of an ion ...
Definition: cv.hpp:223
The base class for elements that may contain cvParams, userParams, or paramGroup references.
Definition: ParamTypes.hpp:244
std::vector< CVParam > cvParams
a collection of controlled vocabulary terms
Definition: ParamTypes.hpp:250
std::vector< ParamGroupPtr > paramGroupPtrs
a collection of references to ParamGroups
Definition: ParamTypes.hpp:247
A collection of CVParam and UserParam elements that can be referenced from elsewhere in this mzML doc...
Definition: ParamTypes.hpp:324
#define unit_assert(x)
Definition: unit.hpp:85

§ testParamGroup()

void testParamGroup ( )

Definition at line 250 of file diff_std_test.cpp.

References pwiz::data::Diff< object_type, config_type, object_result_type >::a_b, pwiz::data::Diff< object_type, config_type, object_result_type >::b_a, diff(), os_, unit_assert, and pwiz::data::ParamContainer::userParams.

Referenced by test().

251 {
252  if (os_) *os_ << "testParamGroup()\n";
253 
254  ParamGroup a("pg"), b("pg");
255  a.userParams.push_back(UserParam("common"));
256  b.userParams.push_back(UserParam("common"));
257 
258  Diff<ParamGroup> diff(a, b);
259  unit_assert(!diff);
260 
261  a.userParams.push_back(UserParam("different", "1"));
262  b.userParams.push_back(UserParam("different", "2"));
263 
264  diff(a, b);
265  if (os_) *os_ << diff << endl;
266  unit_assert(diff);
267 
268  unit_assert(diff.a_b.userParams.size() == 1);
269  unit_assert(diff.a_b.userParams[0] == UserParam("different","1"));
270  unit_assert(diff.b_a.userParams.size() == 1);
271  unit_assert(diff.b_a.userParams[0] == UserParam("different","2"));
272 }
Calculate diffs of objects in a ProteoWizard data model hierarchy.
Definition: diff_std.hpp:142
ostream * os_
void diff(const string &filename1, const string &filename2)
Uncontrolled user parameters (essentially allowing free text). Before using these, one should verify whether there is an appropriate CV term available, and if so, use the CV term instead.
Definition: ParamTypes.hpp:185
A collection of CVParam and UserParam elements that can be referenced from elsewhere in this mzML doc...
Definition: ParamTypes.hpp:324
#define unit_assert(x)
Definition: unit.hpp:85

§ test()

void test ( )

Definition at line 275 of file diff_std_test.cpp.

References testCV(), testCVParam(), testParamContainer(), testParamGroup(), testString(), and testUserParam().

Referenced by main().

276 {
277  testString("goober", "goober");
278  testString("goober", "goo");
279 
280  testIntegral<int>();
281  testIntegral<short>();
282  testIntegral<long>();
283  testIntegral<unsigned int>();
284  testIntegral<unsigned short>();
285  testIntegral<unsigned long>();
286 
287  testFloating<float>(1.f, 1.f, 1.e-6f);
288  testFloating<float>(1.f, 1.0000000001f, 1.e-6f);
289  testFloating<float>(1.f, 1.00001f, 1.e-6f);
290  testFloating<float>(4.f, 4.2f, 1.f);
291 
292  testFloating<double>(1, 1, 1e-6);
293  testFloating<double>(1, 1.0000000001, 1e-6);
294  testFloating<double>(1, 1.00001, 1e-6);
295  testFloating<double>(4, 4.2, 1);
296 
297  testCV();
298  testUserParam();
299  testCVParam();
301  testParamGroup();
302 }
void testUserParam()
void testParamGroup()
void testString(const string &a, const string &b)
void testParamContainer()
void testCVParam()
void testCV()

§ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 304 of file diff_std_test.cpp.

References os_, test(), TEST_EPILOG, TEST_FAILED, and TEST_PROLOG.

305 {
306  TEST_PROLOG(argc, argv)
307 
308  try
309  {
310  if (argc>1 && !strcmp(argv[1],"-v")) os_ = &cout;
311  test();
312  }
313  catch (exception& e)
314  {
315  TEST_FAILED(e.what())
316  }
317  catch (...)
318  {
319  TEST_FAILED("Caught unknown exception.")
320  }
321 
323 }
#define TEST_EPILOG
Definition: unit.hpp:182
ostream * os_
void test()
#define TEST_FAILED(x)
Definition: unit.hpp:176
#define TEST_PROLOG(argc, argv)
Definition: unit.hpp:174

Variable Documentation

§ os_

ostream* os_ = 0