already started, but not done

This commit is contained in:
2025-05-07 18:15:24 +02:00
parent 0c3fdc912b
commit a9cb36e2f6
5 changed files with 251 additions and 0 deletions

122
src/tests.c Normal file
View File

@ -0,0 +1,122 @@
#include "strops.h"
#include <stdio.h>
/* Test template (Maybe make a macro in the future?)
int test_() {
char* input = "";
char* expected = "";
char* result = strops_(input);
if (strcmp(result, expected) != 0) {
printf("test_ failed\n");
printf("Got = '%s'\nExpected = '%s'\n", result, expected);
return 1;
}
return 0;
}
*/
int test_to_lowercase() {
char* input = "sTrInG";
char* expected = "string";
char* result = strops_to_lowercase(input);
if (strcmp(result, expected) != 0) {
printf("test_to_lowercase failed\n");
printf("Got = '%s'\nExpected = '%s'\n", result, expected);
return 1;
}
return 0;
}
int test_to_uppercase() {
char* input = "sTrInG";
char* expected = "STRING";
char* result = strops_to_uppercase(input);
if (strcmp(result, expected) != 0) {
printf("test_to_uppercase failed\n");
printf("Got = '%s'\nExpected = '%s'\n", result, expected);
return 1;
}
return 0;
}
int test_trim_right() {
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("Got = '%s'\nExpected = '%s'\n", result, expected);
return 1;
}
return 0;
}
int test_trim_left() {
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("Got = '%s'\nExpected = '%s'\n", result, expected);
return 1;
}
return 0;
}
int test_trim_both() {
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("Got = '%s'\nExpected = '%s'\n", result, expected);
return 1;
}
return 0;
}
int main() {
int amount_of_tests = 5;
int amount_of_successful_tests = 0;
int ret;
/* Test template
ret = test_();
if (ret == 0) {
amount_of_successful_tests++;
}
*/
ret = test_to_lowercase();
if (ret == 0) {
amount_of_successful_tests++;
}
ret = test_to_uppercase();
if (ret == 0) {
amount_of_successful_tests++;
}
ret = test_trim_right();
if (ret == 0) {
amount_of_successful_tests++;
}
ret = test_trim_left();
if (ret == 0) {
amount_of_successful_tests++;
}
ret = test_trim_both();
if (ret == 0) {
amount_of_successful_tests++;
}
if (amount_of_successful_tests != amount_of_tests) {
printf("%d/%d tests passed successfully\n", amount_of_successful_tests, amount_of_tests);
return 1;
} else {
printf("All tests passed successfully\n");
return 0;
}
}