Skip to main content

Example - insert sort

Let's reconsider the BubbleSort function from the previous chapter and create test cases for it that satisfy the branch coverage criterion.

Step 1. Define the subject and test elements. The test element is the BubbleSort function.

ET1: BubbleSort.

Step 2 and 3. Derivation of test conditions and coverage elements.

The test conditions and at the same time the coverage elements are the edges of the control flow graph.

WT1=EP1: (B1, B2); WT5=EP5: (B5, B4); WT9=EP9: (B7, B2);
WT2=EP2: (B2, B3); WT6=EP6: (B6, B4); WT10=EP10: (B7, B8).
WT3=EP3: (B3, B5); WT7=EP7: (B4, B3);
WT4-EP4: (B5, B6); WT8=EP8: (B3, B7);

These elements are shown graphically in Figure 9.2.

Task 2

Control Flow Graph for the  with labeled graph edges.

insertSort-diagram.png

Code in DOT language  in program GraphViz:

digraph G {
start -> b1;
b1 -> b2 [label="EP1"]

b2 -> end[label="EP5"]
b2 -> b4
b4 -> b5[label="EP2"]

b5 -> b6
b6 -> b8
b8 -> b7[label="EP3"]
b6 ->b9
b7 -> b6
b9->b3 [label="EP4"]
b3->b2

start [shape=Mdiamond];
end [shape=Msquare];
}