already started, but not done
This commit is contained in:
122
src/tests.c
Normal file
122
src/tests.c
Normal 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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user