From: solar Date: Thu, 15 Dec 2005 12:29:11 +0000 (+0000) Subject: Added test drivers. X-Git-Tag: v0.4~41 X-Git-Url: https://pd.if.org/git/?p=pdclib;a=commitdiff_plain;h=3c50a3f497bc07f023be71045f5792e0d82c951f Added test drivers. --- diff --git a/functions/stdlib/div.c b/functions/stdlib/div.c index 45961af..bf82bed 100644 --- a/functions/stdlib/div.c +++ b/functions/stdlib/div.c @@ -26,11 +26,22 @@ div_t div( int numer, int denom ) #ifdef TEST #include <_PDCLIB_test.h> +#ifndef _PDCLIB_CONFIG_H +#include <_PDCLIB_config.h> +#endif + int main() { - int NO_TESTDRIVER = 0; + div_t idiv; BEGIN_TESTS; - TESTCASE( NO_TESTDRIVER ); + idiv = div( 5, 2 ); + TESTCASE( idiv.quot == 2 && idiv.rem == 1 ); + idiv = div( -5, 2 ); + TESTCASE( idiv.quot == -2 && idiv.rem == -1 ); + idiv = div( 5, -2 ); + TESTCASE( idiv.quot == -2 && idiv.rem == 1 ); + TESTCASE( sizeof( idiv.quot ) == _PDCLIB_INT_BYTES ); + TESTCASE( sizeof( idiv.rem ) == _PDCLIB_INT_BYTES ); return TEST_RESULTS; } diff --git a/functions/stdlib/ldiv.c b/functions/stdlib/ldiv.c index 92a56b9..11940de 100644 --- a/functions/stdlib/ldiv.c +++ b/functions/stdlib/ldiv.c @@ -2,7 +2,7 @@ /* Release $Name$ */ -/* ldiv( int, int ) +/* ldiv( long int, long int ) This file is part of the Public Domain C Library (PDCLib). Permission is granted to use, modify, and / or redistribute at will. @@ -17,7 +17,7 @@ ldiv_t ldiv( long int numer, long int denom ) ldiv_t rc; rc.quot = numer / denom; rc.rem = numer % denom; - /* TODO: pre-C99 compilers might require modulus correction */ + /* TODO: pre-C99 compilers might require modulus corrections */ return rc; } @@ -26,11 +26,22 @@ ldiv_t ldiv( long int numer, long int denom ) #ifdef TEST #include <_PDCLIB_test.h> +#ifndef _PDCLIB_CONFIG_H +#include <_PDCLIB_config.h> +#endif + int main() { - int NO_TESTDRIVER = 0; + ldiv_t div; BEGIN_TESTS; - TESTCASE( NO_TESTDRIVER ); + div = ldiv( 5, 2 ); + TESTCASE( div.quot == 2 && div.rem == 1 ); + div = ldiv( -5, 2 ); + TESTCASE( div.quot == -2 && div.rem == -1 ); + div = ldiv( 5, -2 ); + TESTCASE( div.quot == -2 && div.rem == 1 ); + TESTCASE( sizeof( div.quot ) == _PDCLIB_LONG_BYTES ); + TESTCASE( sizeof( div.rem ) == _PDCLIB_LONG_BYTES ); return TEST_RESULTS; } diff --git a/functions/stdlib/lldiv.c b/functions/stdlib/lldiv.c index 349ff2b..358b288 100644 --- a/functions/stdlib/lldiv.c +++ b/functions/stdlib/lldiv.c @@ -17,7 +17,7 @@ lldiv_t lldiv( long long int numer, long long int denom ) lldiv_t rc; rc.quot = numer / denom; rc.rem = numer % denom; - /* TODO */ + /* TODO: pre-C99 compilers might require modulus corrections */ return rc; } @@ -26,11 +26,22 @@ lldiv_t lldiv( long long int numer, long long int denom ) #ifdef TEST #include <_PDCLIB_test.h> +#ifndef _PDCLIB_CONFIG_H +#include <_PDCLIB_config.h> +#endif + int main() { - int NO_TESTDRIVER = 0; + lldiv_t div; BEGIN_TESTS; - TESTCASE( NO_TESTDRIVER ); + div = lldiv( 5, 2 ); + TESTCASE( div.quot == 2 && div.rem == 1 ); + div = lldiv( -5, 2 ); + TESTCASE( div.quot == -2 && div.rem == -1 ); + div = lldiv( 5, -2 ); + TESTCASE( div.quot == -2 && div.rem == 1 ); + TESTCASE( sizeof( div.quot ) == _PDCLIB_LLONG_BYTES ); + TESTCASE( sizeof( div.rem ) == _PDCLIB_LLONG_BYTES ); return TEST_RESULTS; }