ProteoWizard
TruncatedLorentzianParametersTest.cpp
Go to the documentation of this file.
1 //
2 // $Id$
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 
26 #include <boost/filesystem/operations.hpp>
28 #include <cstring>
29 
30 
31 using namespace pwiz::util;
32 using namespace pwiz::frequency;
33 
34 
35 ostream* os_ = 0;
36 
37 
39 {
41  tlp.f0 = 666;
42  tlp.alpha = complex<double>(100);
43  double shift = 666;
44  double scale = 50;
45 
46  ublas::vector<double> p = tlp.parameters(-shift, 1/scale);
50  unit_assert(p(TruncatedLorentzian::F0) == 0);
51 
52  ublas::vector<double> p2(4);
56  p2(TruncatedLorentzian::F0) = 1;
57 
58  tlp.parameters(p2, shift, scale);
59  unit_assert(tlp.alpha == 3.*scale);
60  unit_assert(tlp.tau == 0);
61  unit_assert(tlp.f0 == 1+shift);
62 }
63 
64 
65 void testIO()
66 {
68  tlp.T = 2;
69  tlp.tau = 3;
70  tlp.f0 = 666;
71  tlp.alpha = complex<double>(100);
72 
73  const char* filename = "TruncatedLorentzianTest.test.tlp";
74  tlp.write(filename);
75  TruncatedLorentzianParameters tlp2(filename);
76 
77  unit_assert(tlp2.T == tlp.T);
78  unit_assert(tlp2.tau == tlp.tau);
79  unit_assert(tlp2.f0 == tlp.f0);
80  unit_assert(tlp2.alpha == tlp.alpha);
81 
82  boost::filesystem::remove(filename);
83 }
84 
85 
87 {
90 
91  tlp.f0 = 666;
92  unit_assert(tlp != tlp2);
93  tlp2.f0 = 666;
94  unit_assert(tlp == tlp2);
95 }
96 
97 
99 {
101  tlp.T = 2;
102  tlp.tau = 3;
103  tlp.f0 = 666;
104  tlp.alpha = complex<double>(100);
105 
106  double start = 660;
107  double step = .2;
108  int count = 60;
109 
110  tlp.writeSamples(cout, start, step, count);
111 }
112 
113 
114 int main(int argc, char* argv[])
115 {
116  TEST_PROLOG(argc, argv)
117 
118  try
119  {
120  if (argc>1 && !strcmp(argv[1],"-v")) os_ = &cout;
121  if (os_) *os_ << "TruncatedLorentzianParametersTest\n";
123  testIO();
124  testEquality();
125  //testSamples();
126  }
127  catch (exception& e)
128  {
129  TEST_FAILED(e.what())
130  }
131  catch (...)
132  {
133  TEST_FAILED("Caught unknown exception.")
134  }
135 
137 }
138 
139 
pwiz::frequency
Definition: DerivativeTest.hpp:37
AlphaI
AlphaI
Definition: TruncatedLorentzian.hpp:43
pwiz::frequency::TruncatedLorentzianParameters::T
double T
Definition: TruncatedLorentzianParameters.hpp:39
testParameterConversion
void testParameterConversion()
Definition: TruncatedLorentzianParametersTest.cpp:38
pwiz::frequency::TruncatedLorentzianParameters::writeSamples
void writeSamples(std::ostream &os) const
write samples to stream
pwiz::frequency::TruncatedLorentzianParameters::tau
double tau
Definition: TruncatedLorentzianParameters.hpp:40
pwiz::util
Definition: almost_equal.hpp:33
TEST_EPILOG
#define TEST_EPILOG
Definition: unit.hpp:183
Tau
Tau
Definition: TruncatedLorentzian.hpp:43
Std.hpp
testEquality
void testEquality()
Definition: TruncatedLorentzianParametersTest.cpp:86
testSamples
void testSamples()
Definition: TruncatedLorentzianParametersTest.cpp:98
TruncatedLorentzianParameters.hpp
AlphaR
AlphaR
Definition: TruncatedLorentzian.hpp:43
TEST_FAILED
#define TEST_FAILED(x)
Definition: unit.hpp:177
TEST_PROLOG
#define TEST_PROLOG(argc, argv)
Definition: unit.hpp:175
pwiz::frequency::TruncatedLorentzianParameters::f0
double f0
Definition: TruncatedLorentzianParameters.hpp:42
pwiz::frequency::TruncatedLorentzianParameters::parameters
ublas::vector< double > parameters(double shift=0, std::complex< double > scale=1) const
returns parameters in format usable by TruncatedLorentzian class
ralab::base::stats::scale
void scale(InputIterator begin, InputIterator end, std::pair< typename std::iterator_traits< InputIterator >::value_type, typename std::iterator_traits< InputIterator >::value_type > &scaled, bool center=true, bool scale=true)
scale centers and/or scales all values from begin in to end.
Definition: scale.hpp:77
main
int main(int argc, char *argv[])
Definition: TruncatedLorentzianParametersTest.cpp:114
pwiz::frequency::TruncatedLorentzianParameters::alpha
std::complex< double > alpha
Definition: TruncatedLorentzianParameters.hpp:41
pwiz::frequency::TruncatedLorentzianParameters
struct for holding parameters for a Truncated Lorentzian function
Definition: TruncatedLorentzianParameters.hpp:38
os_
ostream * os_
Definition: TruncatedLorentzianParametersTest.cpp:35
unit.hpp
unit_assert
#define unit_assert(x)
Definition: unit.hpp:85
testIO
void testIO()
Definition: TruncatedLorentzianParametersTest.cpp:65
pwiz::frequency::TruncatedLorentzianParameters::write
void write(const std::string &filename) const
write out to file