source: branches/0.6-stable/test/data_weight_proxy_test.cc @ 2174

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

fixes #597. Testing with mutable forward iterator becase could not find any trivial iterator archetype in boost (although it is documented).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.0 KB
Line 
1// $Id: data_weight_proxy_test.cc 2174 2010-01-30 14:52:38Z 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
27#include <boost/concept_archetype.hpp>
28
29namespace theplu {
30namespace yat {
31namespace test {
32  class ProxyHolder
33  {
34  public:
35    typedef utility::DataWeightProxy<double*, double*> Proxy;
36    ProxyHolder(Proxy& proxy)
37      : proxy_(proxy) {}
38
39    inline Proxy get_copy(void) { return proxy_; }
40    inline Proxy& operator()(void) { return proxy_; }
41    inline const Proxy& operator()(void) const 
42    { return proxy_; }
43  private:
44    Proxy& proxy_;
45  };
46}}}
47
48using namespace theplu::yat;
49
50int main( int argc, char* argv[])
51{ 
52  test::Suite suite(argc, argv);
53  suite.err() << "testing DataWeightProxy" << std::endl;
54
55  using utility::DataWeight;
56
57  typedef utility::DataWeightProxy<double*, double*> Proxy;
58
59  double x=1.2;
60  double w=3.14;
61  DataWeight xw(x, w);
62  Proxy proxy(&x,&w);
63  if (xw != proxy) {
64    suite.add(false);
65  }
66  if (proxy != xw) {
67    suite.add(false);
68  }
69
70  suite.err() << "testing conversion to DataWeight\n";
71  test::ProxyHolder holder(proxy);
72  const test::ProxyHolder const_holder(proxy);
73 
74  xw = holder();
75  xw = const_holder();
76
77  if (holder() != holder()) {
78    suite.add(false);
79  }
80  if (holder() == holder())
81    suite.add(true);
82  else
83    suite.add(false);
84  if (holder() != const_holder()) {
85    suite.add(false);
86  }
87  if (holder() == const_holder())
88    suite.add(true);
89  else
90    suite.add(false);
91
92  suite.err() << "testing assignment\n";
93  holder().data() = 1.0;
94  suite.add(suite.equal(holder().data(), 1.0));
95  holder().weight() = 1.0;
96  suite.add(suite.equal(holder().weight(), 1.0));
97
98  DataWeight xw2(3.14, 0.5);
99  holder() = xw2;
100  suite.add(suite.equal(holder().data(), 3.14));
101  suite.add(suite.equal(holder().weight(), 0.5));
102
103  DataWeight xw3;
104  xw3 = const_holder();
105  suite.add(suite.equal(xw3.data(), 3.14));
106  suite.add(suite.equal(xw3.weight(), 0.5));
107
108  DataWeight xw4(1.602, 1);
109  holder.get_copy() = xw4;
110  suite.add(suite.equal(holder().data(), 1.602));
111  suite.add(suite.equal(holder().weight(), 1));
112
113  // do not run compile tests
114  if (false) {
115    typedef boost::mutable_trivial_iterator_archetype<double> iterator;
116    iterator iter;
117    utility::DataWeightProxy<iterator, iterator> proxy(iter, iter);
118    double x = proxy.data();
119    x = proxy.weight();
120    proxy.data() = proxy.weight() = 0.0;
121  }
122
123  return suite.return_value();
124}
Note: See TracBrowser for help on using the repository browser.