commit d2d1660217ff0a583f1d5736be450ac97a8d8035
parent d6d570e027558233db7d49102557ad4865845e76
Author: Roberto E. Vargas Caballero <k0ga@shike2.net>
Date: Wed, 6 May 2026 13:13:46 +0200
tests/libc: Add 0096-div
Diffstat:
3 files changed, 112 insertions(+), 0 deletions(-)
diff --git a/tests/libc/execute/.gitignore b/tests/libc/execute/.gitignore
@@ -94,3 +94,4 @@ test.log
0093-system
0094-bsearch
0095-abs
+0096-div
diff --git a/tests/libc/execute/0096-div.c b/tests/libc/execute/0096-div.c
@@ -0,0 +1,110 @@
+#include <assert.h>
+#include <inttypes.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+/*
+output:
+testing
+done
+end:
+*/
+
+/*
+div_t div(int, int);
+ldiv_t ldiv(long int, long int);
+lldiv_t lldiv(long long int, long long int);
+imaxdiv_t imaxdiv(intmax_t, intmax_t);
+*/
+static void
+test1(void)
+{
+ div_t d;
+
+ puts("test1");
+
+ d = div(8, 4);
+ assert(d.quot == 2 && d.rem == 0);
+
+ d = div(-10, 3);
+ assert(d.quot == -3 && d.rem == -1);
+
+ d = div(10, -3);
+ assert(d.quot == -3 && d.rem == 1);
+
+ d = div(-11, -3);
+ assert(d.quot == 3 && d.rem == -2);
+}
+
+static void
+test2(void)
+{
+ ldiv_t ld;
+
+ puts("test2");
+
+ ld = ldiv(8, 4);
+ assert(ld.quot == 2 && ld.rem == 0);
+
+
+ ld = ldiv(-10, 3);
+ assert(ld.quot == -3 && ld.rem == -1);
+
+ ld = ldiv(10, -3);
+ assert(ld.quot == -3 && ld.rem == 1);
+
+ ld = ldiv(-11, -3);
+ assert(ld.quot == 3 && ld.rem == -2);
+}
+
+static void
+test3(void)
+{
+ lldiv_t lld;
+
+ puts("test3");
+
+ lld = lldiv(8, 4);
+ assert(lld.quot == 2 && lld.rem == 0);
+
+
+ lld = lldiv(-10, 3);
+ assert(lld.quot == -3 && lld.rem == -1);
+
+ lld = lldiv(10, -3);
+ assert(lld.quot == -3 && lld.rem == 1);
+
+ lld = lldiv(-11, -3);
+ assert(lld.quot == 3 && lld.rem == -2);
+}
+
+static void
+test4(void)
+{
+ imaxdiv_t md;
+
+ puts("test4");
+
+ md = imaxdiv(8, 4);
+ assert(md.quot == 2 && md.rem == 0);
+
+ md = imaxdiv(-10, 3);
+ assert(md.quot == -3 && md.rem == -1);
+
+ md = imaxdiv(10, -3);
+ assert(md.quot == -3 && md.rem == 1);
+
+ md = imaxdiv(-11, -3);
+ assert(md.quot == 3 && md.rem == -2);
+}
+
+int
+main(void)
+{
+ puts("testing");
+ test1();
+ test2();
+ test3();
+ test4();
+ puts("end");
+}
diff --git a/tests/libc/execute/libc-tests.lst b/tests/libc/execute/libc-tests.lst
@@ -92,3 +92,4 @@
0093-system
0094-bsearch
0095-abs
+0096-div