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

{
// verify that pairs == { (1,2), (3,4), (5,6) }
// test size
if (os_)
{
copy(pairs.begin(), pairs.end(), ostream_iterator<OrderedPair>(*os_, " "));
*os_ << endl;
}
unit_assert(pairs.size() == 3);
// test iteration
unit_assert(it->x == 1);
unit_assert(it->y == 2);
++it;
unit_assert(it->x == 3);
unit_assert(it->y == 4);
++it;
unit_assert(it->x == 5);
unit_assert(it->y == 6);
// test random access
unit_assert(pairs[0].x == 1);
unit_assert(pairs[0].y == 2);
unit_assert(pairs[1].x == 3);
unit_assert(pairs[1].y == 4);
unit_assert(pairs[2].x == 5);
unit_assert(pairs[2].y == 6);
// test algorithms
vector<OrderedPair> v;
copy(pairs.begin(), pairs.end(), back_inserter(v));
unit_assert(v.size() == 3);
unit_assert(v[0].x == 1);
unit_assert(v[0].y == 2);
unit_assert(v[1].x == 3);
unit_assert(v[1].y == 4);
unit_assert(v[2].x == 5);
unit_assert(v[2].y == 6);
}
void testArray ( )

Definition at line 95 of file OrderedPairTest.cpp.

References os_, and testContainer().

{
if (os_) *os_ << "testArray()\n";
double a[] = {1, 2, 3, 4, 5, 6};
OrderedPairContainerRef pairs(a, a+sizeof(a)/sizeof(double));
testContainer(pairs);
}
void testVectorDouble ( )

Definition at line 104 of file OrderedPairTest.cpp.

References os_, and testContainer().

Referenced by test().

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

Definition at line 113 of file OrderedPairTest.cpp.

References os_, and testContainer().

Referenced by test().

{
if (os_) *os_ << "testVectorOrderedPair()\n";
vector<OrderedPair> v;
v.push_back(OrderedPair(1,2));
v.push_back(OrderedPair(3,4));
v.push_back(OrderedPair(5,6));
testContainer(v); // note automatic conversion: vector<OrderedPair> -> OrderedPairContainerRef
}
void testVectorCustomPair ( )

Definition at line 129 of file OrderedPairTest.cpp.

References os_, and testContainer().

Referenced by test().

{
if (os_) *os_ << "testVectorCustomPair()\n";
vector<CustomPair> v;
v.push_back(CustomPair(1,2));
v.push_back(CustomPair(3,4));
v.push_back(CustomPair(5,6));
testContainer(v); // note automatic conversion: vector<CustomPair> -> OrderedPairContainerRef
}
void testEquality ( )

Definition at line 140 of file OrderedPairTest.cpp.

References os_, and unit_assert.

{
if (os_) *os_ << "testEquality()\n";
vector<OrderedPair> v;
v.push_back(OrderedPair(1,2));
v.push_back(OrderedPair(3,4));
v.push_back(OrderedPair(5,6));
vector<OrderedPair> w = v;
unit_assert(v == w);
w.push_back(OrderedPair(7,8));
unit_assert(v != w);
v.push_back(OrderedPair(7,9));
unit_assert(v != w);
v.back().y = w.back().y;
unit_assert(v == w);
}
void testExtraction ( )

Definition at line 160 of file OrderedPairTest.cpp.

References unit_assert, x, and y.

Referenced by test().

{
vector<OrderedPair> v;
istringstream iss("(420,666) (421,667)");
copy(istream_iterator<OrderedPair>(iss), istream_iterator<OrderedPair>(), back_inserter(v));
unit_assert(v.size() == 2);
unit_assert(v[0].x == 420);
unit_assert(v[0].y == 666);
unit_assert(v[1].x == 421);
unit_assert(v[1].y == 667);
}
void test ( )
int main ( int  argc,
char *  argv[] 
)

Definition at line 184 of file OrderedPairTest.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 38 of file OrderedPairTest.cpp.