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

#define PWIZ_SOURCE

Definition at line 23 of file diff_std_test.cpp.


Function Documentation

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().

{
if (os_) *os_ << "diff_string(\"" << a << "\", \"" << b << "\")" << endl;
string a_b, b_a;
diff_string(a, b, a_b, b_a);
if (os_) *os_ << "a-b: " << a_b << "\nb-a: " << b_a << endl;
if (a == b)
unit_assert(a_b.empty() && b_a.empty());
else
unit_assert(!a_b.empty() && !b_a.empty());
}
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.

{
if (os_) *os_ << "diff_integral(\"" << a << "\", \"" << b << "\")" << endl;
integral_type a_b, b_a;
diff_integral(a, b, a_b, b_a, BaseDiffConfig());
if (a == b)
unit_assert(a_b == integral_type() && b_a == integral_type());
else
unit_assert(a_b != integral_type() || b_a != integral_type());
}
template<typename integral_type >
void testIntegral ( )

Definition at line 65 of file diff_std_test.cpp.

{
testIntegralReally<int>(1, 1);
testIntegralReally<int>(-1, 1);
testIntegralReally<int>(-1, -1);
testIntegralReally<int>(1, 0);
testIntegralReally<int>(-1, 0);
}
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.

{
floating_type a_b, b_a;
BaseDiffConfig config((double) precision);
diff_floating(a, b, a_b, b_a, config);
if (fabs(a - b) <= config.precision + std::numeric_limits<floating_type>::epsilon())
unit_assert(a_b == floating_type() && b_a == floating_type());
else
unit_assert(a_b == fabs(a - b) && b_a == fabs(a - b));
}
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().

{
if (os_) *os_ << "testCV()\n";
CV a, b;
a.URI = "uri";
a.id = "cvLabel";
a.fullName = "fullName";
a.version = "version";
b = a;
diff(a,b);
unit_assert(!diff);
a.version = "version_changed";
diff(a,b);
if (os_) *os_ << diff << endl;
unit_assert(diff);
unit_assert(diff.a_b.URI.empty() && diff.b_a.URI.empty());
unit_assert(diff.a_b.id.empty() && diff.b_a.id.empty());
unit_assert(diff.a_b.fullName.empty() && diff.b_a.fullName.empty());
unit_assert(diff.a_b.version == "version_changed");
unit_assert(diff.b_a.version == "version");
}
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().

{
if (os_) *os_ << "testUserParam()\n";
UserParam a, b;
a.name = "name";
a.value = "value";
a.type = "type";
b = a;
unit_assert(diff.a_b.empty());
unit_assert(diff.b_a.empty());
b.value = "value_changed";
if (os_) *os_ << diff << endl;
unit_assert(diff.a_b.name == "name");
unit_assert(diff.b_a.name == "name");
unit_assert(diff.a_b.value == "value");
unit_assert(diff.b_a.value == "value_changed");
unit_assert(diff.a_b.type.empty() && diff.b_a.type.empty());
unit_assert(diff.a_b.units == UO_second);
unit_assert(diff.b_a.units == UO_minute);
}
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().

{
if (os_) *os_ << "testCVParam()\n";
CVParam a, b, c;
a.value = "420";
c = b = a;
unit_assert(diff.a_b.empty());
unit_assert(diff.b_a.empty());
b.value = "value_changed";
diff(a,b);
if (os_) *os_ << diff << endl;
unit_assert(diff.a_b.value == "420");
unit_assert(diff.b_a.value == "value_changed");
c.value = "421"; // prove fix for bug that wouldn't catch diff in int values
diff(a,c);
if (os_) *os_ << diff << endl;
unit_assert(diff.a_b.value == "420");
unit_assert(diff.b_a.value == "421");
a.value = "4.1e5"; // make sure we handle scientific notation properly
c.value = "4.1";
diff(a,c);
if (os_) *os_ << diff << endl;
a.value = "4.1e5"; // make sure we handle scientific notation properly
c.value = "410000.0";
diff(a,c);
if (os_) *os_ << diff << endl;
a.value = "1a"; // make sure we aren't naive about things that start out as ints
c.value = "1b";
diff(a,c);
if (os_) *os_ << diff << endl;
}
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 main(), and test().

