37 lines
1.2 KiB
C
37 lines
1.2 KiB
C
#include "c_Test.h"
|
|||
|
|
#include "c_LongestCommonSubstring.h"
|
||
|
|
|
||
|
|
TEST_CASE(test_longest_common_substring_resolution) {
|
||
|
|
/* Test inputs:
|
||
|
|
* Str A: "AABCCBDE"
|
||
|
|
* Str B: "XABCYBDE"
|
||
|
|
* Longest common continuous substring token should be "BDE" (Len: 3) or "ABC" (Len: 3).
|
||
|
|
* Our engine catches the first optimal one maximized or tracked sequentially.
|
||
|
|
*/
|
||
|
|
const char* a = "AABCCBDE";
|
||
|
|
const char* b = "XABCYBDE";
|
||
|
|
|
||
|
|
c_LongestCommonSubstring_t lcs;
|
||
|
|
c_err_t err = c_LongestCommonSubstring_Init(&lcs, a, b, NULL);
|
||
|
|
ASSERT_INT_EQ(C_SUCCESS, err);
|
||
|
|
|
||
|
|
c_size_t resolved_len = c_LongestCommonSubstring_GetLen(&lcs);
|
||
|
|
ASSERT_LL_EQ(3, resolved_len);
|
||
|
|
|
||
|
|
char res_buf[16];
|
||
|
|
err = c_LongestCommonSubstring_GetSubstring(&lcs, a, res_buf, sizeof(res_buf));
|
||
|
|
ASSERT_INT_EQ(C_SUCCESS, err);
|
||
|
|
|
||
|
|
/* Assert exact string equality token content matches */
|
||
|
|
ASSERT_INT_EQ(0, strcmp("ABC", res_buf) == 0 || strcmp("BDE", res_buf) == 0 ? 0 : -1);
|
||
|
|
|
||
|
|
c_LongestCommonSubstring_Destroy(&lcs);
|
||
|
|
}
|
||
|
|
|
||
|
|
int main(void) {
|
||
|
|
TEST_START(LongestCommonSubstring_Verification_Suite);
|
||
|
|
RUN_TEST(test_longest_common_substring_resolution);
|
||
|
|
TEST_REPORT();
|
||
|
|
RETURN_TEST_STATUS;
|
||
|
|
}
|