add unit test

master
leitner 6 years ago
parent 8714ae112d
commit 533195b16f

@ -15,3 +15,17 @@ size_t str_chr(const char *in, char needle) {
} }
return (size_t)(t-in); return (size_t)(t-in);
} }
#ifdef UNITTEST
#include <assert.h>
#include <string.h>
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

@ -21,3 +21,15 @@ int str_diff(const char* a, const char* b) {
} }
return j; return j;
} }
#ifdef UNITTEST
#include <assert.h>
#include <string.h>
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

Loading…
Cancel
Save