woensdag 28 april 2010

Haskell Combinatory Tool

The Haskell library I have been working allows the creation of combinations given an input and set of rules.

First, let's look at the input types:

type Class = String
data Partition = Node String [Partition] | Leaf Class
data Category = Cat String [Partition]

A category is a domain from which one class can chosen per combination. A partition is a subdomain of a category. A class is one of the possible values for its category. Let's look at an example (the same shown at the CTE XL tool paper).

A geometric figure has 3 different atributes: size, shape and color. These three atributes will be our categories. The size can be big or small: those are the classes for the category shape. The color can be blue, red or yellow (classes for color). The shape can be a square, a circle or a triangle. If it is a triangle, it can be isosceles, scalene or equilateral. We have two classes (square and circle), and a partition (triangle) with three classes.

The tool allows us to generate basic combinations or ruled combinations. We have two types of basic combinations:

Minimal Combination: from the given input, the tool generates a number of combinations where each class appears at least once. An example of a minimal combination for the geometric figure input could be:

Circle, Big, Red
Square, Small, Blue
Isosceles, Big, Yellow
Equilateral, Small, Red
Scalene, Big, Blue
Full Combination: here, the tool generates all the possible combinations for the given input. While in small inputs, like the example one, this is easy to do (30 combinations possible), for larger inputs, it can take a long time.

The tool also offers the possibility of adding combination rules:
data Operator = Plus | Times | ST | STN
data LogicOp = And | Or | Xor | Nor | Equi | Impl
data Rule = Rop Operator Rule Rule | RLog LogicOp [String] [String] | P [String] | NotP [String] | Ctg String
Lets explain all these rules.

First we start by the selection rules, as these are the simpler ones:

P x: Returns the list of classes from partition(s) x (note that it receives a list of partitions).
NotP x: Returns the list of classes from the category where x belongs, except the classes contained in partition(s) x.
Ctg x: Returns the list of classes from category x.

Operator Rules:

These rules are the ones that allow us to build combinations with classes from different categories.

Plus a b (a ++ b): Returns the minimal combination of a and b. Note that a and b are rules too, that will be evaluated first. It will create a list of combinations where all combinations from a and b appear at least once.
Times a b (a ** b): Returns the full combination of a and b.
ST (such that) a b: After evaluating a and b, returns the list of combinations in a that cover some combination in b.
STN (such that not) a b: Returns the list of combinations in a that don't cover any combination of b.

Logical Rules:

These rules where introduced to create more "understandable" rules, as all of them can be derived from operator rules. Note that while operator rules have two rules as arguments, these rules have two lists of strings, that represent a list of partitions from two different categories.

For example, the rule Or ["Blue"] ["Triangle"] will return all the combinations between Color and Shape except those where Color isn't Blue and Shape isn't a class from Triangle.

Completeness of combinations

The evaluation of the rules by itself doesn't garantee that we will get a valid list of combinations. If we evaluate P ["Square"] the result would only be [["Square"]].

To ensure that we get a valid list list of combinations, after the rules are evaluated, the tool checks which categories don't have a value in the solution, and combines the list of classes from these categories with the solution, making sure each class appears at least once. If we calculate P ["Square"] in the tool, the result is:

Red, Square, Big
Blue, Square, Small
Yellow, Square, Big



CTE Tool Paper: http://www.systematic-testing.com/documents/eurostar2000.pdf

dinsdag 16 februari 2010