Skip to content

No regression tests for array as function parameter [C standard test] #327

Open
@belous-dp

Description

@belous-dp

Description
Regression tests weren't generated at all for lots of cases that contains array as a function parameter:

  1. array of fixed known size more than 10
  2. dynamic array (passed by pointer) of size more than 10
  3. 2d array of fixed known size more than 10
  4. dynamic array of fixed arrays of size more than 10
  5. dynamic array of dynamic arrays of size more than 10
    At the same time, some error tests were generated and most of them are passed without errors.

Source code

int sum_sign_1d_big(int a[12]) {
    int sum = 0;
    for (int i = 0; i < 12; i++) {
        sum += a[i];
        if (i % 2 == 0) {
            sum++;
        } else {
            sum--;
        }
    }
    if (sum == 0) {
        return 0;
    } else if (sum > 0) {
        return 1;
    } else {
        return -1;
    }
}

int sum_sign_1d_big_p(int *a) {
    int sum = 0;
    for (int i = 0; i < 12; i++) {
        sum += a[i];
        if (i % 2 == 0) {
            sum++;
        } else {
            sum--;
        }
    }
    if (sum == 0) {
        return 0;
    } else if (sum > 0) {
        return 1;
    } else {
        return -1;
    }
}

int sum_sign_9_11(int a[9][11]) {
    int sum = 0;
    for (int i = 0; i < 9; i++) {
        for (int j = 0; j < 11; j++) {
            sum += a[i][j];
        }
    }
    if (sum == 0) {
        return 0;
    } else if (sum > 0) {
        return 1;
    } else {
        return -1;
    }
}

int sum_sign_9_11_pp(int **a) {
    int sum = 0;
    for (int i = 0; i < 9; i++) {
        for (int j = 0; j < 11; j++) {
            sum += a[i][j];
        }
    }
    if (sum == 0) {
        return 0;
    } else if (sum > 0) {
        return 1;
    } else {
        return -1;
    }
}

int sum_sign_9_11_p(int (*a)[11]) {
    int sum = 0;
    for (int i = 0; i < 9; i++) {
        for (int j = 0; j < 11; j++) {
            sum += a[i][j];
        }
    }
    if (sum == 0) {
        return 0;
    } else if (sum > 0) {
        return 1;
    } else {
        return -1;
    }
}

Generated tests

TEST(error, sum_sign_1d_big_test_1) // weird but it PASSED
{
    int a[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
    sum_sign_1d_big(a);
}

TEST(error, sum_sign_1d_big_p_test_1) // weird but it PASSED
{
    int a[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
    sum_sign_1d_big_p(a);
}

TEST(error, sum_sign_9_11_test_1) // weird but it PASSED
{
    int a[2][11] = {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}};
    sum_sign_9_11(a);
}

TEST(error, sum_sign_9_11_pp_test_1) // actually ERROR, test is ok
{
    int _a[2][2] = {{0, 0}, {0, 0}};
    int ** a = (int **) calloc(3, sizeof(int *));
    for (int it_66_0 = 0; it_66_0 < 2; it_66_0 ++) {
        a[it_66_0] = _a[it_66_0];
    }
    a[2] = NULL;
    sum_sign_9_11_pp(a);
}

TEST(error, sum_sign_9_11_p_test_1) // weird but it PASSED
{
    int a[2][11] = {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}};
    sum_sign_9_11_p(a);
}

Environment
UTBotCpp version 2022.7.0.

Metadata

Metadata

Assignees

No one assigned

    Labels

    c-syntaxRelated to generation tests for Cwrong generationInadequate or empty test suite generated

    Type

    No type

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions