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
31using namespace pwiz::util;
32using namespace pwiz::frequency;
33
34
35ostream* 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);
47 unit_assert(p(TruncatedLorentzian::AlphaR) == 2);
48 unit_assert(p(TruncatedLorentzian::AlphaI) == 0);
49 unit_assert(p(TruncatedLorentzian::Tau) == 1);
50 unit_assert(p(TruncatedLorentzian::F0) == 0);
51
52 ublas::vector<double> p2(4);
53 p2(TruncatedLorentzian::AlphaR) = 3;
54 p2(TruncatedLorentzian::AlphaI) = 0;
55 p2(TruncatedLorentzian::Tau) = 0;
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
65void 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
114int 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
int main(int argc, char *argv[])
struct for holding parameters for a Truncated Lorentzian function
void writeSamples(std::ostream &os) const
write samples to stream
void write(const std::string &filename) const
write out to file
ublas::vector< double > parameters(double shift=0, std::complex< double > scale=1) const
returns parameters in format usable by TruncatedLorentzian class
#define unit_assert(x)
Definition unit.hpp:85
#define TEST_EPILOG
Definition unit.hpp:183
#define TEST_FAILED(x)
Definition unit.hpp:177
#define TEST_PROLOG(argc, argv)
Definition unit.hpp:175