Skip to main content

Decision 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 statements for the RegulaFalsi function. Assign a tag to for each identified statement.  Present the list of statements with tags. Write the prompt and the chatbot answer. Discuss the result. 

 Does it properly recognized that the FOR instruction consists of 3 statements?  Did it handle properly nested IFs?

     

  Task 2 (student 2)  

  Using a Chat Bot generate the Control Flow Graph in the DOT language for the RegulaFalsi function. Write the prompt and the chatbot answer. Discuss the result.  

 Does the CFG has the same structure as the CFG created by a human in the previous section of the book? 

  Task 3. (student 3)  

Convince a Chat Bot to write a decision test for the function RegulaFalsi in the C language (I think you need to explain to the chatbot what a decision test is). 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.

"write a DECISION TEST for the function RegulaFalsi in the C language"

#include <stdio.h>
#include <math.h>

#define EPSILON 0.0001

double f(double x) {
    return x * x * x - x - 2;  // Example function
}

double RegulaFalsi(double a, double b) {
    if (f(a) * f(b) >= 0) {
        printf("Invalid interval.\n");
        return -1;
    }

    double c = a;
    while ((b - a) >= EPSILON) {
        // Find the point that touches x axis
        c = (a * f(b) - b * f(a)) / (f(b) - f(a));

        // Check if the above point is root
        if (fabs(f(c)) < EPSILON)
            break;

        // Decide the side to repeat the steps
        if (f(c) * f(a) < 0)
            b = c;
        else
            a = c;
    }
    return c;
}

void test_invalid_interval() {
    double root = RegulaFalsi(1, 1);  // f(1)*f(1) >= 0
    assert(root == -1);               // Should return -1 for invalid interval
    printf("Test invalid interval passed.\n");
}

void test_valid_root_interval() {
    double root = RegulaFalsi(1, 2);  // f(1) = -2, f(2) = 4, sign change
    assert(fabs(f(root)) < EPSILON); // Root should be valid
    printf("Test valid root interval passed.\n");
}

void test_early_termination() {
    // Modify function or input to force f(c) < EPSILON quickly
    double root = RegulaFalsi(1.5, 2); // Should converge quickly
    assert(fabs(f(root)) < EPSILON);
    printf("Test early termination passed.\n");
}

void test_update_a_or_b() {
    double a = 1, b = 2;
    double root = RegulaFalsi(a, b);  // We expect updates to both a and b at some point
    assert(fabs(f(root)) < EPSILON);
    printf("Test update a/b logic passed.\n");
}

int main() {
    test_invalid_interval();    // Covers decision 1 (true)
    test_valid_root_interval(); // Covers decisions 1 (false), 2 (true), 3 (false), 4 (true/false)
    test_early_termination();   // Covers decision 3 (true)
    test_update_a_or_b();       // Covers decision 4 (both branches)

    printf("All decision tests passed.\n");
    return 0;
}