Logic

Model logic is a set of constraints that define allowed combinations of input parameters and a set of assignments to define values of output parameters. Logic may be used with a function or with a structure.

  • Logic of a structure defines dependencies between its parameters.
  • Logic of a function defines rules for all parameters of the function.

To access logic of a function, click on the FUNCTION LOGIC tab, which is located at the bottom of the screen. Additionally, the list of logic elements is available on the left panel.

Accessing function logic

Fig. 1 – Accessing function logic.

To access logic for a structure, first create a structure and the logic panel should automatically appear. Note, that assignments can be used with functions only (they define values of output parameters which are not allowed in structures).

Accessing structure logic

Fig. 2 – Accessing structure logic.

Logic elements take the form of a standard node, similar to (already explained) parameters and choices. You can add comments, rearrange them, delete them, etc. If something goes wrong don’t worry, you can always undo your actions.

Managing logic

Fig. 3 – Managing logic.

To manually create a constraint, first select the function, click on the FUNCTION LOGIC panel and select ‘Constraints’. A button names ADD CONSTRAINT should appear. Click on it and select a meaningful name. Afterwards, click on the expressions field and write logic (or click the ‘tab’ button). If you want to create an alias element or an assignment element, the procedure is exactly the same.

Creating logic nodes manually

Fig. 4 – Creating logic nodes manually.

We know that writing the logic expression manually might not be a trivial task, and therefore, you can use the AI assistant to do it for you. In this scenario create a name (which can be AI generated as well), switch to the ‘expression’ input and wait a few seconds.

Creating logic nodes with assistant

Fig. 5 – Creating logic nodes with assistant.

This constraint means that giants can only yield axes and maces. Generated test cases prove that the constraint works as expected.

Test cases affected by logic

Fig. 6 – Test cases affected by logic.

Now, it’s time to explain expressions in more detail.

Constraint

A constraint defines an expression that must be fulfilled by all tests generated from the model. The value of expression in the constraint may be defined as Invariant or Implication.

Invariant

Invariant is an expression type in form of a single statement that must always hold in the generated tests. For example, the following invariant constraint:

Constraint node, invariant

Fig. 7a – Constraint node, invariant.

means that in the resulting test suite, the choice “dagger” cannot be a part of the “foe weapon” parameter.

Implication

An implication is an expression in a form «IF CONDITION THEN RESULT» (or alternative notation «CONDITION => RESULT»), where CONDITION and RESULT are statements with the same syntax as in the invariant version of the constraint. Implications define constraints that require that for each tests where the CONDITION part is fulfilled, the RESULT part must also be true. For example, the following implication constraint:

Constraint node, implication

Fig. 7b – Constraint node, implication.

means that “Susan” and “Lucy” can only use “dagger”.

Assignments

Assignments are defining values of output parameters in the tests. The syntax is «IF CONDITION THEN ASSIGNMENTS_LIST» (or alternatively «CONDITION => ASSIGNMENT_LIST»), where CONDITION is a statement and ASSIGNMENT_LIST is a comma separated list of assignments of values to chosen output parameters. For example, the following assignment:

Assignment node

Fig. 8a – Assignment node.

means that whenever Peter is in a battle, the outcome is awesome. Note, that for this example we had to create an output parameter:

Output parameter

Fig. 8b – Output parameter.

Output parameters are discussed in more detail in a different tutorial.

Aliases

Aliases are macros that allow defining short names for long statements used in constraints and assignments. Aliases may be then used by their names in other statements of all logic elements (aliases, constraints or assignments). For example, with the following alias:

Alias node

Fig. 9 – Alias node.

we can simplify the previously created constraint:

Constraint nodes improved with aliases

Fig. 10 – Constraint nodes improved with aliases.

Statements

The detailed explanation of statements is not a part of this short introduction. To find more information please refer to the official documentation, i.e. https://pypi.org/project/testomaton/.