[svn commit] r425 - in trunk: . gc/tests
jimb at red-bean.com
jimb at red-bean.com
Sat Mar 26 08:47:49 CST 2005
Author: jimb
Date: Sat Mar 26 08:47:48 2005
New Revision: 425
Modified:
trunk/TODO
trunk/gc/tests/c-api-numbers.c
Log:
Write tests for unsigned number functions, and new mn_TYPE_is_number
functions. Check them off the TODO list.
Modified: trunk/TODO
==============================================================================
--- trunk/TODO (original)
+++ trunk/TODO Sat Mar 26 08:47:48 2005
@@ -9,8 +9,6 @@
* fix build warnings for numbers.c
-* still need tests for unsigned C API functions
-
* Need tests for strings with embedded null characters.
* Need test for mn_string_to_symbol.
@@ -68,7 +66,8 @@
- 'utf8', 'uni' for Unicode utf8 strings and code points, uni_cat for
general categories, uni_cat_set for category sets
-- TYPE_to_TYPE for all conversion functions
+- TYPE_to_TYPE for all conversion functions, TYPE_is_TYPE for functions
+ that test whether the conversion would abort
- QUALITY_p for all predicates, or is_QUALITY for all predicates
Modified: trunk/gc/tests/c-api-numbers.c
==============================================================================
--- trunk/gc/tests/c-api-numbers.c (original)
+++ trunk/gc/tests/c-api-numbers.c Sat Mar 26 08:47:48 2005
@@ -1,6 +1,7 @@
/* c-api-numbers.c --- tests for <minor/minor.h> number functions. */
#include <limits.h>
+#include <stdint.h>
#include <minor/minor.h>
#include <minor/fixnums.h>
@@ -17,14 +18,21 @@
preserve the argument's value. */
int n = n_max;
- test_group_begin ("0x%x", n);
+ test_group_begin ("%d (0x%x)", n, (unsigned int) n);
{
test ("test_int passed a valid 'int' value (meta-test)");
pass_if (n == n_max);
- /* Are we supposed to be able to represent this value as a fixnum?
- (When we support bignums, this test can go away. */
- if (! (MN_FIXNUM_MIN <= n && n <= MN_FIXNUM_MAX))
+ /* Some values we really ought to be able to represent.
+ mn_int_is_number shouldn't return false for everything. */
+ if (-255 <= n && n <= 255)
+ {
+ test ("mn_int_is_number admits value");
+ pass_if (mn_int_is_number (c, n));
+ }
+
+ /* Are we able to represent this value at all? */
+ else if (! mn_int_is_number (c, n))
{
test_group_end ();
return;
@@ -63,14 +71,21 @@
preserve the argument's value. */
long n = n_max;
- test_group_begin ("0x%lx", n);
+ test_group_begin ("%ld (0x%lx)", n, (unsigned long) n);
{
test ("test_long passed a valid 'long' value (meta-test)");
pass_if (n == n_max);
- /* Are we supposed to be able to represent this value as a fixnum?
- (When we support bignums, this test can go away. */
- if (! (MN_FIXNUM_MIN <= n && n <= MN_FIXNUM_MAX))
+ /* Some values we really ought to be able to represent.
+ mn_long_is_number shouldn't return false for everything. */
+ if (-255 <= n && n <= 255)
+ {
+ test ("mn_long_is_number admits value");
+ pass_if (mn_long_is_number (c, n));
+ }
+
+ /* Are we able to represent this value at all? */
+ else if (! mn_long_is_number (c, n))
{
test_group_end ();
return;
@@ -109,14 +124,21 @@
preserve the argument's value. */
long long n = n_max;
- test_group_begin ("0x%llx", n);
+ test_group_begin ("%lld (0x%llx)", n, (unsigned long long) n);
{
test ("test_llong passed a valid 'long long' value (meta-test)");
pass_if (n == n_max);
- /* Are we supposed to be able to represent this value as a fixnum?
- (When we support bignums, this test can go away. */
- if (! (MN_FIXNUM_MIN <= n && n <= MN_FIXNUM_MAX))
+ /* Some values we really ought to be able to represent.
+ mn_llong_is_number shouldn't return false for everything. */
+ if (-255 <= n && n <= 255)
+ {
+ test ("mn_llong_is_number admits value");
+ pass_if (mn_llong_is_number (c, n));
+ }
+
+ /* Are we able to represent this value at all? */
+ else if (! mn_llong_is_number (c, n))
{
test_group_end ();
return;
@@ -148,6 +170,165 @@
}
+static void
+test_uint (mn_call *c, uintmax_t n_max)
+{
+ /* The arguments to unsigned_iterator ensured this assignment will
+ preserve the argument's value. */
+ unsigned int n = n_max;
+
+ test_group_begin ("0x%x", n);
+ {
+ test ("test_uint passed a valid 'unsigned int' value (meta-test)");
+ pass_if (n == n_max);
+
+ /* Some values we really ought to be able to represent.
+ mn_uint_is_number shouldn't return false for everything. */
+ if (n <= 255)
+ {
+ test ("mn_uint_is_number admits value");
+ pass_if (mn_uint_is_number (c, n));
+ }
+
+ /* Are we able to represent this value at all? */
+ else if (! mn_uint_is_number (c, n))
+ {
+ test_group_end ();
+ return;
+ }
+
+ mn_ref *r = mn_from_uint (c, n);
+
+ test ("mn_to_uint preserves value");
+ pass_if (mn_to_uint (c, r) == n);
+
+ test ("mn_number_p returns true");
+ pass_if (mn_number_p (c, r));
+
+ test ("mn_exact_p returns true");
+ pass_if (mn_exact_p (c, r));
+
+ test ("mn_integer_p returns true");
+ pass_if (mn_integer_p (c, r));
+
+ test ("mn_exact_integer_p returns true");
+ pass_if (mn_exact_integer_p (c, r));
+
+ test ("mn_number_is_uint returns true");
+ pass_if (mn_number_is_uint (c, r));
+
+ mn_free_local_ref (c, r);
+ }
+ test_group_end ();
+}
+
+
+static void
+test_ulong (mn_call *c, uintmax_t n_max)
+{
+ /* The arguments to unsigned_iterator ensured this assignment will
+ preserve the argument's value. */
+ unsigned long n = n_max;
+
+ test_group_begin ("0x%lx", n);
+ {
+ test ("test_ulong passed a valid 'unsigned long' value (meta-test)");
+ pass_if (n == n_max);
+
+ /* Some values we really ought to be able to represent.
+ mn_ulong_is_number shouldn't return false for everything. */
+ if (n <= 255)
+ {
+ test ("mn_ulong_is_number admits value");
+ pass_if (mn_ulong_is_number (c, n));
+ }
+
+ /* Are we able to represent this value at all? */
+ else if (! mn_ulong_is_number (c, n))
+ {
+ test_group_end ();
+ return;
+ }
+
+ mn_ref *r = mn_from_ulong (c, n);
+
+ test ("mn_to_ulong preserves value");
+ pass_if (mn_to_ulong (c, r) == n);
+
+ test ("mn_number_p returns true");
+ pass_if (mn_number_p (c, r));
+
+ test ("mn_exact_p returns true");
+ pass_if (mn_exact_p (c, r));
+
+ test ("mn_integer_p returns true");
+ pass_if (mn_integer_p (c, r));
+
+ test ("mn_exact_integer_p returns true");
+ pass_if (mn_exact_integer_p (c, r));
+
+ test ("mn_number_is_ulong returns true");
+ pass_if (mn_number_is_ulong (c, r));
+
+ mn_free_local_ref (c, r);
+ }
+ test_group_end ();
+}
+
+
+static void
+test_ullong (mn_call *c, uintmax_t n_max)
+{
+ /* The arguments to unsigned_iterator ensured this assignment will
+ preserve the argument's value. */
+ unsigned long long n = n_max;
+
+ test_group_begin ("0x%llx", n);
+ {
+ test ("test_ullong passed a valid 'unsigned long long' value (meta-test)");
+ pass_if (n == n_max);
+
+ /* Some values we really ought to be able to represent.
+ mn_ullong_is_number shouldn't return false for everything. */
+ if (n <= 255)
+ {
+ test ("mn_ullong_is_number admits value");
+ pass_if (mn_ullong_is_number (c, n));
+ }
+
+ /* Are we able to represent this value at all? */
+ else if (! mn_ullong_is_number (c, n))
+ {
+ test_group_end ();
+ return;
+ }
+
+ mn_ref *r = mn_from_ullong (c, n);
+
+ test ("mn_to_ullong preserves value");
+ pass_if (mn_to_ullong (c, r) == n);
+
+ test ("mn_number_p returns true");
+ pass_if (mn_number_p (c, r));
+
+ test ("mn_exact_p returns true");
+ pass_if (mn_exact_p (c, r));
+
+ test ("mn_integer_p returns true");
+ pass_if (mn_integer_p (c, r));
+
+ test ("mn_exact_integer_p returns true");
+ pass_if (mn_exact_integer_p (c, r));
+
+ test ("mn_number_is_ullong returns true");
+ pass_if (mn_number_is_ullong (c, r));
+
+ mn_free_local_ref (c, r);
+ }
+ test_group_end ();
+}
+
+
/* For each type, we want to test the following values:
- all values with one or two bits set; and
- all values that are all zero-bits on one half, and all one-bits
@@ -191,13 +372,50 @@
static void
+unsigned_iterator (mn_call *c, const char *name, uintmax_t max,
+ void (*test_val) (mn_call *, uintmax_t n))
+{
+ test_group_begin ("%s", name);
+ {
+ uintmax_t i, j;
+
+ /* All the values with one or two bits set. */
+ for (i = (max >> 1) + 1; i; i >>= 1)
+ for (j = i >> 1; j; j >>= 1)
+ test_val (c, i | j);
+
+ /* All the values whose upper halves are zero, and whose lower
+ halves are ones. This loop includes the all-ones value, but
+ excludes zero; we catch it later. */
+ for (i = max; i; i >>= 1)
+ test_val (c, i);
+
+ /* All the values whose upper halves are ones, and whose lower
+ halves are zeros. This loop excludes the all-ones value and
+ zero. */
+ for (i = max - 1; i; i &= i - 1)
+ test_val (c, i);
+
+ /* Don't miss zero. */
+ test_val (c, 0);
+ }
+ test_group_end ();
+}
+
+
+static void
worker (int t)
{
mn_call *c = mn_first_call ();
- signed_iterator (c, "int", INT_MIN, INT_MAX, test_int);
- signed_iterator (c, "long", LONG_MIN, LONG_MAX, test_long);
+ signed_iterator (c, "int", INT_MIN, INT_MAX, test_int);
+ signed_iterator (c, "long", LONG_MIN, LONG_MAX, test_long);
signed_iterator (c, "long long", LLONG_MIN, LLONG_MAX, test_llong);
+
+ unsigned_iterator (c, "unsigned int", UINT_MAX, test_uint);
+ unsigned_iterator (c, "unsigned long", ULONG_MAX, test_ulong);
+ unsigned_iterator (c, "unsigned long long", ULLONG_MAX, test_ullong);
+
}
More information about the Minor
mailing list