Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Comparing char with string literal #661

Closed
ladisgin opened this issue Dec 11, 2023 · 0 comments · Fixed by #663
Closed

Comparing char with string literal #661

ladisgin opened this issue Dec 11, 2023 · 0 comments · Fixed by #663
Assignees
Labels
bug Something isn't working

Comments

@ladisgin
Copy link
Member

Generated tests for function can't be compiled

char* reverse_str(char* str) {
    int n = strlen(str);
    char* reversed = malloc(n + 1);
    for (int i = 0; i < n; i++) {
        reversed[i] = str[n - 1 - i];
    }
    reversed[n] = '\0';
    return reversed;
}

Tests

TEST(regression, reverse_str_test1)
{
    char str[] = {'c', '\0', 'c', 'c', 'c', 'c', 'c', 'c', 'c', '\0'};
    char * actual = reverse_str(str);
    char expected[] = "c";
    for (int it_10_0 = 0; it_10_0 < 1; it_10_0 ++) {
        EXPECT_EQ(actual[it_10_0], "c");
    }
    char expected_str[] = {'c', '\0', 'c', 'c', 'c', 'c', 'c', 'c', 'c', '\0'};
    for (int it_11_0 = 0; it_11_0 < 10; it_11_0 ++) {
        EXPECT_EQ(expected_str[it_11_0], str[it_11_0]);
    }
}

In line EXPECT_EQ(actual[it_10_0], "c"); comparing char with string literal

@ladisgin ladisgin added the bug Something isn't working label Dec 11, 2023
@ladisgin ladisgin self-assigned this Dec 11, 2023
@ladisgin ladisgin linked a pull request Dec 14, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

1 participant