source: trunk/test/data_weight_proxy_test.cc @ 2122

Last change on this file since 2122 was 2122, checked in by Peter, 12 years ago

Remove implementation of operator==(DataWeightProxy?, DataWeightProxy?)
and rather rely on implicit conversion to DataWeight? and its
operator. This implies the behavior changes but that change is needed
because the previous behavior was very unexpected.

closes #578

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.7 KB
Line 
1// $Id: data_weight_proxy_test.cc 2122 2009-12-19 14:30:55Z peter $
2
3/*
4  Copyright (C) 2008, 2009 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 get_copy(void) { return proxy_; }
38    inline Proxy& operator()(void) { return proxy_; }
39    inline const Proxy& operator()(void) const 
40    { return proxy_; }
41  private:
42    Proxy& proxy_;
43  };
44}}}
45
46using namespace theplu::yat;
47
48int main( int argc, char* argv[])
49{ 
50  test::Suite suite(argc, argv);
51  suite.err() << "testing DataWeightProxy" << std::endl;
52
53  using utility::DataWeight;
54
55  typedef utility::DataWeightProxy<double*, double*> Proxy;
56
57  double x=1.2;
58  double w=3.14;
59  DataWeight xw(x, w);
60  Proxy proxy(&x,&w);
61  if (xw != proxy) {
62    suite.add(false);
63  }
64  if (proxy != xw) {
65    suite.add(false);
66  }
67
68  suite.err() << "testing conversion to DataWeight\n";
69  test::ProxyHolder holder(proxy);
70  const test::ProxyHolder const_holder(proxy);
71 
72  xw = holder();
73  xw = const_holder();
74
75  if (holder() != holder()) {
76    suite.add(false);
77  }
78  if (holder() == holder())
79    suite.add(true);
80  else
81    suite.add(false);
82  if (holder() != const_holder()) {
83    suite.add(false);
84  }
85  if (holder() == const_holder())
86    suite.add(true);
87  else
88    suite.add(false);
89
90  suite.err() << "testing assignment\n";
91  holder().data() = 1.0;
92  suite.add(suite.equal(holder().data(), 1.0));
93  holder().weight() = 1.0;
94  suite.add(suite.equal(holder().weight(), 1.0));
95
96  DataWeight xw2(3.14, 0.5);
97  holder() = xw2;
98  suite.add(suite.equal(holder().data(), 3.14));
99  suite.add(suite.equal(holder().weight(), 0.5));
100
101  DataWeight xw3;
102  xw3 = const_holder();
103  suite.add(suite.equal(xw3.data(), 3.14));
104  suite.add(suite.equal(xw3.weight(), 0.5));
105
106  DataWeight xw4(1.602, 1);
107  holder.get_copy() = xw4;
108  suite.add(suite.equal(holder().data(), 1.602));
109  suite.add(suite.equal(holder().weight(), 1));
110
111  return suite.return_value();
112}
Note: See TracBrowser for help on using the repository browser.