diff options
author | Mattias Andrée <maandree@kth.se> | 2022-06-12 20:13:23 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2022-06-12 20:13:23 +0200 |
commit | 3d6482b0949159c33d6ac2972a69868bdda766f2 (patch) | |
tree | 722cf9ab069d75af63664eeae0c35c63aa73c51c /strrncaseeqlen.c | |
parent | Fix warnings (diff) | |
download | libsimple-3d6482b0949159c33d6ac2972a69868bdda766f2.tar.gz libsimple-3d6482b0949159c33d6ac2972a69868bdda766f2.tar.bz2 libsimple-3d6482b0949159c33d6ac2972a69868bdda766f2.tar.xz |
Move some test code to newline created .c files
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
-rw-r--r-- | strrncaseeqlen.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/strrncaseeqlen.c b/strrncaseeqlen.c index 5963afc..d904577 100644 --- a/strrncaseeqlen.c +++ b/strrncaseeqlen.c @@ -12,6 +12,32 @@ extern inline size_t libsimple_strrncaseeqlen(const char *, const char *, size_t int main(void) { + size_t i, j, n; + + for (n = 0; n < 10; n++) { + char a[] = "abcdefgh", b[] = "ABCDEFGH"; + size_t I, J; + assert(libsimple_strrncaseeqlen("", "", n) == 0); + assert(libsimple_strrncaseeqlen("x", "", n) == 0); + assert(libsimple_strrncaseeqlen("x", "y", n) == 0); + assert(libsimple_strrncaseeqlen("", "y", n) == 0); + for (i = 0; i <= 8; i++) { + for (j = 0; j <= 8; j++) { + I = 8 - i; + J = 8 - j; + assert(libsimple_strrncaseeqlen(&a[i], &b[j], n) == (I == J ? MIN(I,n) : MIN(I,J) * (n >= MAX(I,J)))); + assert(libsimple_strrncaseeqlen(&b[i], &a[j], n) == (I == J ? MIN(I,n) : MIN(I,J) * (n >= MAX(I,J)))); + a[i] = b[j] = '\0'; + assert(libsimple_strrncaseeqlen(a, b, n) == (MIN(i, n) == MIN(j, n) ? MIN(i, n) : 0)); + assert(libsimple_strrncaseeqlen(b, a, n) == (MIN(i, n) == MIN(j, n) ? MIN(i, n) : 0)); + a[i] = "abcdefgh"[i]; + b[j] = "ABCDEFGH"[j]; + } + } + assert(libsimple_strrncaseeqlen("abc", "abc", n) == MIN(3, n)); + assert(libsimple_strrncaseeqlen("123", "123", n) == MIN(3, n)); + } + return 0; } |