ProteoWizard
Classes | Functions | Variables
OrderedPairTest.cpp File Reference
#include "OrderedPair.hpp"
#include "pwiz/utility/misc/unit.hpp"
#include "boost/static_assert.hpp"
#include <iostream>
#include <algorithm>
#include <iterator>
#include <cstring>

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 ( sizeof(OrderedPair = =2 *sizeof(double))
void testContainer ( const OrderedPairContainerRef pairs)

Definition at line 44 of file OrderedPairTest.cpp.

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

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

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

Definition at line 95 of file OrderedPairTest.cpp.

References os_, and testContainer().

Referenced by test().

96 {
97  if (os_) *os_ << "testArray()\n";
98  double a[] = {1, 2, 3, 4, 5, 6};
99  OrderedPairContainerRef pairs(a, a+sizeof(a)/sizeof(double));
100  testContainer(pairs);
101 }
ostream * os_
wrapper class for accessing contiguous data as a container of OrderedPairs; note that it does not own...
Definition: OrderedPair.hpp:83
void testContainer(const OrderedPairContainerRef &pairs)
void testVectorDouble ( )

Definition at line 104 of file OrderedPairTest.cpp.

References os_, and testContainer().

Referenced by test().

105 {
106  if (os_) *os_ << "testVectorDouble()\n";
107  vector<double> v;
108  for (int i=1; i<=6; i++) v.push_back(i);
109  testContainer(v); // note automatic conversion: vector<double> -> OrderedPairContainerRef
110 }
ostream * os_
void testContainer(const OrderedPairContainerRef &pairs)
void testVectorOrderedPair ( )

Definition at line 113 of file OrderedPairTest.cpp.

References os_, and testContainer().

Referenced by test().

114 {
115  if (os_) *os_ << "testVectorOrderedPair()\n";
116  vector<OrderedPair> v;
117  v.push_back(OrderedPair(1,2));
118  v.push_back(OrderedPair(3,4));
119  v.push_back(OrderedPair(5,6));
120  testContainer(v); // note automatic conversion: vector<OrderedPair> -> OrderedPairContainerRef
121 }
ostream * os_
void testContainer(const OrderedPairContainerRef &pairs)
void testVectorCustomPair ( )

Definition at line 129 of file OrderedPairTest.cpp.

References os_, and testContainer().

Referenced by test().

130 {
131  if (os_) *os_ << "testVectorCustomPair()\n";
132  vector<CustomPair> v;
133  v.push_back(CustomPair(1,2));
134  v.push_back(CustomPair(3,4));
135  v.push_back(CustomPair(5,6));
136  testContainer(v); // note automatic conversion: vector<CustomPair> -> OrderedPairContainerRef
137 }
ostream * os_
void testContainer(const OrderedPairContainerRef &pairs)
void testEquality ( )

Definition at line 140 of file OrderedPairTest.cpp.

References os_, and unit_assert.

141 {
142  if (os_) *os_ << "testEquality()\n";
143  vector<OrderedPair> v;
144  v.push_back(OrderedPair(1,2));
145  v.push_back(OrderedPair(3,4));
146  v.push_back(OrderedPair(5,6));
147 
148  vector<OrderedPair> w = v;
149 
150  unit_assert(v == w);
151  w.push_back(OrderedPair(7,8));
152  unit_assert(v != w);
153  v.push_back(OrderedPair(7,9));
154  unit_assert(v != w);
155  v.back().y = w.back().y;
156  unit_assert(v == w);
157 }
ostream * os_
#define unit_assert(x)
Definition: unit.hpp:82
void testExtraction ( )

Definition at line 160 of file OrderedPairTest.cpp.

References unit_assert, x, and y.

Referenced by test().

161 {
162  vector<OrderedPair> v;
163  istringstream iss("(420,666) (421,667)");
164  copy(istream_iterator<OrderedPair>(iss), istream_iterator<OrderedPair>(), back_inserter(v));
165  unit_assert(v.size() == 2);
166  unit_assert(v[0].x == 420);
167  unit_assert(v[0].y == 666);
168  unit_assert(v[1].x == 421);
169  unit_assert(v[1].y == 667);
170 }
KernelTraitsBase< Kernel >::space_type::abscissa_type x
KernelTraitsBase< Kernel >::space_type::ordinate_type y
#define unit_assert(x)
Definition: unit.hpp:82
void test ( )

Definition at line 173 of file OrderedPairTest.cpp.

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

174 {
175  testArray();
179  testEquality();
180  testExtraction();
181 }
void testVectorOrderedPair()
void testVectorCustomPair()
void testExtraction()
void testVectorDouble()
void testArray()
int main ( int  argc,
char *  argv[] 
)

Definition at line 184 of file OrderedPairTest.cpp.

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

185 {
186  TEST_PROLOG(argc, argv)
187 
188  try
189  {
190  if (argc>1 && !strcmp(argv[1],"-v")) os_ = &cout;
191  test();
192  }
193  catch (exception& e)
194  {
195  TEST_FAILED(e.what())
196  }
197  catch (...)
198  {
199  TEST_FAILED("Caught unknown exception.")
200  }
201 
203 }
ostream * os_
#define TEST_EPILOG
Definition: unit.hpp:166
#define TEST_FAILED(x)
Definition: unit.hpp:160
#define TEST_PROLOG(argc, argv)
Definition: unit.hpp:158

Variable Documentation

ostream* os_ = 0

Definition at line 38 of file OrderedPairTest.cpp.