ProteoWizard
difftest.cpp
Go to the documentation of this file.
1//
2// $Id$
3//
4//
5// Original author: Witold Wolski <wewolski@gmail.com>
6//
7// Copyright : ETH Zurich
8//
9// Licensed under the Apache License, Version 2.0 (the "License");
10// you may not use this file except in compliance with the License.
11// You may obtain a copy of the License at
12//
13// http://www.apache.org/licenses/LICENSE-2.0
14//
15// Unless required by applicable law or agreed to in writing, software
16// distributed under the License is distributed on an "AS IS" BASIS,
17// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18// See the License for the specific language governing permissions and
19// limitations under the License.
20//
21
22#include "gtest/gtest.hpp"
23#include "base/base/diff.hpp"
25
26namespace {
27
28
29 void testdiff(){
30
31 double epsilon = 0.00001;
32 std::vector<double> tmp, res, ref; // res- result, ref-reference
33 double numbers_[] = { 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
34 const int N = sizeof( numbers_ ) / sizeof( double );
35 tmp.assign( numbers_ , numbers_ + N ) ;
36 ref.assign( 10 , 1 );
37
38 ralab::base::base::diff(tmp.begin() , tmp.end() , std::back_inserter(res) , 1 );
39 bool bb = std::equal( res.begin(), res.end(), ref.begin(), ralab::base::resample::DaCompFunctor<double>(epsilon) ) ;
40 ASSERT_TRUE( bb );
41
42 res.clear();
43 ref.assign(10,2);
44 ralab::base::base::diff(tmp.begin() , tmp.end() , std::back_inserter(res) , 2 );
45 bb = std::equal( res.begin(), res.end(), ref.begin(), ralab::base::resample::DaCompFunctor<double>(epsilon) ) ;
46 ASSERT_TRUE( bb );
47
48 std::vector<double> xxx(tmp);
49 std::transform( xxx.begin() , xxx.end() , xxx.begin(), xxx.begin() , std::multiplies<double>() );
50
51 std::vector<double>::iterator itmp =
53 (
54 xxx.begin(),
55 xxx.end(),
56 3,
57 3
58 );
59 //long long xt = std::distance(xxx.begin(),itmp);
60 //xt;
61 unit_assert_equal( *xxx.begin(),0., epsilon);
62 nit_assert(std::distance(xxx.begin(),itmp) ,1);
63 }
64}//end namespace
65
66int main(int argc, char **argv) {
67 testdiff();
68}
N
Definition Chemistry.hpp:80
const double epsilon
Definition DiffTest.cpp:41
OutputIterator diff(InputIterator begin, InputIterator end, OutputIterator destBegin, TN lag)
lagged differences
Definition diff.hpp:58
Da Comparator - constant mass error.
#define unit_assert_equal(x, y, epsilon)
Definition unit.hpp:99
int main(int argc, char **argv)
Definition difftest.cpp:66