source: trunk/test/data_weight_proxy_test.cc @ 1535

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

fixing DataWeightProxy?

  • 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 1535 2008-09-25 19:01:48Z 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    ProxyHolder(utility::DataWeightProxy& proxy)
34      : proxy_(proxy) {}
35
36    inline utility::DataWeightProxy& operator()(void) { return proxy_; }
37    inline const utility::DataWeightProxy& operator()(void) const 
38    { return proxy_; }
39  private:
40    utility::DataWeightProxy& proxy_;
41  };
42}}}
43
44using namespace theplu::yat;
45
46int main( int argc, char* argv[])
47{ 
48  test::Suite suite(argc, argv);
49  suite.err() << "testing DataWeightProxy" << std::endl;
50
51  using utility::DataWeightProxy;
52  using utility::DataWeight;
53
54  double x=1.2;
55  double w=3.14;
56  DataWeight xw(x, w);
57  DataWeightProxy proxy(x,w);
58  if (xw != proxy) {
59    suite.add(false);
60  }
61  if (proxy != xw) {
62    suite.add(false);
63  }
64
65  suite.err() << "testing conversion to DataWeight\n";
66  test::ProxyHolder holder(proxy);
67  const test::ProxyHolder const_holder(proxy);
68 
69  xw = holder();
70  xw = const_holder();
71
72  if (holder() != holder()) {
73    suite.add(false);
74  }
75  if (holder() != const_holder()) {
76    suite.add(false);
77  }
78
79  suite.err() << "testing assignment\n";
80  holder().data() = 1.0;
81  suite.add(suite.equal(holder().data(), 1.0));
82  holder().weight() = 1.0;
83  suite.add(suite.equal(holder().weight(), 1.0));
84
85  DataWeight xw2(3.14, 0.5);
86  holder() = xw2;
87  suite.add(suite.equal(holder().data(), 3.14));
88  suite.add(suite.equal(holder().weight(), 0.5));
89
90  DataWeight xw3;
91  xw3 = const_holder();
92  suite.add(suite.equal(xw3.data(), 3.14));
93  suite.add(suite.equal(xw3.weight(), 0.5));
94
95  return suite.return_value();
96}
Note: See TracBrowser for help on using the repository browser.