progress on implementation

This commit is contained in:
2025-05-07 19:18:14 +02:00
parent a9cb36e2f6
commit e2eaa512dd
3 changed files with 311 additions and 13 deletions

View File

@ -39,36 +39,180 @@ int test_to_uppercase() {
return 0;
}
int test_trim_right() {
int test_remove_at_pos() {
char* input = "Hello";
char* expected = "Hllo";
char* result = strops_remove_at_pos(input, 1);
if (strcmp(result, expected) != 0) {
printf("test_remove_at_pos failed\n");
printf("Got = '%s'\nExpected = '%s'\n", result, expected);
return 1;
}
return 0;
}
int test_trim_right_whitespace() {
char* input = "String \t\f\v\r\n ";
char* expected = "String";
char* result = strops_trim_right_whitespace(input);
if (strcmp(result, expected) != 0) {
printf("test_trim_right failed\n");
printf("\ntest_trim_right_whitespace failed\n");
printf("Got = '%s'\nExpected = '%s'\n", result, expected);
return 1;
}
return 0;
}
int test_trim_left() {
int test_trim_left_whitespace() {
char* input = " \t\f\v\r\n String";
char* expected = "String";
char* result = strops_trim_left_whitespace(input);
if (strcmp(result, expected) != 0) {
printf("test_trim_left failed\n");
printf("\ntest_trim_left_whitespace failed\n");
printf("Got = '%s'\nExpected = '%s'\n", result, expected);
return 1;
}
return 0;
}
int test_trim_both() {
int test_trim_both_whitespace() {
char* input = " \t\f\v String \r\n ";
char* expected = "String";
char* result = strops_trim_both_whitespace(input);
if (strcmp(result, expected) != 0) {
printf("test_trim_both failed\n");
printf("\ntest_trim_both_whitespace failed\n");
printf("Got = '%s'\nExpected = '%s'\n", result, expected);
return 1;
}
return 0;
}
int test_trim_right_chars() {
char* input = "banana";
char* expected = "b";
char* result = strops_trim_right_chars(input, "na");
if (strcmp(result, expected) != 0) {
printf("test_right_chars failed\n");
printf("Got = '%s'\nExpected = '%s'\n", result, expected);
return 1;
}
return 0;
}
int test_trim_left_chars() {
char* input = "banana";
char* expected = "nana";
char* result = strops_trim_left_chars(input, "ba");
if (strcmp(result, expected) != 0) {
printf("test_left_chars failed\n");
printf("Got = '%s'\nExpected = '%s'\n", result, expected);
return 1;
}
return 0;
}
int test_trim_both_chars() {
char* input = "anna";
char* expected = "nn";
char* result = strops_trim_both_chars(input, "a");
if (strcmp(result, expected) != 0) {
printf("test_trim_both_chars failed\n");
printf("Got = '%s'\nExpected = '%s'\n", result, expected);
return 1;
}
return 0;
}
int test_trim_right_string() {
char* input = "adad_artist";
char* expected = "adad_";
char* result = strops_trim_right_string(input, "artist");
if (strcmp(result, expected) != 0) {
printf("test_trim_right_string failed\n");
printf("Got = '%s'\nExpected = '%s'\n", result, expected);
return 1;
}
return 0;
}
int test_trim_left_string() {
char* input = "adad_artist";
char* expected = "_artist";
char* result = strops_trim_left_string(input, "adad");
if (strcmp(result, expected) != 0) {
printf("test_trim_left_string failed\n");
printf("Got = '%s'\nExpected = '%s'\n", result, expected);
return 1;
}
return 0;
}
int test_trim_both_string() {
char* input = "NULL Bruh NULL";
char* expected = " Bruh ";
char* result = strops_trim_both_string(input, "NULL");
if (strcmp(result, expected) != 0) {
printf("test_trim_both_string failed\n");
printf("Got = '%s'\nExpected = '%s'\n", result, expected);
return 1;
}
return 0;
}
int test_remove_chars() {
char* input = "banana";
char* expected = "bnn";
char* result = strops_remove_chars(input, "a");
if (strcmp(result, expected) != 0) {
printf("test_remove_chars failed\n");
printf("Got = '%s'\nExpected = '%s'\n", result, expected);
return 1;
}
return 0;
}
int test_remove_string() {
char* input = "I hate you";
char* expected = "I you";
char* result = strops_remove_string(input, "hate");
if (strcmp(result, expected) != 0) {
printf("test_remove_string failed\n");
printf("Got = '%s'\nExpected = '%s'\n", result, expected);
return 1;
}
return 0;
}
int test_word_count() {
char* input = "Hello, World!";
size_t expected = 2;
size_t result = strops_word_count(input);
if (result != expected) {
printf("test_word_count failed\n");
printf("Got = %ld\nExpected = %ld\n", result, expected);
return 1;
}
return 0;
}
int test_url_encode() {
char* input = "(artist)";
char* expected = "%28artist%29";
char* result = strops_url_encode(input);
if (strcmp(result, expected) != 0) {
printf("test_url_encode failed\n");
printf("Got = '%s'\nExpected = '%s'\n", result, expected);
return 1;
}
return 0;
}
int test_url_decode() {
char* input = "%28artist%29";
char* expected = "(artist)";
char* result = strops_url_decode(input);
if (strcmp(result, expected) != 0) {
printf("test_url_decode failed\n");
printf("Got = '%s'\nExpected = '%s'\n", result, expected);
return 1;
}
@ -76,7 +220,7 @@ int test_trim_both() {
}
int main() {
int amount_of_tests = 5;
int amount_of_tests = 17;
int amount_of_successful_tests = 0;
int ret;
@ -97,17 +241,77 @@ int main() {
amount_of_successful_tests++;
}
ret = test_trim_right();
ret = test_remove_at_pos();
if (ret == 0) {
amount_of_successful_tests++;
}
ret = test_trim_left();
ret = test_trim_right_whitespace();
if (ret == 0) {
amount_of_successful_tests++;
}
ret = test_trim_both();
ret = test_trim_left_whitespace();
if (ret == 0) {
amount_of_successful_tests++;
}
ret = test_trim_both_whitespace();
if (ret == 0) {
amount_of_successful_tests++;
}
ret = test_trim_right_chars();
if (ret == 0) {
amount_of_successful_tests++;
}
ret = test_trim_left_chars();
if (ret == 0) {
amount_of_successful_tests++;
}
ret = test_trim_both_chars();
if (ret == 0) {
amount_of_successful_tests++;
}
ret = test_trim_right_string();
if (ret == 0) {
amount_of_successful_tests++;
}
ret = test_trim_left_string();
if (ret == 0) {
amount_of_successful_tests++;
}
ret = test_trim_both_string();
if (ret == 0) {
amount_of_successful_tests++;
}
ret = test_remove_chars();
if (ret == 0) {
amount_of_successful_tests++;
}
ret = test_remove_string();
if (ret == 0) {
amount_of_successful_tests++;
}
ret = test_word_count();
if (ret == 0) {
amount_of_successful_tests++;
}
ret = test_url_encode();
if (ret == 0) {
amount_of_successful_tests++;
}
ret = test_url_decode();
if (ret == 0) {
amount_of_successful_tests++;
}