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.

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

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

Referenced by test().

◆ testIntegralReally()

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

Definition at line 52 of file diff_std_test.cpp.

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}
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

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

◆ 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.

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}
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

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

◆ testCV()

void testCV ( )

Definition at line 88 of file diff_std_test.cpp.

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
100 diff(a,b);
101
102 unit_assert(diff.a_b.empty());
103 unit_assert(diff.b_a.empty());
105
106 a.version = "version_changed";
107
108 diff(a,b);
109 if (os_) *os_ << diff << endl;
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}
PWIZ_API_DECL void diff(const std::string &a, const std::string &b, std::string &a_b, std::string &b_a, const BaseDiffConfig &config)
Information about an ontology or CV source and a short 'lookup' tag to refer to.
Definition cv.hpp:14916
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:14918
std::string fullName
the usual name for the resource (e.g. The PSI-MS Controlled Vocabulary).
Definition cv.hpp:14924
std::string URI
the URI for the resource.
Definition cv.hpp:14921
std::string version
the version of the CV from which the referred-to terms are drawn.
Definition cv.hpp:14927
Calculate diffs of objects in a ProteoWizard data model hierarchy.
Definition diff_std.hpp:143

References pwiz::data::diff_impl::diff(), pwiz::cv::CV::fullName, pwiz::cv::CV::id, os_, unit_assert, pwiz::cv::CV::URI, and pwiz::cv::CV::version.

Referenced by test().

◆ testUserParam()

void testUserParam ( )

Definition at line 119 of file diff_std_test.cpp.

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);
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}
UO_minute
minute: A time unit which is equal to 60 seconds.
Definition cv.hpp:13896
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:13833
Uncontrolled user parameters (essentially allowing free text). Before using these,...
CVID units
an optional CV parameter for the unit term associated with the value, if any (e.g....
std::string value
the value for the parameter, where appropriate.
std::string name
the name for the parameter.
std::string type
the datatype of the parameter, where appropriate (e.g.: xsd:float).

References pwiz::data::diff_impl::diff(), 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().

◆ testCVParam()

void testCVParam ( )

Definition at line 149 of file diff_std_test.cpp.

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);
160 unit_assert(diff.a_b.empty());
161 unit_assert(diff.b_a.empty());
162
163 b.value = "value_changed";
164 diff(a,b);
166 if (os_) *os_ << diff << endl;
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);
175 if (os_) *os_ << diff << endl;
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);
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);
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);
197 if (os_) *os_ << diff << endl;
198
199
200}
MS_ionization_type
ionization type: The method by which gas phase ions are generated from the sample.
Definition cv.hpp:285
represents a tag-value pair, where the tag comes from the controlled vocabulary

References pwiz::data::CVParam::cvid, pwiz::data::diff_impl::diff(), MS_ionization_type, os_, unit_assert, and pwiz::data::CVParam::value.

Referenced by test().

◆ testParamContainer()

void testParamContainer ( )

Definition at line 203 of file diff_std_test.cpp.

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
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;
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_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:384
MS_charge_state
charge state: The charge state of the ion, single or multiple and positive or negatively charged.
Definition cv.hpp:396
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:402
boost::shared_ptr< ParamGroup > ParamGroupPtr
The base class for elements that may contain cvParams, userParams, or paramGroup references.
std::vector< ParamGroupPtr > paramGroupPtrs
a collection of references to ParamGroups
std::vector< CVParam > cvParams
a collection of controlled vocabulary terms
std::vector< UserParam > userParams
a collection of uncontrolled user terms
A collection of CVParam and UserParam elements that can be referenced from elsewhere in this mzML doc...

References pwiz::data::ParamContainer::cvParams, pwiz::data::diff_impl::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().

◆ testParamGroup()

void testParamGroup ( )

Definition at line 250 of file diff_std_test.cpp.

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
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;
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}

References pwiz::data::diff_impl::diff(), os_, unit_assert, and pwiz::data::ParamContainer::userParams.

Referenced by test().

◆ test()

void test ( )

Definition at line 275 of file diff_std_test.cpp.

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();
299 testCVParam();
302}
void testParamContainer()
void testUserParam()
void testCVParam()
void testCV()
void testString(const string &a, const string &b)
void testParamGroup()

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

Referenced by main().

◆ main()

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

Definition at line 304 of file diff_std_test.cpp.

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}
void test()
#define TEST_EPILOG
Definition unit.hpp:183
#define TEST_FAILED(x)
Definition unit.hpp:177
#define TEST_PROLOG(argc, argv)
Definition unit.hpp:175

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

Variable Documentation

◆ os_

ostream* os_ = 0