Skip to main content

Test cases

Task 1

 section [krok4] of the 9.2.2 without table 9.4

Defining test cases. We must provide such input data that all branches are covered. Lets consider the input case T  = [5, 3]. For this array, the program will follow the patch p = B1 - B2 - B4 - B5 - B6 - B8 - B7 - B9 - B3 - B2 - end (both the outer while loop and for loop execute only once). Executing path p will cause the coverage EP1, EP2, EP3, EP4, EP5, without remain coverage uncovered. We contructed test case covering 100% of branches. Generally, the longer test path, the harder it is to choose input values to force the program exactly along this path. Therefore, sometimes one may give up on obtaining the smallest possible test set in favor of creating a slighty larger one that is easier to enforce specific control paths.

 Task 2 

Table 9.4 and source code of the test program

Id Input Expected output

Covered elements

PT1

T = [4, 3]

T = [3, 4]

EP1, EP2, EP3, EP4, EP6, EP7, EP8, EP10

PT2

T = [3, 4, 5]

T = [3, 4, 5]

EP1, EP2, EP3, EP5, EP7, EP8, EP9, EP10

#include <stdbool.h>

void bubbleSort(int T[], int n) {
    bool swapped;
    int i, temp;

    do {
        swapped = false;
        for (i = 0; i < n - 1; i++) {
            if (T[i] > T[i + 1]) {
                temp = T[i];
                T[i] = T[i + 1];
                T[i + 1] = temp;
                swapped = true;
            }
        }
    } while (swapped);
}

int main() {
    int T1[] = {4, 3};
    int T2[] = {3, 4, 5};
    bubbleSort(T1, 2);
    bubbleSort(T2, 3);
    return 0;
}