diff options
author | neal <neal> | 2007-10-17 13:04:39 +0000 |
---|---|---|
committer | neal <neal> | 2007-10-17 13:04:39 +0000 |
commit | 0281ec92a5fbc2be3c1b871388275a72751e61ff (patch) | |
tree | 63d692b642bd6c75a16ce80234d37a26c19d5648 /libbitarray/t-bit-array.c | |
parent | 1d614de164669b727a84ee9ab2bedfc0b62a331e (diff) |
/
2007-10-17 Neal H. Walfield <neal@gnu.org>
* libbitarray: New directory.
* configure.ac: m4_include libbitarray/headers.m4.
(AC_CONFIGU_FILES): Add libbitarray/Makefile.
* Makefile.am (SUBDIRS): Add libbitarray.
libbitarray/
2007-10-17 Neal H. Walfield <neal@gnu.org>
* ChangeLog: New file.
* Makefile.am: Likewise.
* bit-array.h: Likewise.
* headers.m4: Likewise.
* t-bit-array.c: Likewise.
Diffstat (limited to 'libbitarray/t-bit-array.c')
-rw-r--r-- | libbitarray/t-bit-array.c | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/libbitarray/t-bit-array.c b/libbitarray/t-bit-array.c new file mode 100644 index 0000000..4d28275 --- /dev/null +++ b/libbitarray/t-bit-array.c @@ -0,0 +1,55 @@ +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <assert.h> +#include <stdio.h> +#include <string.h> + +#include "bit-array.h" + +static unsigned char array[16]; + +int +main (int argc, char *argv[]) +{ + /* Make sure we can set all the bits when the bit to set is the one + under the hint. */ + int i; + for (i = 0; i < sizeof (array) * 8; i ++) + assert (bit_alloc (array, sizeof (array), i) == i); + assert (bit_alloc (array, sizeof (array), 1) == -1); + + memset (array, 0, sizeof (array)); + + /* Make sure we can set all the bits when the bit to set is not + (necessarily) under the hint. */ + for (i = 0; i < sizeof (array) * 8; i ++) + { + int b = (10 + i) % (sizeof (array) * 8); + assert (bit_alloc (array, sizeof (array), 10) == b); + } + assert (bit_alloc (array, sizeof (array), 1) == -1); + + /* Clear one bit and make sure that independent of the start hint, + we find that bit. */ + for (i = 0; i < sizeof (array) * 8; i ++) + { + bit_dealloc (array, 75); + + assert (bit_alloc (array, sizeof (array), i) == 75); + assert (bit_alloc (array, sizeof (array), i) == -1); + } + + /* See if we can set a bit in the middle of a byte. */ + bit_dealloc (array, 11); + assert (bit_set (array, sizeof (array), 11) == true); + assert (bit_set (array, sizeof (array), 11) == false); + + /* And at the start of a byte. */ + bit_dealloc (array, 24); + assert (bit_set (array, sizeof (array), 24) == true); + assert (bit_set (array, sizeof (array), 24) == false); + + return 0; +} |