1533 |
25 Sep 08 |
peter |
// $Id$ |
1533 |
25 Sep 08 |
peter |
2 |
|
1533 |
25 Sep 08 |
peter |
3 |
/* |
4359 |
23 Aug 23 |
peter |
Copyright (C) 2008, 2009, 2010, 2012, 2013, 2014 Peter Johansson |
1533 |
25 Sep 08 |
peter |
5 |
|
1533 |
25 Sep 08 |
peter |
This file is part of the yat library, http://dev.thep.lu.se/yat |
1533 |
25 Sep 08 |
peter |
7 |
|
1533 |
25 Sep 08 |
peter |
The yat library is free software; you can redistribute it and/or |
1533 |
25 Sep 08 |
peter |
modify it under the terms of the GNU General Public License as |
1533 |
25 Sep 08 |
peter |
published by the Free Software Foundation; either version 3 of the |
1533 |
25 Sep 08 |
peter |
License, or (at your option) any later version. |
1533 |
25 Sep 08 |
peter |
12 |
|
1533 |
25 Sep 08 |
peter |
The yat library is distributed in the hope that it will be useful, |
1533 |
25 Sep 08 |
peter |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
1533 |
25 Sep 08 |
peter |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
1533 |
25 Sep 08 |
peter |
General Public License for more details. |
1533 |
25 Sep 08 |
peter |
17 |
|
1533 |
25 Sep 08 |
peter |
You should have received a copy of the GNU General Public License |
1533 |
25 Sep 08 |
peter |
along with yat. If not, see <http://www.gnu.org/licenses/>. |
1533 |
25 Sep 08 |
peter |
20 |
*/ |
1533 |
25 Sep 08 |
peter |
21 |
|
2881 |
18 Nov 12 |
peter |
22 |
#include <config.h> |
2881 |
18 Nov 12 |
peter |
23 |
|
1533 |
25 Sep 08 |
peter |
24 |
#include "Suite.h" |
1533 |
25 Sep 08 |
peter |
25 |
|
1533 |
25 Sep 08 |
peter |
26 |
#include "yat/utility/DataWeight.h" |
1533 |
25 Sep 08 |
peter |
27 |
#include "yat/utility/DataWeightProxy.h" |
1533 |
25 Sep 08 |
peter |
28 |
|
2202 |
21 Feb 10 |
peter |
29 |
#include <boost/concept_archetype.hpp> |
2202 |
21 Feb 10 |
peter |
30 |
|
1535 |
25 Sep 08 |
peter |
31 |
namespace theplu { |
1535 |
25 Sep 08 |
peter |
32 |
namespace yat { |
1535 |
25 Sep 08 |
peter |
33 |
namespace test { |
1535 |
25 Sep 08 |
peter |
34 |
class ProxyHolder |
1535 |
25 Sep 08 |
peter |
35 |
{ |
1535 |
25 Sep 08 |
peter |
36 |
public: |
1537 |
26 Sep 08 |
peter |
37 |
typedef utility::DataWeightProxy<double*, double*> Proxy; |
1537 |
26 Sep 08 |
peter |
38 |
ProxyHolder(Proxy& proxy) |
1535 |
25 Sep 08 |
peter |
39 |
: proxy_(proxy) {} |
1535 |
25 Sep 08 |
peter |
40 |
|
1538 |
27 Sep 08 |
peter |
41 |
inline Proxy get_copy(void) { return proxy_; } |
1537 |
26 Sep 08 |
peter |
42 |
inline Proxy& operator()(void) { return proxy_; } |
4200 |
19 Aug 22 |
peter |
43 |
inline const Proxy& operator()(void) const |
1535 |
25 Sep 08 |
peter |
44 |
{ return proxy_; } |
1535 |
25 Sep 08 |
peter |
45 |
private: |
1537 |
26 Sep 08 |
peter |
46 |
Proxy& proxy_; |
1535 |
25 Sep 08 |
peter |
47 |
}; |
1535 |
25 Sep 08 |
peter |
48 |
}}} |
1535 |
25 Sep 08 |
peter |
49 |
|
1533 |
25 Sep 08 |
peter |
50 |
using namespace theplu::yat; |
1533 |
25 Sep 08 |
peter |
51 |
|
1533 |
25 Sep 08 |
peter |
52 |
int main( int argc, char* argv[]) |
4200 |
19 Aug 22 |
peter |
53 |
{ |
1533 |
25 Sep 08 |
peter |
54 |
test::Suite suite(argc, argv); |
1533 |
25 Sep 08 |
peter |
55 |
suite.err() << "testing DataWeightProxy" << std::endl; |
1533 |
25 Sep 08 |
peter |
56 |
|
1535 |
25 Sep 08 |
peter |
57 |
using utility::DataWeight; |
1533 |
25 Sep 08 |
peter |
58 |
|
1537 |
26 Sep 08 |
peter |
59 |
typedef utility::DataWeightProxy<double*, double*> Proxy; |
1537 |
26 Sep 08 |
peter |
60 |
|
1533 |
25 Sep 08 |
peter |
61 |
double x=1.2; |
1535 |
25 Sep 08 |
peter |
62 |
double w=3.14; |
1535 |
25 Sep 08 |
peter |
63 |
DataWeight xw(x, w); |
1537 |
26 Sep 08 |
peter |
64 |
Proxy proxy(&x,&w); |
1535 |
25 Sep 08 |
peter |
65 |
if (xw != proxy) { |
1535 |
25 Sep 08 |
peter |
66 |
suite.add(false); |
1535 |
25 Sep 08 |
peter |
67 |
} |
1535 |
25 Sep 08 |
peter |
68 |
if (proxy != xw) { |
1535 |
25 Sep 08 |
peter |
69 |
suite.add(false); |
1535 |
25 Sep 08 |
peter |
70 |
} |
1533 |
25 Sep 08 |
peter |
71 |
|
1535 |
25 Sep 08 |
peter |
72 |
suite.err() << "testing conversion to DataWeight\n"; |
1535 |
25 Sep 08 |
peter |
73 |
test::ProxyHolder holder(proxy); |
1535 |
25 Sep 08 |
peter |
74 |
const test::ProxyHolder const_holder(proxy); |
4200 |
19 Aug 22 |
peter |
75 |
|
1535 |
25 Sep 08 |
peter |
76 |
xw = holder(); |
1535 |
25 Sep 08 |
peter |
77 |
xw = const_holder(); |
1535 |
25 Sep 08 |
peter |
78 |
|
1535 |
25 Sep 08 |
peter |
79 |
if (holder() != holder()) { |
1535 |
25 Sep 08 |
peter |
80 |
suite.add(false); |
1535 |
25 Sep 08 |
peter |
81 |
} |
2122 |
19 Dec 09 |
peter |
82 |
if (holder() == holder()) |
2122 |
19 Dec 09 |
peter |
83 |
suite.add(true); |
2122 |
19 Dec 09 |
peter |
84 |
else |
2122 |
19 Dec 09 |
peter |
85 |
suite.add(false); |
1535 |
25 Sep 08 |
peter |
86 |
if (holder() != const_holder()) { |
1535 |
25 Sep 08 |
peter |
87 |
suite.add(false); |
1535 |
25 Sep 08 |
peter |
88 |
} |
2122 |
19 Dec 09 |
peter |
89 |
if (holder() == const_holder()) |
2122 |
19 Dec 09 |
peter |
90 |
suite.add(true); |
2122 |
19 Dec 09 |
peter |
91 |
else |
2122 |
19 Dec 09 |
peter |
92 |
suite.add(false); |
1535 |
25 Sep 08 |
peter |
93 |
|
1535 |
25 Sep 08 |
peter |
94 |
suite.err() << "testing assignment\n"; |
1535 |
25 Sep 08 |
peter |
95 |
holder().data() = 1.0; |
1535 |
25 Sep 08 |
peter |
96 |
suite.add(suite.equal(holder().data(), 1.0)); |
1535 |
25 Sep 08 |
peter |
97 |
holder().weight() = 1.0; |
1535 |
25 Sep 08 |
peter |
98 |
suite.add(suite.equal(holder().weight(), 1.0)); |
1535 |
25 Sep 08 |
peter |
99 |
|
1535 |
25 Sep 08 |
peter |
100 |
DataWeight xw2(3.14, 0.5); |
1535 |
25 Sep 08 |
peter |
101 |
holder() = xw2; |
1535 |
25 Sep 08 |
peter |
102 |
suite.add(suite.equal(holder().data(), 3.14)); |
1535 |
25 Sep 08 |
peter |
103 |
suite.add(suite.equal(holder().weight(), 0.5)); |
1535 |
25 Sep 08 |
peter |
104 |
|
1535 |
25 Sep 08 |
peter |
105 |
DataWeight xw3; |
1535 |
25 Sep 08 |
peter |
106 |
xw3 = const_holder(); |
1535 |
25 Sep 08 |
peter |
107 |
suite.add(suite.equal(xw3.data(), 3.14)); |
1535 |
25 Sep 08 |
peter |
108 |
suite.add(suite.equal(xw3.weight(), 0.5)); |
1535 |
25 Sep 08 |
peter |
109 |
|
1538 |
27 Sep 08 |
peter |
110 |
DataWeight xw4(1.602, 1); |
1538 |
27 Sep 08 |
peter |
111 |
holder.get_copy() = xw4; |
1538 |
27 Sep 08 |
peter |
112 |
suite.add(suite.equal(holder().data(), 1.602)); |
1538 |
27 Sep 08 |
peter |
113 |
suite.add(suite.equal(holder().weight(), 1)); |
1538 |
27 Sep 08 |
peter |
114 |
|
2202 |
21 Feb 10 |
peter |
// do not run compile tests |
2202 |
21 Feb 10 |
peter |
116 |
if (false) { |
2202 |
21 Feb 10 |
peter |
117 |
typedef boost::mutable_forward_iterator_archetype<double> iterator; |
2202 |
21 Feb 10 |
peter |
118 |
iterator iter; |
2202 |
21 Feb 10 |
peter |
119 |
utility::DataWeightProxy<iterator, iterator> proxy(iter, iter); |
2202 |
21 Feb 10 |
peter |
120 |
double x = proxy.data(); |
2202 |
21 Feb 10 |
peter |
121 |
x = proxy.weight(); |
2202 |
21 Feb 10 |
peter |
122 |
proxy.data() = proxy.weight() = 0.0; |
3322 |
06 Oct 14 |
peter |
123 |
test::avoid_compiler_warning(x); |
2202 |
21 Feb 10 |
peter |
124 |
} |
2202 |
21 Feb 10 |
peter |
125 |
|
1535 |
25 Sep 08 |
peter |
126 |
return suite.return_value(); |
1533 |
25 Sep 08 |
peter |
127 |
} |