You are on page 1of 5

LCSAJ coverage

Execution of a program generally proceeds in two ways:


sequentially or jumping depending on the statement. When there
is at least a branch, the execution can be seen as proceeding in
pairs where the first element of the pair is a sequence of
statements, executed one after the other, terminating with a jump,
the second element, to the next of such pair.
Thus, such pair is called a Linear Code Sequence and Jump
(LCSAJ) unit.
An LCSAJ is represented as a triple (X, Y, Z) where X and Y are,
respectively, locations of the first and the last statements of the
sequential portion of code and Z is the location to which the
statement at Y jumps.

LCSAJ coverage
Es. Consider this simple program:
int function math
1. begin
2. int z;
3. if (s) then
4.
z = x + y;
5. else
6.
z= x * y;
7. end if;
8. return z;
9. end math;

(bool s,
int x,y)

Start line
(X)

End line
(Y)

Jump to
(Z)

-1 (exit)

A jump in a LCSAJ triplet can be also the


program exit usually marked with number -1.
A triplet is considered covered when the
execution arrives at the X, follows through
sequentially to statement Y, and then jumps to
statement Z.

LCSAJ coverage
Es.2 - Example of LCSAJ for loops:
int function factorial(int x)
1. begin
2. int y,z;
3. y = x;
4. z = x - 1;
5. while (z > 1) loop
6.
y = y * z;
7.
z--;
8. end loop;
9. return y;
10.end factorial;

Start line
(X)

End line
(Y)

Jump to
(Z)

10

-1

Note that in order to cover all the triplets,


loop must be executed at least three
times!

LCSAJ coverage
Es.2 - Example of LCSAJ for nested and concatenated if:
bool function example(int x)
1. begin
2. bool y;
3. if (g(x)) then
4.
found = TRUE;
5. else
6.
found = FALSE;
7. end if;
8. if (found) then
9.
if (x > 0) then
10.
y = TRUE;
11.
else
12.
y = FALSE;
13.
end if;
14. end if;
15.end example;

Start line End line


(X)
(Y)

Jump to
(Z)

14

12

11

13

14

12

11

13

12

15

-1

13

15

-1

14

15

-1

LCSAJ coverage
LCSAJ coverage gives more information than Decision Coverage
because each branch is evaluated in different ways depending on
the previous branch and not as an individual node.
The advantage of this metric is that avoids the exponential
difficulty of path coverage. The disadvantage is that it does not
avoid unfeasible paths.

You might also like