Branch testing with Chat GPT
You can use any other Chat Bot. If you do so, change the page title.
Task 1 (student 1)
Using a Chat Bot identify branches for the insertSort function. Assign a tag to for each identified branch. Present the list of statements with tags. Write the prompt and the chatbot answer. Discuss the result - compare it with the previous page of the book.
Prompt
Branch testing.
Identify branches for the insertSort function.
Assign a tag for each identified branch.
Present the list of statements with tags.
void insertSort(int a[], int length)
{
int i, j, value;
for (i = 1; i < length; ++i)s
{
value = a[i];
for (j = i - 1; j >= 0 && a[j] > value; --j)
{
a[j + 1] = a[j];
}
a[j + 1] = value;
}
}
Response
Here’s the insertSort function with explanations and branch tags added:
void insertSort(int a[], int length)
{
int i, j, value;
for (i = 1; i < length; ++i) // [B1]
{
value = a[i];
for (j = i - 1; j >= 0 && a[j] > value; --j) // [B2a], [B2b]
{
a[j + 1] = a[j];
}
a[j + 1] = value;
}
}
Identified Branches and Tags
Tag | Branch Condition | Description |
---|---|---|
B1 | i < length |
Outer for loop condition |
B2a | j >= 0 |
First part of the inner for loop condition |
B2b | a[j] > value |
Second part of the inner for loop condition |
Task 2 (student 2)
Using a Chat Bot generate the Control Flow Graph in the DOT language for the insertSort function. Label the edges of the CFG. Discuss the result - compare the CFG with the graph created by a human.
Task 3. (student 3)
Convince a Chat Bot to write a branch test for the function insertSort in the C language. Write the prompt and the chatbot answer. Discuss the result, compare it with the code written by a human in the previous section of the book.