.. _cit-varianter-plugin:

====================
CIT Varianter Plugin
====================

This plugin is an implementation of a "Combinatorial Interaction
Testing with Constraints" algorithm for the Avocado varianter
functionality.  It generates an optimal number of variants, which in
turn become different test scenarios.
To learn more about this algorithm, please take a look to the papers
listed below.

To install the Avocado CIT plugin from pip, use::

    $ sudo pip install avocado-framework-plugin-varianter-cit

To run the example below, use the test included in the avocado code ::

    $ git clone https://github.com/avocado-framework/avocado.git

Please refer to ``avocado/examples/varianter_cit/params.cit`` for an example
of a input file.

Input file format
=================

The following is the general structure of a input file::

  PARAMETERS
  Parameter_1 [Value_1,  Value_2, Value_3, Value_4]
  Parameter_2 [Value_1,  Value_2, Value_3, Value_4]
  Parameter_3 [Value_1,  Value_2, Value_3, Value_4]

  CONSTRAINTS
  Parameter_1 != Value_1 || Parameter_2 != Value_3
  Parameter_3 != Value_2 || Parameter_2 != Value_4 || Parameter_1 != Value_4

The input file has two parts, parameters and constraints.

Parameters
----------

* Each line represent one parameter.

* Each parameter has a name, and a list of values ​​inside brackets.

Constraints:
------------

* Constraints have to be in Conjunctive normal form.

* Constraints use these tree operands: ``!=, OR, AND``

* ``||`` represents operand ``OR`` and new line represents operand ``AND``.

* In the example, this is the logic formula ::

    ((P_1 != V1 OR P_2 != V_3) AND (P_3 != V_2 OR P_2 != V_4 OR P_1 != Value_4))

Usage
=====

.. note:: the algorithm employed here can be CPU intensive.  If you
          want more information on the progress of the combinatorial
          calculation, add ``--debug`` to a command line, such as
          ``avocado variants --debug --cit-parameter-file $PATH``

Cit varianter plugin runs with two parameters:

- ``--cit-parameter-file`` with path to the input file
- ``--cit-order-of-combinations`` with strength of combination (default is 2)

To see the variants generated by this demo implementation, execute::

    $ avocado variants --cit-parameter-file avocado/examples/varianter_cit/params.cit
    CIT Variants (28):
    Variant red-square-solid-plastic-anodic-6-4-4-2:    /
    Variant green-circle-gas-leather-cathodic-7-5-4-1:    /
    Variant green-triangle-liquid-leather-anodic-5-4-1-3:    /
    Variant green-square-liquid-plastic-anodic-3-1-4-5:    /
    Variant red-triangle-solid-leather-anodic-5-2-4-1:    /
    Variant black-triangle-gas-leather-anodic-7-1-1-2:    /
    Variant green-circle-solid-aluminum-cathodic-7-1-5-4:    /
    Variant red-square-gas-plastic-cathodic-6-3-5-3:    /
    Variant gold-triangle-solid-leather-anodic-6-5-1-4:    /
    Variant gold-triangle-gas-leather-anodic-3-2-5-2:    /
    Variant gold-square-gas-plastic-cathodic-5-1-1-1:    /
    Variant red-circle-gas-plastic-anodic-1-1-3-3:    /
    Variant red-circle-gas-aluminum-cathodic-3-3-1-5:    /
    Variant black-triangle-solid-plastic-cathodic-5-5-5-5:    /
    Variant gold-triangle-gas-leather-anodic-7-4-2-5:    /
    Variant black-triangle-gas-aluminum-cathodic-6-1-2-1:    /
    Variant gold-square-liquid-leather-cathodic-3-5-2-3:    /
    Variant black-square-solid-aluminum-cathodic-7-2-4-3:    /
    Variant black-circle-liquid-aluminum-anodic-1-4-5-1:    /
    Variant black-triangle-gas-leather-cathodic-7-3-3-1:    /
    Variant green-square-solid-aluminum-cathodic-1-3-2-2:    /
    Variant gold-triangle-gas-aluminum-anodic-1-3-4-4:    /
    Variant red-square-liquid-plastic-anodic-7-2-2-4:    /
    Variant gold-circle-liquid-aluminum-anodic-5-5-3-2:    /
    Variant red-triangle-gas-leather-anodic-1-5-1-5:    /
    Variant gold-circle-liquid-aluminum-cathodic-5-3-2-4:    /
    Variant black-square-solid-plastic-cathodic-3-4-3-4:    /
    Variant green-circle-liquid-plastic-cathodic-6-2-3-5:    /

.. note:: The exact variants generated are not guaranteed to be the same
          across executions.

You can enable more verbosity, making each variant to show its content::

    $ avocado variants --cit-parameter-file avocado/examples/varianter_cit/params.cit -c
    CIT Variants (28):

    Variant red-circle-solid-plastic-cathodic-6-3-3-1:    /
        /:coating  => cathodic
        /:color    => red
        /:material => plastic
        /:p10      => 1
        /:p7       => 6
        /:p8       => 3
        /:p9       => 3
        /:shape    => circle
        /:state    => solid

    Variant black-circle-liquid-aluminum-anodic-6-5-1-2:    /
        /:coating  => anodic
        /:color    => black
        /:material => aluminum
        /:p10      => 2
        /:p7       => 6
        /:p8       => 5
        /:p9       => 1
        /:shape    => circle
        /:state    => liquid

    ... Skip 26 more variants ...

