ProteoWizard
SampleDatumTest.cpp
Go to the documentation of this file.
1 //
2 // $Id: SampleDatumTest.cpp 4129 2012-11-20 00:05:37Z chambm $
3 //
4 //
5 // Original author: Darren Kessner <darren@proteowizard.org>
6 //
7 // Copyright 2006 Louis Warschaw Prostate Cancer Center
8 // Cedars Sinai Medical Center, Los Angeles, California 90048
9 //
10 // Licensed under the Apache License, Version 2.0 (the "License");
11 // you may not use this file except in compliance with the License.
12 // You may obtain a copy of the License at
13 //
14 // http://www.apache.org/licenses/LICENSE-2.0
15 //
16 // Unless required by applicable law or agreed to in writing, software
17 // distributed under the License is distributed on an "AS IS" BASIS,
18 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 // See the License for the specific language governing permissions and
20 // limitations under the License.
21 //
22 
23 
24 #include "SampleDatum.hpp"
27 #include <complex>
28 #include <cstring>
29 
30 
31 using namespace pwiz::util;
32 using namespace pwiz::data;
33 
34 
35 ostream* os_ = 0;
36 
37 
38 template <typename abscissa_type, typename ordinate_type>
39 void test()
40 {
42 
43  vector<sd_type> v;
44  v.push_back(sd_type(1,2));
45  v.push_back(sd_type(3,4));
46  v.push_back(sd_type(5,6));
47 
48  // write the pairs out to a stream
49  ostringstream oss;
50  copy(v.begin(), v.end(), ostream_iterator<sd_type>(oss, "\n"));
51  if (os_) *os_ << oss.str();
52 
53  // read them back in
54  vector<sd_type> w;
55  istringstream iss(oss.str());
56  copy(istream_iterator<sd_type>(iss), istream_iterator<sd_type>(), back_inserter(w));
57 
58  // compare the two vectors
59  unit_assert(v == w);
60 }
61 
62 
63 int main(int argc, char* argv[])
64 {
65  TEST_PROLOG(argc, argv)
66 
67  try
68  {
69  if (argc>1 && !strcmp(argv[1],"-v")) os_ = &cout;
70  if (os_) *os_ << "SampleDatumTest\n";
71 
72  test<int,int>();
73  test<double,double>();
74  test< double,complex<double> >();
75  test< complex<double>,complex<double> >();
76 
77  }
78  catch (exception& e)
79  {
80  TEST_FAILED(e.what())
81  }
82  catch (...)
83  {
84  TEST_FAILED("Caught unknown exception.")
85  }
86 
88 }
89 
90