ProteoWizard
WhittakerSmootherTest.cpp
Go to the documentation of this file.
1//
2// $Id$
3//
4//
5// Original author: Matt Chambers <matt.chambers <a.t> vanderbilt.edu>
6//
7// Copyright 2008 Spielberg Family Center for Applied Proteomics
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 "WhittakerSmoother.hpp"
27
28using namespace pwiz::util;
29using namespace pwiz::analysis;
30
31
32ostream* os_ = 0;
33
34
35const double testArrayX[] =
36{
37 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
38 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28,
39 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42,
40 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56
41};
42
43const double testArrayY[] =
44{
45 1, 15, 29, 20, 10, 40, 1, 50, 3, 40, 3, 25, 23, 90,
46 1, 15, 29, 20, 10, 40, 1, 50, 3, 40, 3, 25, 23, 90,
47 1, 15, 29, 20, 10, 40, 1, 50, 3, 40, 3, 25, 23, 90,
48 1, 15, 29, 20, 10, 40, 1, 50, 3, 40, 3, 25, 23, 90
49};
50
51
52void test()
53{
54 // test that invalid value exceptions are thrown
55
56 // lambda too low
58 "[WhittakerSmoother::ctor()] Invalid value for lamda coefficient; valid range is [2, infinity)");
59
60 WhittakerSmoother(100001); // lambda is valid up to numeric limits
61
62 vector<double> testX(testArrayX, testArrayX+(14*4));
63 vector<double> testY(testArrayY, testArrayY+(14*4));
64
65 if (os_)
66 {
67 *os_ << "Unsmoothed data (" << testY.size() << "):\t";
68 copy(testY.begin(), testY.end(), ostream_iterator<double>(*os_, "\t"));
69 *os_ << endl;
70 }
71
72 WhittakerSmoother smoother(10);
73 vector<double> smoothedX, smoothedY;
74 smoother.smooth(testX, testY, smoothedX, smoothedY);
75
76 if (os_)
77 {
78 *os_ << "Smoothed data (" << smoothedY.size() << "):\t";
79 copy(smoothedY.begin(), smoothedY.end(), ostream_iterator<double>(*os_, "\t"));
80 *os_ << endl;
81 }
82
83 // smoothed data should be same size as the unsmoothed data
84 //unit_assert(smoothData.size() == testY.size());
85
86 // TODO: add output testing
87}
88
89
90int main(int argc, char* argv[])
91{
92 TEST_PROLOG(argc, argv)
93
94 try
95 {
96 if (argc>1 && !strcmp(argv[1],"-v")) os_ = &cout;
97 test();
98 }
99 catch (exception& e)
100 {
101 TEST_FAILED(e.what())
102 }
103 catch (...)
104 {
105 TEST_FAILED("Caught unknown exception.")
106 }
107
109}
int main(int argc, char *argv[])
const double testArrayY[]
ostream * os_
void test()
const double testArrayX[]
virtual void smooth(const std::vector< double > &x, const std::vector< double > &y, std::vector< double > &xSmoothed, std::vector< double > &ySmoothed)
smooth y values to existing vectors using Whittaker algorithm; note: in the case of sparse vectors,...
#define TEST_EPILOG
Definition unit.hpp:183
#define TEST_FAILED(x)
Definition unit.hpp:177
#define unit_assert_throws_what(x, exception, whatStr)
Definition unit.hpp:119
#define TEST_PROLOG(argc, argv)
Definition unit.hpp:175