{
if (os_) *os_ << "testParamContainer()\n";
ParamGroupPtr pgp1(new ParamGroup("pg1"));
ParamGroupPtr pgp2(new ParamGroup("pg2"));
ParamGroupPtr pgp3(new ParamGroup("pg3"));
a.userParams.push_back(UserParam("common"));
b.userParams.push_back(UserParam("common"));
a.cvParams.push_back(MS_m_z);
b.cvParams.push_back(MS_m_z);
a.paramGroupPtrs.push_back(pgp1);
b.paramGroupPtrs.push_back(pgp1);
a.userParams.push_back(UserParam("different", "1"));
b.userParams.push_back(UserParam("different", "2"));
a.cvParams.push_back(MS_charge_state);
a.paramGroupPtrs.push_back(pgp2);
b.paramGroupPtrs.push_back(pgp3);
diff(a, b);
if (os_) *os_ << diff << endl;
unit_assert(diff.a_b.userParams.size() == 1);
unit_assert(diff.a_b.userParams[0] == UserParam("different","1"));
unit_assert(diff.b_a.userParams.size() == 1);
unit_assert(diff.b_a.userParams[0] == UserParam("different","2"));
unit_assert(diff.a_b.cvParams.size() == 1);
unit_assert(diff.a_b.cvParams[0] == MS_charge_state);
unit_assert(diff.b_a.cvParams.size() == 1);
unit_assert(diff.b_a.cvParams[0] == MS_peak_intensity);
unit_assert(diff.a_b.paramGroupPtrs.size() == 1);
unit_assert(diff.a_b.paramGroupPtrs[0]->id == "pg2");
unit_assert(diff.b_a.paramGroupPtrs.size() == 1);
unit_assert(diff.b_a.paramGroupPtrs[0]->id == "pg3");
}
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().

{
if (os_) *os_ << "testParamGroup()\n";
ParamGroup a("pg"), b("pg");
a.userParams.push_back(UserParam("common"));
b.userParams.push_back(UserParam("common"));
a.userParams.push_back(UserParam("different", "1"));
b.userParams.push_back(UserParam("different", "2"));
diff(a, b);
if (os_) *os_ << diff << endl;
unit_assert(diff.a_b.userParams.size() == 1);
unit_assert(diff.a_b.userParams[0] == UserParam("different","1"));
unit_assert(diff.b_a.userParams.size() == 1);
unit_assert(diff.b_a.userParams[0] == UserParam("different","2"));
}
void test ( )

Definition at line 275 of file diff_std_test.cpp.

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

{
testString("goober", "goober");
testString("goober", "goo");
testIntegral<int>();
testIntegral<short>();
testIntegral<long>();
testIntegral<unsigned int>();
testIntegral<unsigned short>();
testIntegral<unsigned long>();
testFloating<float>(1.f, 1.f, 1.e-6f);
testFloating<float>(1.f, 1.0000000001f, 1.e-6f);
testFloating<float>(1.f, 1.00001f, 1.e-6f);
testFloating<float>(4.f, 4.2f, 1.f);
testFloating<double>(1, 1, 1e-6);
testFloating<double>(1, 1.0000000001, 1e-6);
testFloating<double>(1, 1.00001, 1e-6);
testFloating<double>(4, 4.2, 1);
testCV();
}
int main ( int  argc,
char *  argv[] 
)

Definition at line 304 of file diff_std_test.cpp.

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

{
TEST_PROLOG(argc, argv)
try
{
if (argc>1 && !strcmp(argv[1],"-v")) os_ = &cout;
test();
}
catch (exception& e)
{
TEST_FAILED(e.what())
}
catch (...)
{
TEST_FAILED("Caught unknown exception.")
}
}

Variable Documentation

ostream* os_ = 0

Definition at line 35 of file diff_std_test.cpp.