diff --git a/str/str_chr.c b/str/str_chr.c index 37d24fe..418dd57 100644 --- a/str/str_chr.c +++ b/str/str_chr.c @@ -15,3 +15,17 @@ size_t str_chr(const char *in, char needle) { } return (size_t)(t-in); } + +#ifdef UNITTEST +#include +#include + +int main() { + char buf[100]; + strcpy(buf,"abcdefghijklmnopqrstuvwxyz"); + size_t i; + for (i=0; i<26; ++i) + assert(str_chr(buf,buf[i])==i); + assert(str_chr(buf,'X')==26); +} +#endif diff --git a/str/str_diff.c b/str/str_diff.c index 57ff0b3..3d28b01 100644 --- a/str/str_diff.c +++ b/str/str_diff.c @@ -21,3 +21,15 @@ int str_diff(const char* a, const char* b) { } return j; } + +#ifdef UNITTEST +#include +#include + +int main() { + assert(str_diff("foo","foo")==0); + assert(str_diff("foo","fob")==('o'-'b')); + assert(str_diff("foo","foox")==(-'x')); + assert(str_diff("foox","foo")=='x'); +} +#endif