ALL 0.9.3
A Loadbalacing Library
Loading...
Searching...
No Matches
point_access.cpp
Go to the documentation of this file.
1/*
2Copyright 2018-2020 Rene Halver, Forschungszentrum Juelich GmbH, Germany
3Copyright 2018-2020 Godehard Sutmann, Forschungszentrum Juelich GmbH, Germany
4
5Redistribution and use in source and binary forms, with or without modification,
6are permitted provided that the following conditions are met:
7
81. Redistributions of source code must retain the above copyright notice, this
9 list of conditions and the following disclaimer.
10
112. Redistributions in binary form must reproduce the above copyright notice,
12this list of conditions and the following disclaimer in the documentation and/or
13 other materials provided with the distribution.
14
153. Neither the name of the copyright holder nor the names of its contributors
16may be used to endorse or promote products derived from this software without
17 specific prior written permission.
18
19THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29*/
30
31#define BOOST_TEST_MAIN
32
33#define BOOST_TEST_MODULE point_access_and_creation
34#include "ALL_Point.hpp"
35#include <boost/test/unit_test.hpp>
36#include <list>
37#include <vector>
38
39BOOST_AUTO_TEST_SUITE(point_access)
40
42 int dimension = 3;
43 double x = 2.5;
44 double y = -5.7;
45 double z = 8.3;
46
47 double data[3];
48 data[0] = x;
49 data[1] = y;
50 data[2] = z;
51
52 ALL::Point<double> result(dimension, data);
53
54 BOOST_CHECK_EQUAL(result.getDimension(), dimension);
55 BOOST_CHECK_CLOSE(result[0], x, 1e-9);
56 BOOST_CHECK_CLOSE(result[1], y, 1e-9);
57 BOOST_CHECK_CLOSE(result[2], z, 1e-9);
58}
59
60BOOST_AUTO_TEST_CASE(array_weight) {
61 int dimension = 3;
62 double x = 2.5;
63 double y = -5.7;
64 double z = 8.3;
65
66 double data[3];
67 data[0] = x;
68 data[1] = y;
69 data[2] = z;
70 double weight = 2.5;
71
72 ALL::Point<double> result(dimension, data, weight);
73
74 BOOST_CHECK_EQUAL(result.getDimension(), dimension);
75 BOOST_CHECK_CLOSE(result[0], x, 1e-9);
76 BOOST_CHECK_CLOSE(result[1], y, 1e-9);
77 BOOST_CHECK_CLOSE(result[2], z, 1e-9);
78 BOOST_CHECK_CLOSE(result.getWeight(), weight, 1e-9);
79}
80
81BOOST_AUTO_TEST_CASE(array_weight_index) {
82 int dimension = 3;
83 double x = 2.5;
84 double y = -5.7;
85 double z = 8.3;
86
87 double data[3];
88 data[0] = x;
89 data[1] = y;
90 data[2] = z;
91
92 double weight = 1.4;
93 long index = 1l;
94 ALL::Point<double> result(dimension, data, weight, index);
95
96 BOOST_CHECK_EQUAL(result.getDimension(), dimension);
97 BOOST_CHECK_CLOSE(result[0], x, 1e-9);
98 BOOST_CHECK_CLOSE(result[1], y, 1e-9);
99 BOOST_CHECK_CLOSE(result[2], z, 1e-9);
100 BOOST_CHECK_CLOSE(result.getWeight(), weight, 1e-9);
101 BOOST_CHECK_EQUAL(result.get_id(), index);
102}
103
105 int dimension = 3;
106 double x = 2.5;
107 double y = -5.7;
108 double z = 8.3;
109 std::vector<double> data(dimension);
110 data.at(0) = x;
111 data.at(1) = y;
112 data.at(2) = z;
113 ALL::Point<double> result(data);
114
115 BOOST_CHECK_EQUAL(result.getDimension(), dimension);
116 BOOST_CHECK_CLOSE(result[0], x, 1e-9);
117 BOOST_CHECK_CLOSE(result[1], y, 1e-9);
118 BOOST_CHECK_CLOSE(result[2], z, 1e-9);
119}
120
121BOOST_AUTO_TEST_CASE(vector_weight) {
122 int dimension = 3;
123 double x = 2.5;
124 double y = -5.7;
125 double z = 8.3;
126
127 std::vector<double> data(dimension);
128 data.at(0) = x;
129 data.at(1) = y;
130 data.at(2) = z;
131
132 double weight = 1.4;
133 ALL::Point<double> result(data, weight);
134
135 BOOST_CHECK_EQUAL(result.getDimension(), dimension);
136 BOOST_CHECK_CLOSE(result[0], x, 1e-9);
137 BOOST_CHECK_CLOSE(result[1], y, 1e-9);
138 BOOST_CHECK_CLOSE(result[2], z, 1e-9);
139 BOOST_CHECK_CLOSE(result.getWeight(), weight, 1e-9);
140}
141
142BOOST_AUTO_TEST_CASE(vector_weight_index) {
143 int dimension = 3;
144 double x = 2.5;
145 double y = -5.7;
146 double z = 8.3;
147
148 std::vector<double> data(dimension);
149 data.at(0) = x;
150 data.at(1) = y;
151 data.at(2) = z;
152
153 double weight = 1.4;
154 long index = 1l;
155 ALL::Point<double> result(data, weight, index);
156
157 BOOST_CHECK_EQUAL(result.getDimension(), dimension);
158 BOOST_CHECK_CLOSE(result[0], x, 1e-9);
159 BOOST_CHECK_CLOSE(result[1], y, 1e-9);
160 BOOST_CHECK_CLOSE(result[2], z, 1e-9);
161 BOOST_CHECK_CLOSE(result.getWeight(), weight, 1e-9);
162 BOOST_CHECK_EQUAL(result.get_id(), index);
163}
164
165BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(empty)
int getDimension() const
T getWeight() const
long get_id() const
BOOST_AUTO_TEST_CASE(array)