diff --git a/plugins/amda/tests/FuzzingOperations.cpp b/plugins/amda/tests/FuzzingOperations.cpp index 124ae35..8341ed1 100644 --- a/plugins/amda/tests/FuzzingOperations.cpp +++ b/plugins/amda/tests/FuzzingOperations.cpp @@ -8,6 +8,8 @@ #include +#include + Q_LOGGING_CATEGORY(LOG_FuzzingOperations, "FuzzingOperations") namespace { @@ -41,6 +43,54 @@ struct CreateOperation : public IFuzzingOperation { } }; +/** + * Defines a move operation through a range. + * + * A move operation is determined by three functions: + * - Two 'move' functions, used to indicate in which direction the beginning and the end of a range + * are going during the operation. These functions will be: + * -- {<- / <-} for pan left + * -- {-> / ->} for pan right + * -- {-> / <-} for zoom in + * -- {<- / ->} for zoom out + * - One 'max move' functions, used to compute the max delta at which the operation can move a + * range, according to a max range. For exemple, for a range of {1, 5} and a max range of {0, 10}, + * max deltas will be: + * -- {0, 4} for pan left + * -- {6, 10} for pan right + * -- {3, 3} for zoom in + * -- {0, 6} for zoom out (same spacing left and right) + */ +struct MoveOperation : public IFuzzingOperation { + using MoveFunction = std::function; + using MaxMoveFunction = std::function; + + explicit MoveOperation(MoveFunction rangeStartMoveFun, MoveFunction rangeEndMoveFun, + MaxMoveFunction maxMoveFun, + const QString &label = QStringLiteral("Move operation")) + : m_RangeStartMoveFun{std::move(rangeStartMoveFun)}, + m_RangeEndMoveFun{std::move(rangeEndMoveFun)}, + m_MaxMoveFun{std::move(maxMoveFun)}, + m_Label{label} + { + } + + bool canExecute(std::shared_ptr variable) const override + { + return variable != nullptr; + } + + void execute(std::shared_ptr &variable, VariableController &variableController, + const Properties &properties) const override + { + } + + MoveFunction m_RangeStartMoveFun; + MoveFunction m_RangeEndMoveFun; + MaxMoveFunction m_MaxMoveFun; + QString m_Label; +}; + struct UnknownOperation : public IFuzzingOperation { bool canExecute(std::shared_ptr variable) const override { @@ -65,6 +115,36 @@ std::unique_ptr FuzzingOperationFactory::create(FuzzingOperat switch (type) { case FuzzingOperationType::CREATE: return std::make_unique(); + case FuzzingOperationType::PAN_LEFT: + return std::make_unique( + std::minus(), std::minus(), + [](const SqpRange &range, const SqpRange &maxRange) { + return range.m_TStart - maxRange.m_TStart; + }, + QStringLiteral("Pan left operation")); + case FuzzingOperationType::PAN_RIGHT: + return std::make_unique( + std::plus(), std::plus(), + [](const SqpRange &range, const SqpRange &maxRange) { + return maxRange.m_TEnd - range.m_TEnd; + }, + QStringLiteral("Pan right operation")); + case FuzzingOperationType::ZOOM_IN: + return std::make_unique( + std::plus(), std::minus(), + [](const SqpRange &range, const SqpRange &maxRange) { + Q_UNUSED(maxRange) + return range.m_TEnd - (range.m_TStart + range.m_TEnd) / 2.; + }, + QStringLiteral("Zoom in operation")); + case FuzzingOperationType::ZOOM_OUT: + return std::make_unique( + std::minus(), std::plus(), + [](const SqpRange &range, const SqpRange &maxRange) { + return std::min(range.m_TStart - maxRange.m_TStart, + maxRange.m_TEnd - range.m_TEnd); + }, + QStringLiteral("Zoom out operation")); default: // Default case returns unknown operation break; diff --git a/plugins/amda/tests/FuzzingOperations.h b/plugins/amda/tests/FuzzingOperations.h index fd2c380..fecd2dc 100644 --- a/plugins/amda/tests/FuzzingOperations.h +++ b/plugins/amda/tests/FuzzingOperations.h @@ -17,7 +17,7 @@ class VariableController; /** * Enumeration of types of existing fuzzing operations */ -enum class FuzzingOperationType { CREATE }; +enum class FuzzingOperationType { CREATE, PAN_LEFT, PAN_RIGHT, ZOOM_IN, ZOOM_OUT }; /// Interface that represents an operation that can be executed during a fuzzing test struct IFuzzingOperation {