GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: TESTS/TEST_TENSOR_FILE/main.cpp Lines: 116 116 100.0 %
Date: 2026-03-27 22:08:32 Branches: 133 133 100.0 %

Line Branch Exec Source
1
/***************************************
2
	Auteur : Pierre Aubert
3
	Mail : pierre.aubert@lapp.in2p3.fr
4
	Licence : CeCILL-C
5
****************************************/
6
7
#include <sstream>
8
#include "tensor_check.h"
9
10
///Test the Tensor with one dimension
11
/**	@param testName : name of the test
12
 * 	@param mode : allocation mode
13
 * 	@param nbElement : number of element of the tensor
14
 * 	@return true on success, false otherwise
15
*/
16
template<typename T>
17
132
bool testMessageTensor1d(const std::string & testName, AllocMode::AllocMode mode, size_t nbElement){
18
264
	PTensor<T> tensor(mode, nbElement);
19
12276
	for(size_t i(0lu); i < nbElement; ++i){
20
12144
		tensor.setValue(i, (T)(2lu*i + 1lu));
21
	}
22
264
	std::string fileName("file.ptensor");
23
132
	bool b(true);
24
132
	b &= data_save(fileName, tensor);			//Save the message
25
26
264
	PTensor<T> loadTensor;
27
132
	b &= data_load(fileName, loadTensor);		//Load the message
28
29
132
	std::stringstream str;
30
132
	str << (int)mode;
31

132
	b &= checkTensor(testName + " " + str.str(), tensor, loadTensor);
32


132
	std::cout << "testMessageTensor1d("<<testName<<" " << str.str() <<") : b = " << b << std::endl;
33
264
	return b;
34
}
35
36
///Test the Tensor with one dimension
37
/**	@param testName : name of the test
38
 * 	@param nbElement : number of element of the tensor
39
 * 	@return true on success, false otherwise
40
*/
41
template<typename T>
42
44
bool testMessageModeTensor1d(const std::string & testName, size_t nbElement){
43
44
	bool b(true);
44
44
	b &= testMessageTensor1d<T>(testName, AllocMode::NONE, nbElement);
45
44
	b &= testMessageTensor1d<T>(testName, AllocMode::ALIGNED, nbElement);
46
44
	b &= testMessageTensor1d<T>(testName, AllocMode::PADDING, nbElement);
47
44
	return b;
48
}
49
50
///Test the Tensor with one dimension
51
/**	@param nbElement : number of element of the tensor
52
 * 	@return true on success, false otherwise
53
*/
54
2
bool testMessageTensor1(size_t nbElement){
55
2
	bool b(true);
56
2
	b &= testMessageModeTensor1d<bool>("bool", nbElement);
57
2
	b &= testMessageModeTensor1d<char>("char", nbElement);
58
2
	b &= testMessageModeTensor1d<short>("short", nbElement);
59
2
	b &= testMessageModeTensor1d<int>("int", nbElement);
60
2
	b &= testMessageModeTensor1d<long int>("long int", nbElement);
61
62
2
	b &= testMessageModeTensor1d<unsigned char>("unsigned char", nbElement);
63
2
	b &= testMessageModeTensor1d<unsigned short>("unsigned short", nbElement);
64
2
	b &= testMessageModeTensor1d<unsigned int>("unsigned int", nbElement);
65
2
	b &= testMessageModeTensor1d<long unsigned int>("long unsigned int", nbElement);
66
67
2
	b &= testMessageModeTensor1d<float>("float", nbElement);
68
2
	b &= testMessageModeTensor1d<double>("double", nbElement);
69
70
2
	return b;
71
}
72
73
74
///Test the Tensor with one dimension
75
/**	@param testName : name of the test
76
 * 	@param mode : allocation mode
77
 * 	@param nbRow : number of rows of the tensor
78
 * 	@param nbCol : number of columns of the tensor
79
 * 	@return true on success, false otherwise
80
*/
81
template<typename T>
82
264
bool testMessageTensor2d(const std::string & testName, AllocMode::AllocMode mode, size_t nbRow, size_t nbCol){
83
528
	PTensor<T> tensor(mode, nbRow, nbCol);
84
23298
	for(size_t i(0lu); i < nbRow; ++i){
85
975018
		for(size_t j(0lu); j < nbCol; ++j){
86
951984
			tensor.setValue(i, j, (T)(2lu*(i*nbCol + j) + 1lu));
87
		}
88
	}
89
528
	std::string fileName("file.ptensor");
90
264
	bool b(true);
91
264
	b &= data_save(fileName, tensor);			//Save the message
92
93
528
	PTensor<T> loadTensor;
94
264
	b &= data_load(fileName, loadTensor);		//Load the message
95
96
264
	std::stringstream str;
97
264
	str << (int)mode;
98

264
	b &= checkTensor(testName + " " + str.str(), tensor, loadTensor);
99


264
	std::cout << "testMessageTensor2d("<<testName<<" " << str.str() <<") : b = " << b << std::endl;
100
528
	return b;
101
}
102
103
///Test the Tensor with one dimension
104
/**	@param testName : name of the test
105
 * 	@param nbRow : number of rows of the tensor
106
 * 	@param nbCol : number of columns of the tensor
107
 * 	@return true on success, false otherwise
108
*/
109
template<typename T>
110
88
bool testMessageModeTensor2d(const std::string & testName, size_t nbRow, size_t nbCol){
111
88
	bool b(true);
112
88
	b &= testMessageTensor2d<T>(testName, AllocMode::NONE, nbRow, nbCol);
113
88
	b &= testMessageTensor2d<T>(testName, AllocMode::ALIGNED, nbRow, nbCol);
114
88
	b &= testMessageTensor2d<T>(testName, AllocMode::PADDING, nbRow, nbCol);
115
88
	return b;
116
}
117
118
///Test the Tensor with one dimension
119
/**	@param nbRow : number of rows of the tensor
120
 * 	@param nbCol : number of columns of the tensor
121
 * 	@return true on success, false otherwise
122
*/
123
4
bool testMessageTensor2(size_t nbRow, size_t nbCol){
124
4
	bool b(true);
125
4
	b &= testMessageModeTensor2d<bool>("bool", nbRow, nbCol);
126
4
	b &= testMessageModeTensor2d<char>("char", nbRow, nbCol);
127
4
	b &= testMessageModeTensor2d<short>("short", nbRow, nbCol);
128
4
	b &= testMessageModeTensor2d<int>("int", nbRow, nbCol);
129
4
	b &= testMessageModeTensor2d<long int>("long int", nbRow, nbCol);
130
131
4
	b &= testMessageModeTensor2d<unsigned char>("unsigned char", nbRow, nbCol);
132
4
	b &= testMessageModeTensor2d<unsigned short>("unsigned short", nbRow, nbCol);
133
4
	b &= testMessageModeTensor2d<unsigned int>("unsigned int", nbRow, nbCol);
134
4
	b &= testMessageModeTensor2d<long unsigned int>("long unsigned int", nbRow, nbCol);
135
136
4
	b &= testMessageModeTensor2d<float>("float", nbRow, nbCol);
137
4
	b &= testMessageModeTensor2d<double>("double", nbRow, nbCol);
138
139
4
	return b;
140
}
141
142
///Test the Tensor with one dimension
143
/**	@param testName : name of the test
144
 * 	@param mode : allocation mode
145
 * 	@param nbSlice : number of slices of the tensor
146
 * 	@param nbRow : number of rows of the tensor
147
 * 	@param nbCol : number of columns of the tensor
148
 * 	@return true on success, false otherwise
149
*/
150
template<typename T>
151
264
bool testMessageTensor3d(const std::string & testName, AllocMode::AllocMode mode, size_t nbSlice, size_t nbRow, size_t nbCol){
152
528
	PTensor<T> tensor(mode, nbSlice, nbRow, nbCol);
153
100254
	for(size_t i(0lu); i < nbSlice*nbRow; ++i){
154
4126782
		for(size_t j(0lu); j < nbCol; ++j){
155
4026792
			tensor.setValue(i, j, (T)(2lu*(i*nbCol + j) + 1lu));
156
		}
157
	}
158
528
	std::string fileName("file.ptensor");
159
264
	bool b(true);
160
264
	b &= data_save(fileName, tensor);			//Save the message
161
162
528
	PTensor<T> loadTensor;
163
264
	b &= data_load(fileName, loadTensor);		//Load the message
164
165
264
	std::stringstream str;
166
264
	str << (int)mode;
167

264
	b &= checkTensor(testName + " " + str.str(), tensor, loadTensor);
168


264
	std::cout << "testMessageTensor3d("<<testName<<" " << str.str() <<") : b = " << b << std::endl;
169
528
	return b;
170
}
171
172
///Test the Tensor with one dimension
173
/**	@param testName : name of the test
174
 * 	@param nbSlice : number of slices of the tensor
175
 * 	@param nbRow : number of rows of the tensor
176
 * 	@param nbCol : number of columns of the tensor
177
 * 	@return true on success, false otherwise
178
*/
179
template<typename T>
180
88
bool testMessageModeTensor3d(const std::string & testName, size_t nbSlice, size_t nbRow, size_t nbCol){
181
88
	bool b(true);
182
88
	b &= testMessageTensor3d<T>(testName, AllocMode::NONE, nbSlice, nbRow, nbCol);
183
88
	b &= testMessageTensor3d<T>(testName, AllocMode::ALIGNED, nbSlice, nbRow, nbCol);
184
88
	b &= testMessageTensor3d<T>(testName, AllocMode::PADDING, nbSlice, nbRow, nbCol);
185
88
	return b;
186
}
187
188
///Test the Tensor with one dimension
189
/**	@param nbSlice : number of slices of the tensor
190
 * 	@param nbRow : number of rows of the tensor
191
 * 	@param nbCol : number of columns of the tensor
192
 * 	@return true on success, false otherwise
193
*/
194
4
bool testMessageTensor3(size_t nbSlice, size_t nbRow, size_t nbCol){
195
4
	bool b(true);
196
4
	b &= testMessageModeTensor3d<bool>("bool", nbSlice, nbRow, nbCol);
197
4
	b &= testMessageModeTensor3d<char>("char", nbSlice, nbRow, nbCol);
198
4
	b &= testMessageModeTensor3d<short>("short", nbSlice, nbRow, nbCol);
199
4
	b &= testMessageModeTensor3d<int>("int", nbSlice, nbRow, nbCol);
200
4
	b &= testMessageModeTensor3d<long int>("long int", nbSlice, nbRow, nbCol);
201
202
4
	b &= testMessageModeTensor3d<unsigned char>("unsigned char", nbSlice, nbRow, nbCol);
203
4
	b &= testMessageModeTensor3d<unsigned short>("unsigned short", nbSlice, nbRow, nbCol);
204
4
	b &= testMessageModeTensor3d<unsigned int>("unsigned int", nbSlice, nbRow, nbCol);
205
4
	b &= testMessageModeTensor3d<long unsigned int>("long unsigned int", nbSlice, nbRow, nbCol);
206
207
4
	b &= testMessageModeTensor3d<float>("float", nbSlice, nbRow, nbCol);
208
4
	b &= testMessageModeTensor3d<double>("double", nbSlice, nbRow, nbCol);
209
210
4
	return b;
211
}
212
213
1
int main(int argc, char** argv){
214
1
	bool b(testMessageTensor1(42lu));
215
1
	b &= testMessageTensor1(142lu);
216
1
	b &= testMessageTensor2(42lu, 21lu);
217
1
	b &= testMessageTensor2(142lu, 21lu);
218
1
	b &= testMessageTensor2(23lu, 64lu);
219
1
	b &= testMessageTensor2(142lu, 64lu);
220
221
1
	b &= testMessageTensor3(3lu, 42lu, 21lu);
222
1
	b &= testMessageTensor3(5lu, 142lu, 21lu);
223
1
	b &= testMessageTensor3(11lu, 23lu, 64lu);
224
1
	b &= testMessageTensor3(3lu, 142lu, 64lu);
225
226
1
	return b - 1;
227
}
228
229