ProteoWizard
Classes | Functions | Variables
OrderedPairTest.cpp File Reference
#include "OrderedPair.hpp"
#include "pwiz/utility/misc/Std.hpp"
#include "pwiz/utility/misc/unit.hpp"
#include "boost/static_assert.hpp"

Go to the source code of this file.

Classes

struct  CustomPair
 

Functions

 BOOST_STATIC_ASSERT (sizeof(OrderedPair)==2 *sizeof(double))
 
void testContainer (const OrderedPairContainerRef &pairs)
 
void testArray ()
 
void testVectorDouble ()
 
void testVectorOrderedPair ()
 
void testVectorCustomPair ()
 
void testEquality ()
 
void testExtraction ()
 
void test ()
 
int main (int argc, char *argv[])
 

Variables

ostream * os_ = 0
 

Function Documentation

◆ BOOST_STATIC_ASSERT()

BOOST_STATIC_ASSERT ( sizeof(OrderedPair = =2 *sizeof(double))

◆ testContainer()

void testContainer ( const OrderedPairContainerRef pairs)

Definition at line 40 of file OrderedPairTest.cpp.

41{
42 // verify that pairs == { (1,2), (3,4), (5,6) }
43
44 // test size
45
46 if (os_)
47 {
48 copy(pairs.begin(), pairs.end(), ostream_iterator<OrderedPair>(*os_, " "));
49 *os_ << endl;
50 }
51
52 unit_assert(pairs.size() == 3);
53
54 // test iteration
55
57 unit_assert(it->x == 1);
58 unit_assert(it->y == 2);
59
60 ++it;
61 unit_assert(it->x == 3);
62 unit_assert(it->y == 4);
63
64 ++it;
65 unit_assert(it->x == 5);
66 unit_assert(it->y == 6);
67
68 // test random access
69
70 unit_assert(pairs[0].x == 1);
71 unit_assert(pairs[0].y == 2);
72 unit_assert(pairs[1].x == 3);
73 unit_assert(pairs[1].y == 4);
74 unit_assert(pairs[2].x == 5);
75 unit_assert(pairs[2].y == 6);
76
77 // test algorithms
78
79 vector<OrderedPair> v;
80 copy(pairs.begin(), pairs.end(), back_inserter(v));
81 unit_assert(v.size() == 3);
82 unit_assert(v[0].x == 1);
83 unit_assert(v[0].y == 2);
84 unit_assert(v[1].x == 3);
85 unit_assert(v[1].y == 4);
86 unit_assert(v[2].x == 5);
87 unit_assert(v[2].y == 6);
88}
KernelTraitsBase< Kernel >::space_type::abscissa_type x
KernelTraitsBase< Kernel >::space_type::ordinate_type y
ostream * os_
#define unit_assert(x)
Definition unit.hpp:85

References pwiz::math::OrderedPairContainerRef::begin(), pwiz::math::OrderedPairContainerRef::end(), os_, pwiz::math::OrderedPairContainerRef::size(), unit_assert, x, pwiz::math::OrderedPair::x, y, and pwiz::math::OrderedPair::y.

Referenced by testArray(), testVectorCustomPair(), testVectorDouble(), and testVectorOrderedPair().

◆ testArray()

void testArray ( )

Definition at line 91 of file OrderedPairTest.cpp.

92{
93 if (os_) *os_ << "testArray()\n";
94 double a[] = {1, 2, 3, 4, 5, 6};
95 OrderedPairContainerRef pairs(a, a+sizeof(a)/sizeof(double));
96 testContainer(pairs);
97}
void testContainer(const OrderedPairContainerRef &pairs)
wrapper class for accessing contiguous data as a container of OrderedPairs; note that it does not own...

References os_, and testContainer().

Referenced by test().

◆ testVectorDouble()

void testVectorDouble ( )

Definition at line 100 of file OrderedPairTest.cpp.

101{
102 if (os_) *os_ << "testVectorDouble()\n";
103 vector<double> v;
104 for (int i=1; i<=6; i++) v.push_back(i);
105 testContainer(v); // note automatic conversion: vector<double> -> OrderedPairContainerRef
106}

References os_, and testContainer().

Referenced by test().

◆ testVectorOrderedPair()

void testVectorOrderedPair ( )

Definition at line 109 of file OrderedPairTest.cpp.

110{
111 if (os_) *os_ << "testVectorOrderedPair()\n";
112 vector<OrderedPair> v;
113 v.push_back(OrderedPair(1,2));
114 v.push_back(OrderedPair(3,4));
115 v.push_back(OrderedPair(5,6));
116 testContainer(v); // note automatic conversion: vector<OrderedPair> -> OrderedPairContainerRef
117}

References os_, and testContainer().

Referenced by test().

◆ testVectorCustomPair()

void testVectorCustomPair ( )

Definition at line 125 of file OrderedPairTest.cpp.

126{
127 if (os_) *os_ << "testVectorCustomPair()\n";
128 vector<CustomPair> v;
129 v.push_back(CustomPair(1,2));
130 v.push_back(CustomPair(3,4));
131 v.push_back(CustomPair(5,6));
132 testContainer(v); // note automatic conversion: vector<CustomPair> -> OrderedPairContainerRef
133}

References os_, and testContainer().

Referenced by test().

◆ testEquality()

void testEquality ( )

Definition at line 136 of file OrderedPairTest.cpp.

137{
138 if (os_) *os_ << "testEquality()\n";
139 vector<OrderedPair> v;
140 v.push_back(OrderedPair(1,2));
141 v.push_back(OrderedPair(3,4));
142 v.push_back(OrderedPair(5,6));
143
144 vector<OrderedPair> w = v;
145
146 unit_assert(v == w);
147 w.push_back(OrderedPair(7,8));
148 unit_assert(v != w);
149 v.push_back(OrderedPair(7,9));
150 unit_assert(v != w);
151 v.back().y = w.back().y;
152 unit_assert(v == w);
153}

References os_, and unit_assert.

Referenced by test().

◆ testExtraction()

void testExtraction ( )

Definition at line 156 of file OrderedPairTest.cpp.

157{
158 vector<OrderedPair> v;
159 istringstream iss("(420,666) (421,667)");
160 copy(istream_iterator<OrderedPair>(iss), istream_iterator<OrderedPair>(), back_inserter(v));
161 unit_assert(v.size() == 2);
162 unit_assert(v[0].x == 420);
163 unit_assert(v[0].y == 666);
164 unit_assert(v[1].x == 421);
165 unit_assert(v[1].y == 667);
166}

References unit_assert, x, and y.

Referenced by test().

◆ test()

void test ( )

Definition at line 169 of file OrderedPairTest.cpp.

170{
171 testArray();
175 testEquality();
177}
void testVectorCustomPair()
void testExtraction()
void testVectorOrderedPair()
void testVectorDouble()
void testEquality()
void testArray()

References testArray(), testEquality(), testExtraction(), testVectorCustomPair(), testVectorDouble(), and testVectorOrderedPair().

Referenced by main().

◆ main()

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

Definition at line 180 of file OrderedPairTest.cpp.

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