Test cases
Defining Test Cases.
There are three independent exit points from the module (at B2, B5, and B11), so at least three test cases are needed.
When configuring the test environment, we should specify a concrete form of the function f(x), since its values affect the control flow at B4, B6, and B8.
Let us assume f(x) = x
Test Cases for Decision Coverage
Id | Input | Expected Output | Covered EP |
---|---|---|---|
PT1 | (l = 4, r = 5) | Invalid input interval | EP1 |
PT2 | (l = –1, r = 1) | Exact root = 0 | EP2, EP3, EP5 |
PT3 | (l = –0.000125, r = 0.00025) | The root is in the interval (–0.00003125, 0.0000625) | EP2, EP3, EP4, EP6, EP7, EP8, EP9 |
Case PT3 forces the following sequence of events:
B1 – false, covers EP2;
B3 – true (r – l = 0.000375 > 0.0001, m := 0.0000625), covers EP3;
B4 – false, covers EP6;
B6 – false (because f(l) · f(m) = l · m < 0), covers EP8;
B8 – true, r := 0.0000625, covers EP9;
B3 – true (l = –0.000125, r = 0.0000625, r – l = 0.0001875, m := –0.00003125);
B4 – false;
B6 – true (because f(l) · f(m) = l · m > 0), l := –0.00003125, covers EP7;
B3 – false (because r – l = 0.0000625 – (–0.00003125) = 0.00009375 < 0.0001), covers EP4.
As we observed earlier, coverage of EP10 is unreachable. We have therefore achieved 9/10 = 90% decision coverage. Let's check how much branch coverage is obtained from the same set of tests. In the control flow graph, there are 13 edges. The only uncovered edge (due to the unreachability of EP10) is the edge (B8, B10). Therefore, the branch coverage rate is 12/13 ≈ 92% – slightly higher than the decision coverage rate.
Task 2
Source code of the test program:
include <stdio.h>
void insertSort(int a[], int length) {
int i, j, value;
for (i = 1; i < length; ++i) {
value = a[i];
for (j = i - 1; j >= 0 && a[j] > value; --j) {
a[j + 1] = a[j];
}
a[j + 1] = value;
}
}
int main() {
int a[9]={5,3, 1, 2,7,9,4,6,8};
int i;
for(i=0; i< 9; i++){
printf("%d", a[i]);
}
printf("\n");
insertSort(a,9);
for(i=0; i< 9; i++){
printf("%d", a[i]);
}
return 0;
}
No Comments