1 | // $Id: data_weight_proxy_test.cc 1538 2008-09-27 04:27:55Z 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 | |
---|
27 | namespace theplu { |
---|
28 | namespace yat { |
---|
29 | namespace 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 | |
---|
46 | using namespace theplu::yat; |
---|
47 | |
---|
48 | int 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() != const_holder()) { |
---|
79 | suite.add(false); |
---|
80 | } |
---|
81 | |
---|
82 | suite.err() << "testing assignment\n"; |
---|
83 | holder().data() = 1.0; |
---|
84 | suite.add(suite.equal(holder().data(), 1.0)); |
---|
85 | holder().weight() = 1.0; |
---|
86 | suite.add(suite.equal(holder().weight(), 1.0)); |
---|
87 | |
---|
88 | DataWeight xw2(3.14, 0.5); |
---|
89 | holder() = xw2; |
---|
90 | suite.add(suite.equal(holder().data(), 3.14)); |
---|
91 | suite.add(suite.equal(holder().weight(), 0.5)); |
---|
92 | |
---|
93 | DataWeight xw3; |
---|
94 | xw3 = const_holder(); |
---|
95 | suite.add(suite.equal(xw3.data(), 3.14)); |
---|
96 | suite.add(suite.equal(xw3.weight(), 0.5)); |
---|
97 | |
---|
98 | DataWeight xw4(1.602, 1); |
---|
99 | holder.get_copy() = xw4; |
---|
100 | suite.add(suite.equal(holder().data(), 1.602)); |
---|
101 | suite.add(suite.equal(holder().weight(), 1)); |
---|
102 | |
---|
103 | return suite.return_value(); |
---|
104 | } |
---|