##// END OF EJS Templates
Passes FuzzingState and variable id instead VariableState to the methods of operations
Alexandre Leroux -
r1236:ea04bef9c90c
parent child
Show More
@@ -1,210 +1,206
1 1 #include "FuzzingOperations.h"
2 2 #include "FuzzingUtils.h"
3 3
4 4 #include <Data/IDataProvider.h>
5 5
6 6 #include <Variable/Variable.h>
7 7 #include <Variable/VariableController.h>
8 8
9 9 #include <QUuid>
10 10
11 11 #include <functional>
12 12
13 13 Q_LOGGING_CATEGORY(LOG_FuzzingOperations, "FuzzingOperations")
14 14
15 15 namespace {
16 16
17 17 struct CreateOperation : public IFuzzingOperation {
18 bool canExecute(const VariableState &variableState) const override
18 bool canExecute(VariableId variableId, const FuzzingState &fuzzingState) const override
19 19 {
20 20 // A variable can be created only if it doesn't exist yet
21 return variableState.m_Variable == nullptr;
21 return fuzzingState.variableState(variableId).m_Variable == nullptr;
22 22 }
23 23
24 void execute(VariableState &variableState, VariableController &variableController,
24 void execute(VariableId variableId, FuzzingState &fuzzingState,
25 VariableController &variableController,
25 26 const Properties &properties) const override
26 27 {
27 28 // Retrieves metadata pool from properties, and choose one of the metadata entries to
28 29 // associate it with the variable
29 30 auto metaDataPool = properties.value(METADATA_POOL_PROPERTY).value<MetadataPool>();
30 31 auto variableMetadata = RandomGenerator::instance().randomChoice(metaDataPool);
31 32
32 33 // Retrieves provider
33 34 auto variableProvider
34 35 = properties.value(PROVIDER_PROPERTY).value<std::shared_ptr<IDataProvider> >();
35 36
36 37 auto variableName = QString{"Var_%1"}.arg(QUuid::createUuid().toString());
37 38 qCInfo(LOG_FuzzingOperations()).noquote()
38 39 << "Creating variable" << variableName << "(metadata:" << variableMetadata << ")...";
39 40
40 41 auto newVariable
41 42 = variableController.createVariable(variableName, variableMetadata, variableProvider);
42 43
43 44 // Updates variable's state
45 auto &variableState = fuzzingState.variableState(variableId);
44 46 variableState.m_Range = properties.value(INITIAL_RANGE_PROPERTY).value<SqpRange>();
45 47 std::swap(variableState.m_Variable, newVariable);
46 48 }
47 49 };
48 50
49 51 struct DeleteOperation : public IFuzzingOperation {
50 bool canExecute(const VariableState &variableState) const override
52 bool canExecute(VariableId variableId, const FuzzingState &fuzzingState) const override
51 53 {
52 54 // A variable can be delete only if it exists
53 return variableState.m_Variable != nullptr;
55 return fuzzingState.variableState(variableId).m_Variable != nullptr;
54 56 }
55 57
56 void execute(VariableState &variableState, VariableController &variableController,
57 const Properties &properties) const override
58 void execute(VariableId variableId, FuzzingState &fuzzingState,
59 VariableController &variableController, const Properties &) const override
58 60 {
59 Q_UNUSED(properties);
61 auto &variableState = fuzzingState.variableState(variableId);
60 62
61 63 qCInfo(LOG_FuzzingOperations()).noquote()
62 64 << "Deleting variable" << variableState.m_Variable->name() << "...";
63 65 variableController.deleteVariable(variableState.m_Variable);
64 66
65 67 // Updates variable's state
66 68 variableState.m_Range = INVALID_RANGE;
67 69 variableState.m_Variable = nullptr;
68 70 }
69 71 };
70 72
71 73 /**
72 74 * Defines a move operation through a range.
73 75 *
74 76 * A move operation is determined by three functions:
75 77 * - Two 'move' functions, used to indicate in which direction the beginning and the end of a range
76 78 * are going during the operation. These functions will be:
77 79 * -- {<- / <-} for pan left
78 80 * -- {-> / ->} for pan right
79 81 * -- {-> / <-} for zoom in
80 82 * -- {<- / ->} for zoom out
81 83 * - One 'max move' functions, used to compute the max delta at which the operation can move a
82 84 * range, according to a max range. For exemple, for a range of {1, 5} and a max range of {0, 10},
83 85 * max deltas will be:
84 86 * -- {0, 4} for pan left
85 87 * -- {6, 10} for pan right
86 88 * -- {3, 3} for zoom in
87 89 * -- {0, 6} for zoom out (same spacing left and right)
88 90 */
89 91 struct MoveOperation : public IFuzzingOperation {
90 92 using MoveFunction = std::function<double(double currentValue, double maxValue)>;
91 93 using MaxMoveFunction = std::function<double(const SqpRange &range, const SqpRange &maxRange)>;
92 94
93 95 explicit MoveOperation(MoveFunction rangeStartMoveFun, MoveFunction rangeEndMoveFun,
94 96 MaxMoveFunction maxMoveFun,
95 97 const QString &label = QStringLiteral("Move operation"))
96 98 : m_RangeStartMoveFun{std::move(rangeStartMoveFun)},
97 99 m_RangeEndMoveFun{std::move(rangeEndMoveFun)},
98 100 m_MaxMoveFun{std::move(maxMoveFun)},
99 101 m_Label{label}
100 102 {
101 103 }
102 104
103 bool canExecute(const VariableState &variableState) const override
105 bool canExecute(VariableId variableId, const FuzzingState &fuzzingState) const override
104 106 {
105 return variableState.m_Variable != nullptr;
107 return fuzzingState.variableState(variableId).m_Variable != nullptr;
106 108 }
107 109
108 void execute(VariableState &variableState, VariableController &variableController,
110 void execute(VariableId variableId, FuzzingState &fuzzingState,
111 VariableController &variableController,
109 112 const Properties &properties) const override
110 113 {
114 auto &variableState = fuzzingState.variableState(variableId);
111 115 auto variable = variableState.m_Variable;
112 116
113 117 // Gets the max range defined
114 118 auto maxRange = properties.value(MAX_RANGE_PROPERTY, QVariant::fromValue(INVALID_RANGE))
115 119 .value<SqpRange>();
116 120 auto variableRange = variable->range();
117 121
118 122 if (maxRange == INVALID_RANGE || variableRange.m_TStart < maxRange.m_TStart
119 123 || variableRange.m_TEnd > maxRange.m_TEnd) {
120 124 qCWarning(LOG_FuzzingOperations()) << "Can't execute operation: invalid max range";
121 125 return;
122 126 }
123 127
124 128 // Computes the max delta at which the variable can move, up to the limits of the max range
125 129 auto deltaMax = m_MaxMoveFun(variable->range(), maxRange);
126 130
127 131 // Generates random delta that will be used to move variable
128 132 auto delta = RandomGenerator::instance().generateDouble(0, deltaMax);
129 133
130 134 // Moves variable to its new range
131 135 auto newVariableRange = SqpRange{m_RangeStartMoveFun(variableRange.m_TStart, delta),
132 136 m_RangeEndMoveFun(variableRange.m_TEnd, delta)};
133 137 qCInfo(LOG_FuzzingOperations()).noquote()
134 138 << "Performing" << m_Label << "on" << variable->name() << "(from" << variableRange
135 139 << "to" << newVariableRange << ")...";
136 140 variableController.onRequestDataLoading({variable}, newVariableRange, false);
137 141
138 142 // Updates variable's state
139 143 variableState.m_Range = newVariableRange;
140 144 }
141 145
142 146 MoveFunction m_RangeStartMoveFun;
143 147 MoveFunction m_RangeEndMoveFun;
144 148 MaxMoveFunction m_MaxMoveFun;
145 149 QString m_Label;
146 150 };
147 151
148 152 struct UnknownOperation : public IFuzzingOperation {
149 bool canExecute(const VariableState &variableState) const override
150 {
151 Q_UNUSED(variableState);
152 return false;
153 }
153 bool canExecute(VariableId, const FuzzingState &) const override { return false; }
154 154
155 void execute(VariableState &variableState, VariableController &variableController,
156 const Properties &properties) const override
155 void execute(VariableId, FuzzingState &, VariableController &,
156 const Properties &) const override
157 157 {
158 Q_UNUSED(variableState);
159 Q_UNUSED(variableController);
160 Q_UNUSED(properties);
161 // Does nothing
162 158 }
163 159 };
164 160
165 161 } // namespace
166 162
167 163 std::unique_ptr<IFuzzingOperation> FuzzingOperationFactory::create(FuzzingOperationType type)
168 164 {
169 165 switch (type) {
170 166 case FuzzingOperationType::CREATE:
171 167 return std::make_unique<CreateOperation>();
172 168 case FuzzingOperationType::DELETE:
173 169 return std::make_unique<DeleteOperation>();
174 170 case FuzzingOperationType::PAN_LEFT:
175 171 return std::make_unique<MoveOperation>(
176 172 std::minus<double>(), std::minus<double>(),
177 173 [](const SqpRange &range, const SqpRange &maxRange) {
178 174 return range.m_TStart - maxRange.m_TStart;
179 175 },
180 176 QStringLiteral("Pan left operation"));
181 177 case FuzzingOperationType::PAN_RIGHT:
182 178 return std::make_unique<MoveOperation>(
183 179 std::plus<double>(), std::plus<double>(),
184 180 [](const SqpRange &range, const SqpRange &maxRange) {
185 181 return maxRange.m_TEnd - range.m_TEnd;
186 182 },
187 183 QStringLiteral("Pan right operation"));
188 184 case FuzzingOperationType::ZOOM_IN:
189 185 return std::make_unique<MoveOperation>(
190 186 std::plus<double>(), std::minus<double>(),
191 187 [](const SqpRange &range, const SqpRange &maxRange) {
192 188 Q_UNUSED(maxRange)
193 189 return range.m_TEnd - (range.m_TStart + range.m_TEnd) / 2.;
194 190 },
195 191 QStringLiteral("Zoom in operation"));
196 192 case FuzzingOperationType::ZOOM_OUT:
197 193 return std::make_unique<MoveOperation>(
198 194 std::minus<double>(), std::plus<double>(),
199 195 [](const SqpRange &range, const SqpRange &maxRange) {
200 196 return std::min(range.m_TStart - maxRange.m_TStart,
201 197 maxRange.m_TEnd - range.m_TEnd);
202 198 },
203 199 QStringLiteral("Zoom out operation"));
204 200 default:
205 201 // Default case returns unknown operation
206 202 break;
207 203 }
208 204
209 205 return std::make_unique<UnknownOperation>();
210 206 }
@@ -1,48 +1,50
1 1 #ifndef SCIQLOP_FUZZINGOPERATIONS_H
2 2 #define SCIQLOP_FUZZINGOPERATIONS_H
3 3
4 4 #include "FuzzingDefs.h"
5 5
6 6 #include <memory>
7 7 #include <set>
8 8
9 9 #include <QLoggingCategory>
10 10 #include <QMetaType>
11 11
12 12 Q_DECLARE_LOGGING_CATEGORY(LOG_FuzzingOperations)
13 13
14 14 class VariableController;
15 15
16 16 /**
17 17 * Enumeration of types of existing fuzzing operations
18 18 */
19 19 enum class FuzzingOperationType { CREATE, DELETE, PAN_LEFT, PAN_RIGHT, ZOOM_IN, ZOOM_OUT };
20 20
21 21 /// Interface that represents an operation that can be executed during a fuzzing test
22 22 struct IFuzzingOperation {
23 23 virtual ~IFuzzingOperation() noexcept = default;
24 24
25 /// Checks if the operation can be executed according to the current variable state passed in
26 /// parameter
27 virtual bool canExecute(const VariableState &variableState) const = 0;
28 /// Executes the operation on the variable state passed in parameter
29 /// @param variableState the variable state on which to execute the operation
25 /// Checks if the operation can be executed according to the current test's state for the
26 /// variable passed in parameter
27 virtual bool canExecute(VariableId variableId, const FuzzingState &fuzzingState) const = 0;
28 /// Executes the operation on the variable for which its identifier is passed in parameter
29 /// @param variableId the variable identifier
30 /// @param fuzzingState the current test's state on which to find the variable and execute the
31 /// operation
30 32 /// @param variableController the controller associated to the operation
31 33 /// @param properties properties that can be used to configure the operation
32 /// @remarks variableState is passed as a reference because, according to the operation, it can
33 /// be
34 /// modified (in/out parameter)
35 virtual void execute(VariableState &variableState, VariableController &variableController,
34 /// @remarks fuzzingState is passed as a reference because, according to the operation, it can
35 /// be modified (in/out parameter)
36 virtual void execute(VariableId variableId, FuzzingState &fuzzingState,
37 VariableController &variableController,
36 38 const Properties &properties = {}) const = 0;
37 39 };
38 40
39 41 /// Factory of @sa IFuzzingOperation
40 42 struct FuzzingOperationFactory {
41 43 /// Creates a fuzzing operation from a type
42 44 static std::unique_ptr<IFuzzingOperation> create(FuzzingOperationType type);
43 45 };
44 46
45 47 using WeightedOperationsTypes = std::map<FuzzingOperationType, double>;
46 48 Q_DECLARE_METATYPE(WeightedOperationsTypes)
47 49
48 50 #endif // SCIQLOP_FUZZINGOPERATIONS_H
@@ -1,332 +1,328
1 1 #include "FuzzingDefs.h"
2 2 #include "FuzzingOperations.h"
3 3 #include "FuzzingUtils.h"
4 4 #include "FuzzingValidators.h"
5 5
6 6 #include "AmdaProvider.h"
7 7
8 8 #include <Network/NetworkController.h>
9 9 #include <Settings/SqpSettingsDefs.h>
10 10 #include <SqpApplication.h>
11 11 #include <Time/TimeController.h>
12 12 #include <Variable/Variable.h>
13 13 #include <Variable/VariableController.h>
14 14
15 15 #include <QLoggingCategory>
16 16 #include <QObject>
17 17 #include <QtTest>
18 18
19 19 #include <memory>
20 20
21 21 Q_LOGGING_CATEGORY(LOG_TestAmdaFuzzing, "TestAmdaFuzzing")
22 22
23 23 namespace {
24 24
25 25 // /////// //
26 26 // Aliases //
27 27 // /////// //
28 28
29 using VariableId = int;
30 29 using Weight = double;
31 30 using Weights = std::vector<Weight>;
32 31
33 32 using VariableOperation = std::pair<VariableId, std::shared_ptr<IFuzzingOperation> >;
34 33 using VariablesOperations = std::vector<VariableOperation>;
35 34
36 35 using WeightedOperationsPool = std::map<std::shared_ptr<IFuzzingOperation>, Weight>;
37 using VariablesPool = std::map<VariableId, VariableState>;
38 36 using Validators = std::vector<std::shared_ptr<IFuzzingValidator> >;
39 37
40 38 // ///////// //
41 39 // Constants //
42 40 // ///////// //
43 41
44 42 // Defaults values used when the associated properties have not been set for the test
45 43 const auto NB_MAX_OPERATIONS_DEFAULT_VALUE = 100;
46 44 const auto NB_MAX_VARIABLES_DEFAULT_VALUE = 1;
47 45 const auto AVAILABLE_OPERATIONS_DEFAULT_VALUE = QVariant::fromValue(WeightedOperationsTypes{
48 46 {FuzzingOperationType::CREATE, 1.},
49 47 {FuzzingOperationType::DELETE, 0.1}, // Delete operation is less frequent
50 48 {FuzzingOperationType::PAN_LEFT, 1.},
51 49 {FuzzingOperationType::PAN_RIGHT, 1.},
52 50 {FuzzingOperationType::ZOOM_IN, 1.},
53 51 {FuzzingOperationType::ZOOM_OUT, 1.}});
54 52 const auto CACHE_TOLERANCE_DEFAULT_VALUE = 0.2;
55 53
56 54 /// Delay between each operation (in ms)
57 55 const auto OPERATION_DELAY_DEFAULT_VALUE = 3000;
58 56
59 57 /// Validators for the tests (executed in the order in which they're defined)
60 58 const auto VALIDATORS_DEFAULT_VALUE = QVariant::fromValue(
61 59 ValidatorsTypes{{FuzzingValidatorType::RANGE, FuzzingValidatorType::DATA}});
62 60
63 61 // /////// //
64 62 // Methods //
65 63 // /////// //
66 64
67 65 /// Goes through the variables pool and operations pool to determine the set of {variable/operation}
68 66 /// pairs that are valid (i.e. operation that can be executed on variable)
69 67 std::pair<VariablesOperations, Weights>
70 availableOperations(const VariablesPool &variablesPool,
71 const WeightedOperationsPool &operationsPool)
68 availableOperations(const FuzzingState &fuzzingState, const WeightedOperationsPool &operationsPool)
72 69 {
73 70 VariablesOperations result{};
74 71 Weights weights{};
75 72
76 for (const auto &variablesPoolEntry : variablesPool) {
73 for (const auto &variablesPoolEntry : fuzzingState.m_VariablesPool) {
77 74 auto variableId = variablesPoolEntry.first;
78 const auto &variableState = variablesPoolEntry.second;
79 75
80 76 for (const auto &operationsPoolEntry : operationsPool) {
81 77 auto operation = operationsPoolEntry.first;
82 78 auto weight = operationsPoolEntry.second;
83 79
84 80 // A pair is valid if the current operation can be executed on the current variable
85 if (operation->canExecute(variableState)) {
81 if (operation->canExecute(variableId, fuzzingState)) {
86 82 result.push_back({variableId, operation});
87 83 weights.push_back(weight);
88 84 }
89 85 }
90 86 }
91 87
92 88 return {result, weights};
93 89 }
94 90
95 91 WeightedOperationsPool createOperationsPool(const WeightedOperationsTypes &types)
96 92 {
97 93 WeightedOperationsPool result{};
98 94
99 95 std::transform(
100 96 types.cbegin(), types.cend(), std::inserter(result, result.end()), [](const auto &type) {
101 97 return std::make_pair(FuzzingOperationFactory::create(type.first), type.second);
102 98 });
103 99
104 100 return result;
105 101 }
106 102
107 103 Validators createValidators(const ValidatorsTypes &types)
108 104 {
109 105 Validators result{};
110 106
111 107 std::transform(types.cbegin(), types.cend(), std::inserter(result, result.end()),
112 108 [](const auto &type) { return FuzzingValidatorFactory::create(type); });
113 109
114 110 return result;
115 111 }
116 112
117 113 /**
118 114 * Validates all the variables' states passed in parameter, according to a set of validators
119 115 * @param variablesPool the variables' states
120 116 * @param validators the validators used for validation
121 117 */
122 118 void validate(const VariablesPool &variablesPool, const Validators &validators)
123 119 {
124 120 for (const auto &variablesPoolEntry : variablesPool) {
125 121 auto variableId = variablesPoolEntry.first;
126 122 const auto &variableState = variablesPoolEntry.second;
127 123
128 124 auto variableMessage = variableState.m_Variable ? variableState.m_Variable->name()
129 125 : QStringLiteral("null variable");
130 126 qCInfo(LOG_TestAmdaFuzzing()).noquote() << "Validating state of variable at index"
131 127 << variableId << "(" << variableMessage << ")...";
132 128
133 129 for (const auto &validator : validators) {
134 130 validator->validate(VariableState{variableState});
135 131 }
136 132
137 133 qCInfo(LOG_TestAmdaFuzzing()).noquote() << "Validation completed.";
138 134 }
139 135 }
140 136
141 137 /**
142 138 * Class to run random tests
143 139 */
144 140 class FuzzingTest {
145 141 public:
146 142 explicit FuzzingTest(VariableController &variableController, Properties properties)
147 143 : m_VariableController{variableController},
148 144 m_Properties{std::move(properties)},
149 m_VariablesPool{}
145 m_FuzzingState{}
150 146 {
151 147 // Inits variables pool: at init, all variables are null
152 148 for (auto variableId = 0; variableId < nbMaxVariables(); ++variableId) {
153 m_VariablesPool[variableId] = VariableState{};
149 m_FuzzingState.m_VariablesPool[variableId] = VariableState{};
154 150 }
155 151 }
156 152
157 153 void execute()
158 154 {
159 155 qCInfo(LOG_TestAmdaFuzzing()).noquote() << "Running" << nbMaxOperations() << "operations on"
160 156 << nbMaxVariables() << "variable(s)...";
161 157
162 158 auto canExecute = true;
163 159 for (auto i = 0; i < nbMaxOperations() && canExecute; ++i) {
164 160 // Retrieves all operations that can be executed in the current context
165 161 VariablesOperations variableOperations{};
166 162 Weights weights{};
167 163 std::tie(variableOperations, weights)
168 = availableOperations(m_VariablesPool, operationsPool());
164 = availableOperations(m_FuzzingState, operationsPool());
169 165
170 166 canExecute = !variableOperations.empty();
171 167 if (canExecute) {
172 168 // Of the operations available, chooses a random operation and executes it
173 169 auto variableOperation
174 170 = RandomGenerator::instance().randomChoice(variableOperations, weights);
175 171
176 172 auto variableId = variableOperation.first;
177 auto &variableState = m_VariablesPool.at(variableId);
178 173 auto fuzzingOperation = variableOperation.second;
179 174
180 fuzzingOperation->execute(variableState, m_VariableController, m_Properties);
175 fuzzingOperation->execute(variableId, m_FuzzingState, m_VariableController,
176 m_Properties);
181 177 QTest::qWait(operationDelay());
182 178
183 179 // Validates variables
184 validate(m_VariablesPool, validators());
180 validate(m_FuzzingState.m_VariablesPool, validators());
185 181 }
186 182 else {
187 183 qCInfo(LOG_TestAmdaFuzzing()).noquote()
188 184 << "No more operations are available, the execution of the test will stop...";
189 185 }
190 186 }
191 187
192 188 qCInfo(LOG_TestAmdaFuzzing()).noquote() << "Execution of the test completed.";
193 189 }
194 190
195 191 private:
196 192 int nbMaxOperations() const
197 193 {
198 194 static auto result
199 195 = m_Properties.value(NB_MAX_OPERATIONS_PROPERTY, NB_MAX_OPERATIONS_DEFAULT_VALUE)
200 196 .toInt();
201 197 return result;
202 198 }
203 199
204 200 int nbMaxVariables() const
205 201 {
206 202 static auto result
207 203 = m_Properties.value(NB_MAX_VARIABLES_PROPERTY, NB_MAX_VARIABLES_DEFAULT_VALUE).toInt();
208 204 return result;
209 205 }
210 206
211 207 int operationDelay() const
212 208 {
213 209 static auto result
214 210 = m_Properties.value(OPERATION_DELAY_PROPERTY, OPERATION_DELAY_DEFAULT_VALUE).toInt();
215 211 return result;
216 212 }
217 213
218 214 WeightedOperationsPool operationsPool() const
219 215 {
220 216 static auto result = createOperationsPool(
221 217 m_Properties.value(AVAILABLE_OPERATIONS_PROPERTY, AVAILABLE_OPERATIONS_DEFAULT_VALUE)
222 218 .value<WeightedOperationsTypes>());
223 219 return result;
224 220 }
225 221
226 222 Validators validators() const
227 223 {
228 224 static auto result
229 225 = createValidators(m_Properties.value(VALIDATORS_PROPERTY, VALIDATORS_DEFAULT_VALUE)
230 226 .value<ValidatorsTypes>());
231 227 return result;
232 228 }
233 229
234 230 VariableController &m_VariableController;
235 231 Properties m_Properties;
236 VariablesPool m_VariablesPool;
232 FuzzingState m_FuzzingState;
237 233 };
238 234
239 235 } // namespace
240 236
241 237 class TestAmdaFuzzing : public QObject {
242 238 Q_OBJECT
243 239
244 240 private slots:
245 241 /// Input data for @sa testFuzzing()
246 242 void testFuzzing_data();
247 243 void testFuzzing();
248 244 };
249 245
250 246 void TestAmdaFuzzing::testFuzzing_data()
251 247 {
252 248 // ////////////// //
253 249 // Test structure //
254 250 // ////////////// //
255 251
256 252 QTest::addColumn<Properties>("properties"); // Properties for random test
257 253
258 254 // ////////// //
259 255 // Test cases //
260 256 // ////////// //
261 257
262 258 auto maxRange = SqpRange::fromDateTime({2017, 1, 1}, {0, 0}, {2017, 1, 5}, {0, 0});
263 259 MetadataPool metadataPool{{{"dataType", "vector"}, {"xml:id", "imf"}}};
264 260
265 261 // Note: we don't use auto here as we want to pass std::shared_ptr<IDataProvider> as is in the
266 262 // QVariant
267 263 std::shared_ptr<IDataProvider> provider = std::make_shared<AmdaProvider>();
268 264
269 265 QTest::newRow("fuzzingTest") << Properties{
270 266 {MAX_RANGE_PROPERTY, QVariant::fromValue(maxRange)},
271 267 {METADATA_POOL_PROPERTY, QVariant::fromValue(metadataPool)},
272 268 {PROVIDER_PROPERTY, QVariant::fromValue(provider)}};
273 269 }
274 270
275 271 void TestAmdaFuzzing::testFuzzing()
276 272 {
277 273 QFETCH(Properties, properties);
278 274
279 275 // Sets cache property
280 276 QSettings settings{};
281 277 auto cacheTolerance = properties.value(CACHE_TOLERANCE_PROPERTY, CACHE_TOLERANCE_DEFAULT_VALUE);
282 278 settings.setValue(GENERAL_TOLERANCE_AT_INIT_KEY, cacheTolerance);
283 279 settings.setValue(GENERAL_TOLERANCE_AT_UPDATE_KEY, cacheTolerance);
284 280
285 281 auto &variableController = sqpApp->variableController();
286 282 auto &timeController = sqpApp->timeController();
287 283
288 284 // Generates random initial range (bounded to max range)
289 285 auto maxRange = properties.value(MAX_RANGE_PROPERTY, QVariant::fromValue(INVALID_RANGE))
290 286 .value<SqpRange>();
291 287
292 288 QVERIFY(maxRange != INVALID_RANGE);
293 289
294 290 auto initialRangeStart
295 291 = RandomGenerator::instance().generateDouble(maxRange.m_TStart, maxRange.m_TEnd);
296 292 auto initialRangeEnd
297 293 = RandomGenerator::instance().generateDouble(maxRange.m_TStart, maxRange.m_TEnd);
298 294 if (initialRangeStart > initialRangeEnd) {
299 295 std::swap(initialRangeStart, initialRangeEnd);
300 296 }
301 297
302 298 // Sets initial range on time controller
303 299 SqpRange initialRange{initialRangeStart, initialRangeEnd};
304 300 qCInfo(LOG_TestAmdaFuzzing()).noquote() << "Setting initial range to" << initialRange << "...";
305 301 timeController.onTimeToUpdate(initialRange);
306 302 properties.insert(INITIAL_RANGE_PROPERTY, QVariant::fromValue(initialRange));
307 303
308 304 FuzzingTest test{variableController, properties};
309 305 test.execute();
310 306 }
311 307
312 308 int main(int argc, char *argv[])
313 309 {
314 310 QLoggingCategory::setFilterRules(
315 311 "*.warning=false\n"
316 312 "*.info=false\n"
317 313 "*.debug=false\n"
318 314 "FuzzingOperations.info=true\n"
319 315 "FuzzingValidators.info=true\n"
320 316 "TestAmdaFuzzing.info=true\n");
321 317
322 318 SqpApplication app{argc, argv};
323 319 SqpApplication::setOrganizationName("LPP");
324 320 SqpApplication::setOrganizationDomain("lpp.fr");
325 321 SqpApplication::setApplicationName("SciQLop-TestFuzzing");
326 322 app.setAttribute(Qt::AA_Use96Dpi, true);
327 323 TestAmdaFuzzing testObject{};
328 324 QTEST_SET_MAIN_SOURCE_PATH
329 325 return QTest::qExec(&testObject, argc, argv);
330 326 }
331 327
332 328 #include "TestAmdaFuzzing.moc"
General Comments 0
You need to be logged in to leave comments. Login now