To execute tests with those combinations use::

    $ avocado run avocado/examples/tests/passtest.py --cit-parameter-file avocado/examples/varianter_cit/params.cit
    JOB ID     : 6abd9e9f1ff9ed33a353ca8f3ef845cd4cc404a5
    JOB LOG    : $HOME/avocado/job-results/job-2018-07-23T08.46-6abd9e9/job.log
     (01/25) passtest.py:PassTest.test;black-circle-gas-plastic-anodic-3-3-5-5: PASS (0.04 s)
     (02/25) passtest.py:PassTest.test;gold-square-liquid-leather-anodic-3-2-1-4: PASS (0.03 s)
     (03/25) passtest.py:PassTest.test;green-square-gas-plastic-cathodic-3-5-4-1: PASS (0.04 s)
     (04/25) passtest.py:PassTest.test;gold-circle-solid-leather-anodic-6-4-4-2: PASS (0.04 s)
     (05/25) passtest.py:PassTest.test;green-triangle-liquid-aluminum-cathodic-7-4-5-1: PASS (0.04 s)
     (06/25) passtest.py:PassTest.test;black-circle-gas-plastic-cathodic-1-4-3-4: PASS (0.04 s)
     (07/25) passtest.py:PassTest.test;red-square-gas-leather-anodic-3-4-2-3: PASS (0.04 s)
     (08/25) passtest.py:PassTest.test;gold-triangle-solid-leather-anodic-1-3-2-1: PASS (0.04 s)
     (09/25) passtest.py:PassTest.test;green-circle-gas-plastic-cathodic-7-1-2-4: PASS (0.04 s)
     (10/25) passtest.py:PassTest.test;green-triangle-gas-aluminum-cathodic-6-2-2-5: PASS (0.04 s)
     (11/25) passtest.py:PassTest.test;black-circle-liquid-plastic-cathodic-5-5-2-2: PASS (0.03 s)
     (12/25) passtest.py:PassTest.test;red-square-solid-aluminum-anodic-5-2-3-1: PASS (0.04 s)
     (13/25) passtest.py:PassTest.test;gold-square-solid-leather-anodic-7-5-3-5: PASS (0.04 s)
     (14/25) passtest.py:PassTest.test;green-triangle-solid-leather-anodic-1-5-1-3: PASS (0.04 s)
     (15/25) passtest.py:PassTest.test;black-circle-liquid-leather-cathodic-6-1-1-1: PASS (0.04 s)
     (16/25) passtest.py:PassTest.test;red-triangle-liquid-plastic-anodic-6-3-3-3: PASS (0.04 s)
     (17/25) passtest.py:PassTest.test;green-triangle-solid-plastic-cathodic-5-3-4-4: PASS (0.04 s)
     (18/25) passtest.py:PassTest.test;red-square-liquid-aluminum-anodic-6-5-5-4: PASS (0.04 s)
     (19/25) passtest.py:PassTest.test;red-square-gas-aluminum-cathodic-7-3-1-2: PASS (0.04 s)
     (20/25) passtest.py:PassTest.test;red-square-liquid-aluminum-anodic-1-1-4-5: PASS (0.04 s)
     (21/25) passtest.py:PassTest.test;gold-circle-gas-plastic-anodic-5-4-1-5: PASS (0.04 s)
     (22/25) passtest.py:PassTest.test;gold-circle-solid-leather-anodic-5-1-5-3: PASS (0.04 s)
     (23/25) passtest.py:PassTest.test;red-circle-liquid-plastic-cathodic-1-2-5-2: PASS (0.04 s)
     (24/25) passtest.py:PassTest.test;green-triangle-solid-aluminum-anodic-3-1-3-2: PASS (0.04 s)
     (25/25) passtest.py:PassTest.test;black-circle-solid-aluminum-cathodic-7-2-4-3: PASS (0.03 s)
    RESULTS    : PASS 25 | ERROR 0 | FAIL 0 | SKIP 0 | WARN 0 | INTERRUPT 0 | CANCEL 0
    JOB TIME   : 1.21 s
    JOB HTML   : $HOME/avocado/job-results/job-2018-07-23T08.46-6abd9e9/results.html

Publications
============

The publication by Ahmed, Bestoun S., Kamal Z. Zamli, and Chee Peng
Lim, entitled `“Application of particle swarm optimization to uniform
and variable strength covering array construction”
<https://www.sciencedirect.com/science/article/pii/S1568494611004716>`__,
Applied Soft Computing, 12(4), 2012, pp. 1330-1347, contains the basis
for the algorithm and implementation of this feature.

Additionally, the publication by Bestoun S. Ahmed, Amador Pahim,
Cleber R. Rosa Junior, D. Richard Kuhn and Miroslav Bures, entitled
`"Towards an Automated Unified Framework to Run Applications for
Combinatorial Interaction Testing"
<https://arxiv.org/pdf/1903.05387.pdf>`__, contain a practical use
case of this software.
