Documentation for OpenFLUID 2.2.0
SimulatorSignatureUtils.hpp
Go to the documentation of this file.
1 /*
2 
3  This file is part of OpenFLUID software
4  Copyright(c) 2007, INRA - Montpellier SupAgro
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.RequiredParams.push_back({"speedl","speed limit","m/s",openfluid::core::Value::DOUBLE});
86  Sign.HandledData.RequiredParams.push_back({"forcefield","field of force","n/m2",openfluid::core::Value::MATRIX});
87 
88  Sign.HandledData.UsedExtraFiles = {"observed.csv","simulated.csv","randomized.csv"};
89  Sign.HandledData.RequiredExtraFiles = {"forced_data1.csv","forced_data2.csv",};
90 
91  Sign.HandledData.UsedAttributes.push_back({"venue_capacity[integer]","YU","the venue capacity",""});
92  Sign.HandledData.UsedAttributes.push_back({"venue_volume","YU","the venue volume","m3s"});
93  Sign.HandledData.RequiredAttributes.push_back(
94  {"stage_area","ZU","the stage area","m2",openfluid::core::Value::DOUBLE});
96  {"area_per_musician","ZU","the area for each musician on stage","m2",openfluid::core::Value::DOUBLE});
97 
98  Sign.SimulatorHandledData.ProducedVars.push_back(
99  {"venue.band.music.instruments","YU","the music","db",openfluid::core::Value::VECTOR});
100  Sign.SimulatorHandledData.ProducedVars.push_back({"venue.stage.light.system[map]","YU","the light","lm"});
101  Sign.SimulatorHandledData.UpdatedVars.push_back(
102  {"venue.temperature.attendance","ZU","the venue temperature","K",openfluid::core::Value::DOUBLE});
103  Sign.HandledData.RequiredVars.push_back(
104  {"venue.stage.power","ZU","the electric power","W",openfluid::core::Value::INTEGER});
105  Sign.HandledData.UsedVars.push_back({"venue.band.mojo","ZU","the mojo",""});
106 
107  Sign.SimulatorHandledData.UsedEventsOnUnits = {"ZU","YU"};
108 
109  Sign.TimeScheduling.setAsRange(300,600);
110 
111  Sign.HandledUnitsGraph.UpdatedUnitsGraph = "Spatial graph is modified";
113  {"XU","XU units are created"},
114  {"YU","YU units connections to XU units are updated"},
115  };
116 
117  return Sign;
118 }
119 
120 
121 // =====================================================================
122 // =====================================================================
123 
124 
127  const std::string& Context)
128 {
129  std::cout << Context << " : compareSignatures()" << std::endl;
130 
131  compareSignaturesBase<openfluid::ware::SimulatorSignature>(Sign1,Sign2);
132 
133  // parameters
134  BOOST_CHECK(!Sign1.HandledData.UsedParams.empty());
135  BOOST_CHECK(!Sign1.HandledData.RequiredParams.empty());
136  BOOST_CHECK_EQUAL(Sign1.HandledData.UsedParams.size(),Sign2.HandledData.UsedParams.size());
137  BOOST_CHECK_EQUAL(Sign1.HandledData.RequiredParams.size(),Sign2.HandledData.RequiredParams.size());
138 
139  // extra files
140  BOOST_CHECK(!Sign1.HandledData.UsedExtraFiles.empty());
141  BOOST_CHECK_EQUAL(Sign1.HandledData.UsedExtraFiles.size(),Sign2.HandledData.UsedExtraFiles.size());
142  BOOST_CHECK_EQUAL_COLLECTIONS(Sign1.HandledData.UsedExtraFiles.begin(),
143  Sign1.HandledData.UsedExtraFiles.end(),
144  Sign2.HandledData.UsedExtraFiles.begin(),
145  Sign2.HandledData.UsedExtraFiles.end());
146  BOOST_CHECK(!Sign1.HandledData.RequiredExtraFiles.empty());
147  BOOST_CHECK_EQUAL(Sign1.HandledData.RequiredExtraFiles.size(),
148  Sign2.HandledData.RequiredExtraFiles.size());
149  BOOST_CHECK_EQUAL_COLLECTIONS(
152  );
153 
154  // attributes
155  BOOST_CHECK(!Sign1.SimulatorHandledData.ProducedAttributes.empty());
156  BOOST_CHECK_EQUAL(Sign1.SimulatorHandledData.ProducedAttributes.size(),
158  BOOST_CHECK(!Sign1.HandledData.RequiredAttributes.empty());
159  BOOST_CHECK_EQUAL(Sign1.HandledData.RequiredAttributes.size(),
160  Sign2.HandledData.RequiredAttributes.size());
161  BOOST_CHECK(!Sign1.HandledData.RequiredAttributes.empty());
162  BOOST_CHECK_EQUAL(Sign1.HandledData.RequiredAttributes.size(),
163  Sign2.HandledData.RequiredAttributes.size());
164 
165  // variables
166  BOOST_CHECK(!Sign1.SimulatorHandledData.ProducedVars.empty());
167  BOOST_CHECK_EQUAL(Sign1.SimulatorHandledData.ProducedVars.size(),Sign2.SimulatorHandledData.ProducedVars.size());
168  BOOST_CHECK(!Sign1.HandledData.UsedVars.empty());
169  BOOST_CHECK_EQUAL(Sign1.HandledData.UsedVars.size(),Sign2.HandledData.UsedVars.size());
170  BOOST_CHECK(!Sign1.HandledData.RequiredVars.empty());
171  BOOST_CHECK_EQUAL(Sign1.HandledData.RequiredVars.size(),Sign2.HandledData.RequiredVars.size());
172  BOOST_CHECK(!Sign1.SimulatorHandledData.UpdatedVars.empty());
173  BOOST_CHECK_EQUAL(Sign1.SimulatorHandledData.UpdatedVars.size(),Sign2.SimulatorHandledData.UpdatedVars.size());
174 
175  // events
176  BOOST_CHECK_EQUAL(Sign1.SimulatorHandledData.UsedEventsOnUnits.size(),
178  BOOST_CHECK_EQUAL_COLLECTIONS(Sign1.SimulatorHandledData.UsedEventsOnUnits.begin(),
182 
183  // spatial graph
184  BOOST_CHECK(!Sign1.HandledUnitsGraph.UpdatedUnitsGraph.empty());
186  BOOST_CHECK(!Sign1.HandledUnitsGraph.UpdatedUnitsClasses.empty());
187  BOOST_CHECK_EQUAL(Sign1.HandledUnitsGraph.UpdatedUnitsClasses.size(),
189 
190  // scheduling
191  BOOST_CHECK(Sign1.TimeScheduling.Type == Sign2.TimeScheduling.Type);
192  BOOST_CHECK_EQUAL(Sign1.TimeScheduling.Min,Sign2.TimeScheduling.Min);
193  BOOST_CHECK_EQUAL(Sign1.TimeScheduling.Max,Sign2.TimeScheduling.Max);
194 }
195 
196 
197 // =====================================================================
198 // =====================================================================
199 
200 
202  const openfluid::thirdparty::json& DataItem2)
203 {
204  BOOST_CHECK_EQUAL(DataItem1.value("name", ""), DataItem2.value("name", ""));
205  BOOST_CHECK_EQUAL(DataItem1.value("description", ""), DataItem2.value("description", ""));
206  BOOST_CHECK_EQUAL(DataItem1.value("siunit", ""), DataItem2.value("siunit", ""));
207  BOOST_CHECK_EQUAL(DataItem1.value("type", ""), DataItem2.value("type", ""));
208  BOOST_CHECK_EQUAL(DataItem1.value("unitsclass", ""), DataItem2.value("unitsclass", ""));
209 }
210 
211 
212 // =====================================================================
213 // =====================================================================
214 
215 
217  const openfluid::thirdparty::json& Object2,
218  const std::string& ConditionKey)
219 {
220  openfluid::thirdparty::json ConditionObject1 = Object1.value(ConditionKey, openfluid::thirdparty::json::array());
221  openfluid::thirdparty::json ConditionObject2 = Object2.value(ConditionKey, openfluid::thirdparty::json::array());
222  checkArraysJSON (ConditionObject1, ConditionObject2);
223  for (unsigned int i=0; i < ConditionObject1.size(); i++)
224  {
225  compareDataItemsJSON(ConditionObject1[i], ConditionObject2[i]);
226  }
227 }
228 
229 
230 // =====================================================================
231 // =====================================================================
232 
233 
235  const openfluid::thirdparty::json& Json2,
236  const std::string& Context)
237 {
238  std::cout << Context << " : compareJSON()" << std::endl;
239 
240  compareJSONBase(Json1, Json2);
241 
242  openfluid::thirdparty::json Simulator1 = Json1.value("simulator",openfluid::thirdparty::json::object());
243  openfluid::thirdparty::json Simulator2 = Json2.value("simulator",openfluid::thirdparty::json::object());
244  BOOST_CHECK(Simulator1.is_object());
245  BOOST_CHECK(Simulator2.is_object());
246 
247  openfluid::thirdparty::json Data1 = Simulator1.value("data",openfluid::thirdparty::json::object());
248  openfluid::thirdparty::json Data2 = Simulator2.value("data",openfluid::thirdparty::json::object());
249 
250  // Parameters
251  openfluid::thirdparty::json Params1 = Data1.value("parameters",openfluid::thirdparty::json::object());
252  openfluid::thirdparty::json Params2 = Data2.value("parameters",openfluid::thirdparty::json::object());
253  compareIOConditionJSON(Params1, Params2, "required");
254  compareIOConditionJSON(Params1, Params2, "used");
255 
256  // Attributes
257  openfluid::thirdparty::json Attributes1 = Data1.value("attributes",openfluid::thirdparty::json::object());
258  openfluid::thirdparty::json Attributes2 = Data2.value("attributes",openfluid::thirdparty::json::object());
259  compareIOConditionJSON(Attributes1, Attributes2, "required");
260  compareIOConditionJSON(Attributes1, Attributes2, "used");
261  compareIOConditionJSON(Attributes1, Attributes2, "produced");
262 
263  // Variables
264  openfluid::thirdparty::json Variables1 = Data1.value("variables",openfluid::thirdparty::json::object());
265  openfluid::thirdparty::json Variables2 = Data2.value("variables",openfluid::thirdparty::json::object());
266  compareIOConditionJSON(Variables1, Variables2, "required");
267  compareIOConditionJSON(Variables1, Variables2, "used");
268  compareIOConditionJSON(Variables1, Variables2, "produced");
269  compareIOConditionJSON(Variables1, Variables2, "updated");
270 
271  // Events
272  openfluid::thirdparty::json Events1 = Data1.value("events",openfluid::thirdparty::json::array());
273  openfluid::thirdparty::json Events2 = Data2.value("events",openfluid::thirdparty::json::array());
274  checkArraysJSON (Events1, Events2);
275  for (unsigned int i=0; i < Events1.size(); i++)
276  {
277  BOOST_CHECK_EQUAL(Events1[i], Events2[i]);
278  }
279 
280  // Extra files
281  openfluid::thirdparty::json ExtraFiles1 = Data1.value("extrafiles",openfluid::thirdparty::json::object());
282  openfluid::thirdparty::json ExtraFiles2 = Data2.value("extrafiles",openfluid::thirdparty::json::object());
283  openfluid::thirdparty::json RequiredEF1 = ExtraFiles1.value("required",openfluid::thirdparty::json::array());
284  openfluid::thirdparty::json RequiredEF2 = ExtraFiles2.value("required",openfluid::thirdparty::json::array());
285  checkArraysJSON (RequiredEF1, RequiredEF2);
286  for (unsigned int i=0; i < RequiredEF1.size(); i++)
287  {
288  BOOST_CHECK_EQUAL(RequiredEF1[i], RequiredEF2[i]);
289  }
290  openfluid::thirdparty::json UsedEF1 = ExtraFiles1.value("used",openfluid::thirdparty::json::array());
291  openfluid::thirdparty::json UsedEF2 = ExtraFiles2.value("used",openfluid::thirdparty::json::array());
292  checkArraysJSON (UsedEF1, UsedEF2);
293  for (unsigned int i=0; i < UsedEF1.size(); i++)
294  {
295  BOOST_CHECK_EQUAL(UsedEF1[i], UsedEF2[i]);
296  }
297 
298  // Spatial graph
299  openfluid::thirdparty::json SpatialGraph1 = Simulator1.value("spatial_graph",openfluid::thirdparty::json::object());
300  openfluid::thirdparty::json SpatialGraph2 = Simulator2.value("spatial_graph",openfluid::thirdparty::json::object());
301  BOOST_CHECK_EQUAL(SpatialGraph1.value("description", ""), SpatialGraph2.value("description", ""));
302  openfluid::thirdparty::json DetailsSG1 = SpatialGraph1.value("details", openfluid::thirdparty::json::array());
303  openfluid::thirdparty::json DetailsSG2 = SpatialGraph2.value("details", openfluid::thirdparty::json::array());
304  checkArraysJSON (DetailsSG1, DetailsSG2);
305  for (unsigned int i=0; i < DetailsSG1.size(); i++)
306  {
307  BOOST_CHECK_EQUAL(DetailsSG1[i].value("unitsclass", ""), DetailsSG2[i].value("unitsclass", ""));
308  BOOST_CHECK_EQUAL(DetailsSG1[i].value("description", ""), DetailsSG2[i].value("description", ""));
309  }
310 
311  // Scheduling
312  openfluid::thirdparty::json Scheduling1 = Simulator1.value("scheduling",openfluid::thirdparty::json::object());
313  openfluid::thirdparty::json Scheduling2 = Simulator2.value("scheduling",openfluid::thirdparty::json::object());
314  BOOST_CHECK_EQUAL(Scheduling1.value("type", ""), Scheduling2.value("type", ""));
315  BOOST_CHECK_EQUAL(Scheduling1.value("min", 0), Scheduling2.value("min", 0));
316  BOOST_CHECK_EQUAL(Scheduling1.value("max", 0), Scheduling2.value("max", 0));
317 }
318 
319 #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:201
void compareIOConditionJSON(const openfluid::thirdparty::json &Object1, const openfluid::thirdparty::json &Object2, const std::string &ConditionKey)
Definition: SimulatorSignatureUtils.hpp:216
void compareSignatures(const openfluid::ware::SimulatorSignature &Sign1, const openfluid::ware::SimulatorSignature &Sign2, const std::string &Context)
Definition: SimulatorSignatureUtils.hpp:125
void compareJSON(const openfluid::thirdparty::json &Json1, const openfluid::thirdparty::json &Json2, const std::string &Context)
Definition: SimulatorSignatureUtils.hpp:234
Class for management of date and time information.
Definition: DateTime.hpp:88
@ VECTOR
Definition: Value.hpp:66
@ MATRIX
Definition: Value.hpp:66
@ DOUBLE
Definition: Value.hpp:66
@ INTEGER
Definition: Value.hpp:66
SignatureHandledData HandledData
Definition: WareSignature.hpp:336
std::vector< SignatureDataItem > UsedParams
Definition: WareSignature.hpp:290
std::vector< SignatureSpatialDataItem > UsedVars
Definition: WareSignature.hpp:296
std::vector< std::string > RequiredExtraFiles
Definition: WareSignature.hpp:302
std::vector< std::string > UsedExtraFiles
Definition: WareSignature.hpp:304
std::vector< SignatureSpatialDataItem > RequiredAttributes
Definition: WareSignature.hpp:298
std::vector< SignatureSpatialDataItem > RequiredVars
Definition: WareSignature.hpp:294
std::vector< SignatureSpatialDataItem > UsedAttributes
Definition: WareSignature.hpp:300
std::vector< SignatureDataItem > RequiredParams
Definition: WareSignature.hpp:292
openfluid::core::Duration_t Min
Definition: SimulatorSignature.hpp:153
void setAsRange(openfluid::core::Duration_t MinVal, openfluid::core::Duration_t MaxVal)
Definition: SimulatorSignature.hpp:184
openfluid::core::Duration_t Max
Definition: SimulatorSignature.hpp:155
SchedulingType Type
Definition: SimulatorSignature.hpp:151
std::string UpdatedUnitsGraph
Definition: SimulatorSignature.hpp:122
std::vector< SignatureUnitsClassItem > UpdatedUnitsClasses
Definition: SimulatorSignature.hpp:124
std::vector< SignatureSpatialDataItem > ProducedVars
Definition: SimulatorSignature.hpp:63
std::vector< SignatureSpatialDataItem > UpdatedVars
Definition: SimulatorSignature.hpp:65
std::vector< SignatureSpatialDataItem > ProducedAttributes
Definition: SimulatorSignature.hpp:67
std::vector< openfluid::core::UnitsClass_t > UsedEventsOnUnits
Definition: SimulatorSignature.hpp:69
Definition: SimulatorSignature.hpp:237
SignatureTimeScheduling TimeScheduling
Definition: SimulatorSignature.hpp:256
SimulatorSignatureHandledData SimulatorHandledData
Definition: SimulatorSignature.hpp:241
SignatureUnitsGraph HandledUnitsGraph
Definition: SimulatorSignature.hpp:251
void add(const WareIssue &Issue)
WareID_t ID
Definition: WareSignature.hpp:77
WareStatus_t Status
Definition: WareSignature.hpp:91
PeopleList_t Authors
Definition: WareSignature.hpp:96
std::vector< std::string > Tags
Definition: WareSignature.hpp:111
std::string Description
Definition: WareSignature.hpp:81
LinksList_t Links
Definition: WareSignature.hpp:116
std::string License
Definition: WareSignature.hpp:106
WareName_t Name
Definition: WareSignature.hpp:79
DependenciesMap_t Dependencies
Definition: WareSignature.hpp:126
WareVersion_t Version
Definition: WareSignature.hpp:86
PeopleList_t Contacts
Definition: WareSignature.hpp:101
WareIssues Issues
Definition: WareSignature.hpp:121
nlohmann::ordered_json json
Definition: JSON.hpp:52
@ BETA
Definition: TypeDefs.hpp:111