source: trunk/test/data_weight_proxy_test.cc @ 1537

Last change on this file since 1537 was 1537, checked in by Peter, 13 years ago

refs #368 - redesign to solve some issues regarding mutable functionality in WeightedIterator?

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.3 KB
Line 
1// $Id: data_weight_proxy_test.cc 1537 2008-09-26 22:37:33Z peter $
2
3/*
4  Copyright (C) 2008 Peter Johansson
5
6  This file is part of the yat library, http://dev.thep.lu.se/yat
7
8  The yat library is free software; you can redistribute it and/or
9  modify it under the terms of the GNU General Public License as
10  published by the Free Software Foundation; either version 3 of the
11  License, or (at your option) any later version.
12
13  The yat library is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  General Public License for more details.
17
18  You should have received a copy of the GNU General Public License
19  along with yat. If not, see <http://www.gnu.org/licenses/>.
20*/
21
22#include "Suite.h"
23
24#include "yat/utility/DataWeight.h"
25#include "yat/utility/DataWeightProxy.h"
26
27namespace theplu {
28namespace yat {
29namespace test {
30  class ProxyHolder
31  {
32  public:
33    typedef utility::DataWeightProxy<double*, double*> Proxy;
34    ProxyHolder(Proxy& proxy)
35      : proxy_(proxy) {}
36
37    inline Proxy& operator()(void) { return proxy_; }
38    inline const Proxy& operator()(void) const 
39    { return proxy_; }
40  private:
41    Proxy& proxy_;
42  };
43}}}
44
45using namespace theplu::yat;
46
47int main( int argc, char* argv[])
48{ 
49  test::Suite suite(argc, argv);
50  suite.err() << "testing DataWeightProxy" << std::endl;
51
52  using utility::DataWeight;
53
54  typedef utility::DataWeightProxy<double*, double*> Proxy;
55
56  double x=1.2;
57  double w=3.14;
58  DataWeight xw(x, w);
59  Proxy proxy(&x,&w);
60  if (xw != proxy) {
61    suite.add(false);
62  }
63  if (proxy != xw) {
64    suite.add(false);
65  }
66
67  suite.err() << "testing conversion to DataWeight\n";
68  test::ProxyHolder holder(proxy);
69  const test::ProxyHolder const_holder(proxy);
70 
71  xw = holder();
72  xw = const_holder();
73
74  if (holder() != holder()) {
75    suite.add(false);
76  }
77  if (holder() != const_holder()) {
78    suite.add(false);
79  }
80
81  suite.err() << "testing assignment\n";
82  holder().data() = 1.0;
83  suite.add(suite.equal(holder().data(), 1.0));
84  holder().weight() = 1.0;
85  suite.add(suite.equal(holder().weight(), 1.0));
86
87  DataWeight xw2(3.14, 0.5);
88  holder() = xw2;
89  suite.add(suite.equal(holder().data(), 3.14));
90  suite.add(suite.equal(holder().weight(), 0.5));
91
92  DataWeight xw3;
93  xw3 = const_holder();
94  suite.add(suite.equal(xw3.data(), 3.14));
95  suite.add(suite.equal(xw3.weight(), 0.5));
96
97  return suite.return_value();
98}
Note: See TracBrowser for help on using the repository browser.