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

Go to the source code of this file.

Functions

void testMZ ()
 
void testPPM ()
 
void testIsWithinTolerance ()
 
void testIO ()
 
void test ()
 
int main (int argc, char *argv[])
 

Variables

ostream * os_ = 0
 
const double epsilon_ = numeric_limits<double>::epsilon()
 

Function Documentation

◆ testMZ()

void testMZ ( )

Definition at line 40 of file MZToleranceTest.cpp.

41{
42 double x = 1000;
43 MZTolerance tolerance(.1);
44
45 x += tolerance;
47
48 x -= tolerance;
50
51 unit_assert_equal(x+tolerance, 1000.1, epsilon_);
52 unit_assert_equal(x-tolerance, 999.9, epsilon_);
53}
const double epsilon_
KernelTraitsBase< Kernel >::space_type::abscissa_type x
struct for expressing m/z tolerance in either amu or ppm
#define unit_assert_equal(x, y, epsilon)
Definition unit.hpp:99

References epsilon_, unit_assert_equal, and x.

Referenced by test().

◆ testPPM()

void testPPM ( )

Definition at line 56 of file MZToleranceTest.cpp.

57{
58 double x = 1000;
59 MZTolerance tolerance(5, MZTolerance::PPM);
60
61 x += tolerance;
62 unit_assert_equal(x, 1000.005, epsilon_);
63
64 x -= tolerance;
65 const double delta = 1000.005 * 5e-6; // a little more than .005
66 unit_assert_equal(x, 1000.005 - delta, epsilon_);
67
68 unit_assert_equal(1000+tolerance, 1000.005, epsilon_);
69 unit_assert_equal(1000-tolerance, 999.995, epsilon_);
70
71 unit_assert_equal(-1000+tolerance, -999.995, epsilon_);
72 unit_assert_equal(-1000-tolerance, -1000.005, epsilon_);
73}

References epsilon_, pwiz::chemistry::MZTolerance::PPM, unit_assert_equal, and x.

Referenced by test().

◆ testIsWithinTolerance()

void testIsWithinTolerance ( )

Definition at line 76 of file MZToleranceTest.cpp.

77{
78 MZTolerance fiveppm(5, MZTolerance::PPM);
79 unit_assert(isWithinTolerance(1000.001, 1000, fiveppm));
80 unit_assert(isWithinTolerance(999.997, 1000, fiveppm));
81 unit_assert(!isWithinTolerance(1000.01, 1000, fiveppm));
82 unit_assert(!isWithinTolerance(999.99, 1000, fiveppm));
83
84 MZTolerance delta(.01);
85 unit_assert(isWithinTolerance(1000.001, 1000, delta));
86 unit_assert(isWithinTolerance(999.999, 1000, delta));
87 unit_assert(!isWithinTolerance(1000.1, 1000, delta));
88 unit_assert(!isWithinTolerance(999.9, 1000, .01)); // automatic conversion
89}
PWIZ_API_DECL bool isWithinTolerance(double a, double b, const MZTolerance &tolerance)
returns true iff a is in (b-tolerance, b+tolerance)
#define unit_assert(x)
Definition unit.hpp:85

References pwiz::chemistry::isWithinTolerance(), pwiz::chemistry::MZTolerance::PPM, and unit_assert.

Referenced by test().

◆ testIO()

void testIO ( )

Definition at line 92 of file MZToleranceTest.cpp.

93{
94 if (os_) *os_ << "testIO()\n";
95
96 MZTolerance temp;
97 if (os_) *os_ << "temp: " << temp << endl;
98
99 MZTolerance fiveppm(5, MZTolerance::PPM);
100 MZTolerance blackbirds(4.20, MZTolerance::MZ);
101
102 {
103 ostringstream oss;
104 oss << fiveppm;
105 if (os_) *os_ << "fiveppm: " << oss.str() << endl;
106
107 {
108 istringstream iss(oss.str());
109 iss >> temp;
110 if (os_) *os_ << "temp: " << temp << endl;
111 unit_assert(temp == fiveppm);
112 unit_assert(temp != blackbirds);
113 }
114
115 {
116 istringstream iss("5.0 PPM");
117 iss >> temp;
118 if (os_) *os_ << "temp: " << temp << endl;
119 unit_assert(temp == fiveppm);
120 }
121
122 {
123 istringstream iss("5ppm");
124 iss >> temp;
125 if (os_) *os_ << "temp: " << temp << endl;
126 unit_assert(temp == fiveppm);
127 }
128 }
129
130 {
131 ostringstream oss;
132 oss << blackbirds;
133 if (os_) *os_ << "blackbirds: " << oss.str() << endl;
134
135 {
136 istringstream iss(oss.str());
137 iss >> temp;
138 if (os_) *os_ << "temp: " << temp << endl;
139 unit_assert(temp == blackbirds);
140 unit_assert(temp != fiveppm);
141 }
142
143 {
144 istringstream iss("4.2mz");
145 iss >> temp;
146 if (os_) *os_ << "temp: " << temp << endl;
147 unit_assert(temp == blackbirds);
148 }
149
150 {
151 istringstream iss("4.20 da");
152 iss >> temp;
153 if (os_) *os_ << "temp: " << temp << endl;
154 unit_assert(temp == blackbirds);
155 }
156
157 {
158 istringstream iss("4.2 DALTONS");
159 iss >> temp;
160 if (os_) *os_ << "temp: " << temp << endl;
161 unit_assert(temp == blackbirds);
162 }
163 }
164}
ostream * os_

References pwiz::chemistry::MZTolerance::MZ, os_, pwiz::chemistry::MZTolerance::PPM, and unit_assert.

Referenced by test().

◆ test()

void test ( )

Definition at line 167 of file MZToleranceTest.cpp.

168{
169 testMZ();
170 testPPM();
172 testIO();
173}
void testPPM()
void testIsWithinTolerance()
void testIO()
void testMZ()

References testIO(), testIsWithinTolerance(), testMZ(), and testPPM().

Referenced by main().

◆ main()

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

Definition at line 176 of file MZToleranceTest.cpp.

177{
178 TEST_PROLOG(argc, argv)
179
180 try
181 {
182 if (argc>1 && !strcmp(argv[1],"-v")) os_ = &cout;
183 test();
184 }
185 catch (exception& e)
186 {
187 TEST_FAILED(e.what())
188 }
189 catch (...)
190 {
191 TEST_FAILED("Caught unknown exception.")
192 }
193
195}
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

Definition at line 34 of file MZToleranceTest.cpp.

Referenced by main(), and testIO().

◆ epsilon_

const double epsilon_ = numeric_limits<double>::epsilon()

Definition at line 37 of file MZToleranceTest.cpp.

Referenced by testMZ(), and testPPM().