Documentation for OpenFLUID 2.2.2
Loading...
Searching...
No Matches
SimulatorSignatureUtils.hpp
Go to the documentation of this file.
1/*
2
3 This file is part of OpenFLUID software
4 Copyright(c) 2021-2026, INRAE
5
6
7 == GNU General Public License Usage ==
8
9 OpenFLUID is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13
14 OpenFLUID is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with OpenFLUID. If not, see <http://www.gnu.org/licenses/>.
21
22
23 == Other Usage ==
24
25 Other Usage means a use of OpenFLUID that is inconsistent with the GPL
26 license, and requires a written agreement between You and INRA.
27 Licensees for Other Usage of OpenFLUID may use this file in accordance
28 with the terms contained in the written agreement between You and INRA.
29
30*/
31
32
33/**
34 @file SimulatorSignatureUtils.hpp
35
36 @author Jean-Christophe FABRE <jean-christophe.fabre@inrae.fr>
37 @author Armel Thöni <armel.thoni@inrae.fr>
38 */
39
40
41#ifndef __OPENFLUID_WARESDEVTESTS_SIMULATORSIGNATUREUTILS_HPP__
42#define __OPENFLUID_WARESDEVTESTS_SIMULATORSIGNATUREUTILS_HPP__
43
44
46#include "SignatureCommon.hpp"
47
48
50{
52
53 Sign.ID = "unit.test.simulator-signature";
54 Sign.Name = "Simulator signature for unit testing";
55 Sign.Description = "This is a simulator signature\n"
56 " that should be used for **unit testing only**";
57 Sign.Version = "2022.07";
59
60 Sign.Authors = {
61 {"Kurt Cobain","kurt@nirvana.org"},
62 {"Dave Grohl","dave@nirvana.org"},
63 {"Krist Novoselic","krist@nirvana.org"}
64 };
65 Sign.Contacts = {{"OpenFLUID contact","contact@openfluid-project.org"}};
66 Sign.License = "GPL-3.0-or-later";
67
68 Sign.Tags = {"simulator","unit testing","development","software quality"} ;
69 Sign.Links = {
70 {"OpenFLUID","www.openfluid-project.org"},
71 {"OpenFLUID community","community.openfluid-project.org"}
72 };
73
74 Sign.Issues.add({101, "Issue X","This is the issue X",{"bug","results"},"Dave",
75 openfluid::core::DateTime(1983,07,22,16,47,11),
76 openfluid::core::DateTime(2024,02,29,12,16,52)});
77 Sign.Issues.add({102, "Issue Y","This is\nthe issue Y",{"feature","IO"},"Kurt",
80 false});
81
82 Sign.Dependencies["otherLib"] = ">=1.0";
83
84 Sign.HandledData.UsedParams.push_back({"coeff","coefficient",""});
85 Sign.HandledData.UsedParams.push_back({"coeff 2","coefficient with a space",""});
86 Sign.HandledData.UsedParams.push_back({"coeff&3","coefficient with weïrd char",""});
87 Sign.HandledData.RequiredParams.push_back({"speedl","speed limit","m/s",openfluid::core::Value::DOUBLE});
88 Sign.HandledData.RequiredParams.push_back({"forcefield","field of force","n/m2",openfluid::core::Value::MATRIX});
89
90 Sign.HandledData.UsedExtraFiles = {"observed.csv","simulated.csv","randomized.csv"};
91 Sign.HandledData.RequiredExtraFiles = {"forced_data1.csv","forced_data2.csv",};
92
93 Sign.HandledData.UsedAttributes.push_back({"venue_capacity","YU","the venue capacity","",
95 Sign.HandledData.UsedAttributes.push_back({"venue_volume","YU","the venue volume","m3s"});
96 Sign.HandledData.RequiredAttributes.push_back(
97 {"stage_area","ZU","the stage area","m2",openfluid::core::Value::DOUBLE});
99 {"area_per_musician","ZU","the area for each musician on stage","m2",openfluid::core::Value::DOUBLE});
100
101 Sign.SimulatorHandledData.ProducedVars.push_back(
102 {"venue.band.music.instruments","YU","the music","db",openfluid::core::Value::VECTOR});
103 Sign.SimulatorHandledData.ProducedVars.push_back({"venue.stage.light.system","YU","the light","lm",
105 Sign.SimulatorHandledData.UpdatedVars.push_back(
106 {"venue.temperature.attendance","ZU","the venue temperature","K",openfluid::core::Value::DOUBLE});
107 Sign.HandledData.RequiredVars.push_back(
108 {"venue.stage.power","ZU","the electric power","W",openfluid::core::Value::INTEGER});
109 Sign.HandledData.UsedVars.push_back({"venue.band.mojo","ZU","the mojo",""});
110
111 Sign.SimulatorHandledData.UsedEventsOnUnits = {"ZU","YU"};
112
113 Sign.TimeScheduling.setAsRange(300,600);
114
115 Sign.HandledUnitsGraph.UpdatedUnitsGraph = "Spatial graph is modified";
117 {"XU","XU units are created"},
118 {"YU","YU units connections to XU units are updated"},
119 };
120
121 return Sign;
122}
123
124
125// =====================================================================
126// =====================================================================
127
128
131 const std::string& Context)
132{
133 std::cout << Context << " : compareSignatures()" << std::endl;
134
135 compareSignaturesBase<openfluid::ware::SimulatorSignature>(Sign1,Sign2);
136
137 // parameters
138 BOOST_CHECK(!Sign1.HandledData.UsedParams.empty());
139 BOOST_CHECK(!Sign1.HandledData.RequiredParams.empty());
140 BOOST_CHECK_EQUAL(Sign1.HandledData.UsedParams.size(),Sign2.HandledData.UsedParams.size());
141 BOOST_CHECK_EQUAL(Sign1.HandledData.RequiredParams.size(),Sign2.HandledData.RequiredParams.size());
142
143 // extra files
144 BOOST_CHECK(!Sign1.HandledData.UsedExtraFiles.empty());
145 BOOST_CHECK_EQUAL(Sign1.HandledData.UsedExtraFiles.size(),Sign2.HandledData.UsedExtraFiles.size());
146 BOOST_CHECK_EQUAL_COLLECTIONS(Sign1.HandledData.UsedExtraFiles.begin(),
147 Sign1.HandledData.UsedExtraFiles.end(),
148 Sign2.HandledData.UsedExtraFiles.begin(),
149 Sign2.HandledData.UsedExtraFiles.end());
150 BOOST_CHECK(!Sign1.HandledData.RequiredExtraFiles.empty());
151 BOOST_CHECK_EQUAL(Sign1.HandledData.RequiredExtraFiles.size(),
152 Sign2.HandledData.RequiredExtraFiles.size());
153 BOOST_CHECK_EQUAL_COLLECTIONS(
156 );
157
158 // attributes
159 BOOST_CHECK(!Sign1.SimulatorHandledData.ProducedAttributes.empty());
160 BOOST_CHECK_EQUAL(Sign1.SimulatorHandledData.ProducedAttributes.size(),
162 BOOST_CHECK(!Sign1.HandledData.RequiredAttributes.empty());
163 BOOST_CHECK_EQUAL(Sign1.HandledData.RequiredAttributes.size(),
164 Sign2.HandledData.RequiredAttributes.size());
165 BOOST_CHECK(!Sign1.HandledData.RequiredAttributes.empty());
166 BOOST_CHECK_EQUAL(Sign1.HandledData.RequiredAttributes.size(),
167 Sign2.HandledData.RequiredAttributes.size());
168
169 // variables
170 BOOST_CHECK(!Sign1.SimulatorHandledData.ProducedVars.empty());
171 BOOST_CHECK_EQUAL(Sign1.SimulatorHandledData.ProducedVars.size(),Sign2.SimulatorHandledData.ProducedVars.size());
172 BOOST_CHECK(!Sign1.HandledData.UsedVars.empty());
173 BOOST_CHECK_EQUAL(Sign1.HandledData.UsedVars.size(),Sign2.HandledData.UsedVars.size());
174 BOOST_CHECK(!Sign1.HandledData.RequiredVars.empty());
175 BOOST_CHECK_EQUAL(Sign1.HandledData.RequiredVars.size(),Sign2.HandledData.RequiredVars.size());
176 BOOST_CHECK(!Sign1.SimulatorHandledData.UpdatedVars.empty());
177 BOOST_CHECK_EQUAL(Sign1.SimulatorHandledData.UpdatedVars.size(),Sign2.SimulatorHandledData.UpdatedVars.size());
178
179 // events
180 BOOST_CHECK_EQUAL(Sign1.SimulatorHandledData.UsedEventsOnUnits.size(),
182 BOOST_CHECK_EQUAL_COLLECTIONS(Sign1.SimulatorHandledData.UsedEventsOnUnits.begin(),
186
187 // spatial graph
188 BOOST_CHECK(!Sign1.HandledUnitsGraph.UpdatedUnitsGraph.empty());
190 BOOST_CHECK(!Sign1.HandledUnitsGraph.UpdatedUnitsClasses.empty());
191 BOOST_CHECK_EQUAL(Sign1.HandledUnitsGraph.UpdatedUnitsClasses.size(),
193
194 // scheduling
195 BOOST_CHECK(Sign1.TimeScheduling.Type == Sign2.TimeScheduling.Type);
196 BOOST_CHECK_EQUAL(Sign1.TimeScheduling.Min,Sign2.TimeScheduling.Min);
197 BOOST_CHECK_EQUAL(Sign1.TimeScheduling.Max,Sign2.TimeScheduling.Max);
198}
199
200
201// =====================================================================
202// =====================================================================
203
204
206 const openfluid::thirdparty::json& DataItem2)
207{
208 BOOST_CHECK_EQUAL(DataItem1.value("name", ""), DataItem2.value("name", ""));
209 BOOST_CHECK_EQUAL(DataItem1.value("description", ""), DataItem2.value("description", ""));
210 BOOST_CHECK_EQUAL(DataItem1.value("siunit", ""), DataItem2.value("siunit", ""));
211 BOOST_CHECK_EQUAL(DataItem1.value("type", ""), DataItem2.value("type", ""));
212 BOOST_CHECK_EQUAL(DataItem1.value("unitsclass", ""), DataItem2.value("unitsclass", ""));
213}
214
215
216// =====================================================================
217// =====================================================================
218
219
221 const openfluid::thirdparty::json& Object2,
222 const std::string& ConditionKey)
223{
224 openfluid::thirdparty::json ConditionObject1 = Object1.value(ConditionKey, openfluid::thirdparty::json::array());
225 openfluid::thirdparty::json ConditionObject2 = Object2.value(ConditionKey, openfluid::thirdparty::json::array());
226 checkArraysJSON (ConditionObject1, ConditionObject2);
227 for (unsigned int i=0; i < ConditionObject1.size(); i++)
228 {
229 compareDataItemsJSON(ConditionObject1[i], ConditionObject2[i]);
230 }
231}
232
233
234// =====================================================================
235// =====================================================================
236
237
239 const openfluid::thirdparty::json& Json2,
240 const std::string& Context)
241{
242 std::cout << Context << " : compareJSON()" << std::endl;
243
244 compareJSONBase(Json1, Json2);
245
246 openfluid::thirdparty::json Simulator1 = Json1.value("simulator",openfluid::thirdparty::json::object());
247 openfluid::thirdparty::json Simulator2 = Json2.value("simulator",openfluid::thirdparty::json::object());
248 BOOST_CHECK(Simulator1.is_object());
249 BOOST_CHECK(Simulator2.is_object());
250
251 openfluid::thirdparty::json Data1 = Simulator1.value("data",openfluid::thirdparty::json::object());
252 openfluid::thirdparty::json Data2 = Simulator2.value("data",openfluid::thirdparty::json::object());
253
254 // Parameters
255 openfluid::thirdparty::json Params1 = Data1.value("parameters",openfluid::thirdparty::json::object());
256 openfluid::thirdparty::json Params2 = Data2.value("parameters",openfluid::thirdparty::json::object());
257 compareIOConditionJSON(Params1, Params2, "required");
258 compareIOConditionJSON(Params1, Params2, "used");
259
260 // Attributes
261 openfluid::thirdparty::json Attributes1 = Data1.value("attributes",openfluid::thirdparty::json::object());
262 openfluid::thirdparty::json Attributes2 = Data2.value("attributes",openfluid::thirdparty::json::object());
263 compareIOConditionJSON(Attributes1, Attributes2, "required");
264 compareIOConditionJSON(Attributes1, Attributes2, "used");
265 compareIOConditionJSON(Attributes1, Attributes2, "produced");
266
267 // Variables
268 openfluid::thirdparty::json Variables1 = Data1.value("variables",openfluid::thirdparty::json::object());
269 openfluid::thirdparty::json Variables2 = Data2.value("variables",openfluid::thirdparty::json::object());
270 compareIOConditionJSON(Variables1, Variables2, "required");
271 compareIOConditionJSON(Variables1, Variables2, "used");
272 compareIOConditionJSON(Variables1, Variables2, "produced");
273 compareIOConditionJSON(Variables1, Variables2, "updated");
274
275 // Events
276 openfluid::thirdparty::json Events1 = Data1.value("events",openfluid::thirdparty::json::array());
277 openfluid::thirdparty::json Events2 = Data2.value("events",openfluid::thirdparty::json::array());
278 checkArraysJSON (Events1, Events2);
279 for (unsigned int i=0; i < Events1.size(); i++)
280 {
281 BOOST_CHECK_EQUAL(Events1[i], Events2[i]);
282 }
283
284 // Extra files
285 openfluid::thirdparty::json ExtraFiles1 = Data1.value("extrafiles",openfluid::thirdparty::json::object());
286 openfluid::thirdparty::json ExtraFiles2 = Data2.value("extrafiles",openfluid::thirdparty::json::object());
287 openfluid::thirdparty::json RequiredEF1 = ExtraFiles1.value("required",openfluid::thirdparty::json::array());
288 openfluid::thirdparty::json RequiredEF2 = ExtraFiles2.value("required",openfluid::thirdparty::json::array());
289 checkArraysJSON (RequiredEF1, RequiredEF2);
290 for (unsigned int i=0; i < RequiredEF1.size(); i++)
291 {
292 BOOST_CHECK_EQUAL(RequiredEF1[i], RequiredEF2[i]);
293 }
294 openfluid::thirdparty::json UsedEF1 = ExtraFiles1.value("used",openfluid::thirdparty::json::array());
295 openfluid::thirdparty::json UsedEF2 = ExtraFiles2.value("used",openfluid::thirdparty::json::array());
296 checkArraysJSON (UsedEF1, UsedEF2);
297 for (unsigned int i=0; i < UsedEF1.size(); i++)
298 {
299 BOOST_CHECK_EQUAL(UsedEF1[i], UsedEF2[i]);
300 }
301
302 // Spatial graph
303 openfluid::thirdparty::json SpatialGraph1 = Simulator1.value("spatial_graph",openfluid::thirdparty::json::object());
304 openfluid::thirdparty::json SpatialGraph2 = Simulator2.value("spatial_graph",openfluid::thirdparty::json::object());
305 BOOST_CHECK_EQUAL(SpatialGraph1.value("description", ""), SpatialGraph2.value("description", ""));
306 openfluid::thirdparty::json DetailsSG1 = SpatialGraph1.value("details", openfluid::thirdparty::json::array());
307 openfluid::thirdparty::json DetailsSG2 = SpatialGraph2.value("details", openfluid::thirdparty::json::array());
308 checkArraysJSON (DetailsSG1, DetailsSG2);
309 for (unsigned int i=0; i < DetailsSG1.size(); i++)
310 {
311 BOOST_CHECK_EQUAL(DetailsSG1[i].value("unitsclass", ""), DetailsSG2[i].value("unitsclass", ""));
312 BOOST_CHECK_EQUAL(DetailsSG1[i].value("description", ""), DetailsSG2[i].value("description", ""));
313 }
314
315 // Scheduling
316 openfluid::thirdparty::json Scheduling1 = Simulator1.value("scheduling",openfluid::thirdparty::json::object());
317 openfluid::thirdparty::json Scheduling2 = Simulator2.value("scheduling",openfluid::thirdparty::json::object());
318 BOOST_CHECK_EQUAL(Scheduling1.value("type", ""), Scheduling2.value("type", ""));
319 BOOST_CHECK_EQUAL(Scheduling1.value("min", 0), Scheduling2.value("min", 0));
320 BOOST_CHECK_EQUAL(Scheduling1.value("max", 0), Scheduling2.value("max", 0));
321}
322
323#endif /* __OPENFLUID_WARESDEVTESTS_SIMULATORSIGNATUREUTILS_HPP__ */
void compareJSONBase(const openfluid::thirdparty::json &Json1, const openfluid::thirdparty::json &Json2)
Definition SignatureCommon.hpp:148
void checkArraysJSON(const openfluid::thirdparty::json &Json1, const openfluid::thirdparty::json &Json2)
Definition SignatureCommon.hpp:84
openfluid::ware::SimulatorSignature getRefSignature()
Definition SimulatorSignatureUtils.hpp:49
void compareDataItemsJSON(const openfluid::thirdparty::json &DataItem1, const openfluid::thirdparty::json &DataItem2)
Definition SimulatorSignatureUtils.hpp:205
void compareIOConditionJSON(const openfluid::thirdparty::json &Object1, const openfluid::thirdparty::json &Object2, const std::string &ConditionKey)
Definition SimulatorSignatureUtils.hpp:220
void compareSignatures(const openfluid::ware::SimulatorSignature &Sign1, const openfluid::ware::SimulatorSignature &Sign2, const std::string &Context)
Definition SimulatorSignatureUtils.hpp:129
void compareJSON(const openfluid::thirdparty::json &Json1, const openfluid::thirdparty::json &Json2, const std::string &Context)
Definition SimulatorSignatureUtils.hpp:238
Class for management of date and time information.
Definition DateTime.hpp:88
@ VECTOR
Definition Value.hpp:66
@ MAP
Definition Value.hpp:66
@ MATRIX
Definition Value.hpp:66
@ DOUBLE
Definition Value.hpp:66
@ INTEGER
Definition Value.hpp:66
SignatureHandledData HandledData
Definition WareSignature.hpp:343
std::vector< SignatureDataItem > UsedParams
Definition WareSignature.hpp:297
std::vector< SignatureSpatialDataItem > UsedVars
Definition WareSignature.hpp:303
std::vector< std::string > RequiredExtraFiles
Definition WareSignature.hpp:309
std::vector< std::string > UsedExtraFiles
Definition WareSignature.hpp:311
std::vector< SignatureSpatialDataItem > RequiredAttributes
Definition WareSignature.hpp:305
std::vector< SignatureSpatialDataItem > RequiredVars
Definition WareSignature.hpp:301
std::vector< SignatureSpatialDataItem > UsedAttributes
Definition WareSignature.hpp:307
std::vector< SignatureDataItem > RequiredParams
Definition WareSignature.hpp:299
openfluid::core::Duration_t Min
Definition SimulatorSignature.hpp:178
void setAsRange(openfluid::core::Duration_t MinVal, openfluid::core::Duration_t MaxVal)
Definition SimulatorSignature.hpp:209
openfluid::core::Duration_t Max
Definition SimulatorSignature.hpp:180
SchedulingType Type
Definition SimulatorSignature.hpp:176
std::string UpdatedUnitsGraph
Definition SimulatorSignature.hpp:147
std::vector< SignatureUnitsClassItem > UpdatedUnitsClasses
Definition SimulatorSignature.hpp:149
std::vector< SignatureSpatialDataItem > ProducedVars
Definition SimulatorSignature.hpp:88
std::vector< SignatureSpatialDataItem > UpdatedVars
Definition SimulatorSignature.hpp:90
std::vector< SignatureSpatialDataItem > ProducedAttributes
Definition SimulatorSignature.hpp:92
std::vector< openfluid::core::UnitsClass_t > UsedEventsOnUnits
Definition SimulatorSignature.hpp:94
Definition SimulatorSignature.hpp:262
SignatureTimeScheduling TimeScheduling
Definition SimulatorSignature.hpp:281
SimulatorSignatureHandledData SimulatorHandledData
Definition SimulatorSignature.hpp:266
SignatureUnitsGraph HandledUnitsGraph
Definition SimulatorSignature.hpp:276
void add(const WareIssue &Issue)
WareID_t ID
Definition WareSignature.hpp:79
WareStatus_t Status
Definition WareSignature.hpp:93
PeopleList_t Authors
Definition WareSignature.hpp:98
std::vector< std::string > Tags
Definition WareSignature.hpp:113
std::string Description
Definition WareSignature.hpp:83
LinksList_t Links
Definition WareSignature.hpp:118
std::string License
Definition WareSignature.hpp:108
WareName_t Name
Definition WareSignature.hpp:81
DependenciesMap_t Dependencies
Definition WareSignature.hpp:128
WareVersion_t Version
Definition WareSignature.hpp:88
PeopleList_t Contacts
Definition WareSignature.hpp:103
WareIssues Issues
Definition WareSignature.hpp:123
nlohmann::ordered_json json
Definition JSON.hpp:52
@ BETA
Definition TypeDefs.hpp:111