This repository has been archived on 2021-10-31. You can view files and clone it, but cannot push or open issues or pull requests.
sys_prog/sortstrings/tests/test2.c

38 lines
906 B
C
Raw Normal View History

2019-10-09 08:18:40 +00:00
#include <assert.h>
#include <string.h>
extern void sort_strings(const char * input, char * output, unsigned int n);
int main() {
char buf[1000];
sort_strings("ciao\0ciao", buf, 2);
assert(memcmp(buf, "ciao\0ciao", 10) == 0);
sort_strings("a\0b", buf, 2);
assert(memcmp(buf, "a\0b", 4) == 0);
sort_strings("a\0b\0c", buf, 3);
assert(memcmp(buf, "a\0b\0c", 6) == 0);
sort_strings("b\0c\0a", buf, 3);
assert(memcmp(buf, "a\0b\0c", 6) == 0);
sort_strings("c\0a\0b", buf, 3);
assert(memcmp(buf, "a\0b\0c", 6) == 0);
sort_strings("c\0a\0b", buf, 1);
assert(memcmp(buf, "c", 2) == 0);
sort_strings("c\0a\0b", buf, 2);
assert(memcmp(buf, "a\0c", 2) == 0);
sort_strings("a\0a", buf, 2);
assert(memcmp(buf, "a\0a", 4) == 0);
sort_strings("b\0a\0a\0a\0b", buf, 5);
assert(memcmp(buf, "a\0a\0a\0b\0b", 10) == 0);
return 0;
}