Sha256: 9d1dd36201afe97c7cbb82021865e61865e9b9a842f575e18b1aa9602406eeaa

Contents?: true

Size: 1.35 KB

Versions: 3

Compression:

Stored size: 1.35 KB

Contents

#include "../foundationallib.h"
#include <assert.h>
#include <string.h>

// Define this if the function is part of a library

// Function to test
FOUNDATIONAL_LIB_FUNC char *longest_common_suffix(const char **strings, size_t count);

// Test cases
void testSingleString()
{
    const char *input[] = {"hello"};
    char *result = longest_common_suffix(input, 1);
    assert(strcmp(result, "hello") == 0);
    free(result);
}

void testEmptyStrings()
{
    const char *input[] = {"", "", ""};
    char *result = longest_common_suffix(input, 3);
    assert(strcmp(result, "") == 0);
    free(result);
}

void testNoCommonSuffix()
{
    const char *input[] = {"hello", "world", "foo"};
    char *result = longest_common_suffix(input, 3);
    assert(strcmp(result, "") == 0);
    free(result);
}

void testCommonSuffix()
{
    const char *input[] = {"testing", "ing", "string"};
    char *result = longest_common_suffix(input, 3);
    assert(strcmp(result, "ing") == 0);
    free(result);
}

void testLongestCommonSuffix()
{
    const char *input[] = {"apple", "people", "staple"};
    char *result = longest_common_suffix(input, 3);
    assert(strcmp(result, "ple") == 0);
    free(result);
}

int main()
{
    testSingleString();
    testEmptyStrings();
    testNoCommonSuffix();
    testCommonSuffix();
    testLongestCommonSuffix();

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

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
foundational_lib-1.0.1 ./tests/more/experimental/third_test_suite/non_production_ready_test_suite/test_every_relevant_function_in_a_separate_thorough_program/work_in_progress_code/src/test_longest_common_suffix.c
foundational_lib2-1.0 ./tests/more/experimental/third_test_suite/non_production_ready_test_suite/test_every_relevant_function_in_a_separate_thorough_program/work_in_progress_code/src/test_longest_common_suffix.c
foundational_lib-1.0 ./tests/more/experimental/third_test_suite/non_production_ready_test_suite/test_every_relevant_function_in_a_separate_thorough_program/work_in_progress_code/src/test_longest_common_suffix.c