This commit is contained in:
Gregory Burd 2024-04-07 22:35:42 -04:00
parent f857c48fb2
commit 938fde14c3
5 changed files with 48 additions and 242 deletions

View file

@ -37,8 +37,8 @@ main(void)
// randomize setting the bits on
shuffle(array, TEST_ARRAY_SIZE);
//print_array(array, TEST_ARRAY_SIZE);
//print_spans(array, TEST_ARRAY_SIZE);
// print_array(array, TEST_ARRAY_SIZE);
// print_spans(array, TEST_ARRAY_SIZE);
// set all the bits on in a random order
for (i = 0; i < TEST_ARRAY_SIZE; i++) {
@ -46,15 +46,15 @@ main(void)
assert(sparsemap_is_set(map, array[i]) == true);
}
// for (size_t len = 1; len < 20; len++) {
// for (size_t len = 1; len < TEST_ARRAY_SIZE - 1; len++) {
// for (size_t len = 1; len <= 1; len++) {
// for (size_t len = 2; len <= 2; len++) {
// for (size_t len = 3; len <= 3; len++) {
// for (size_t len = 4; len <= 4; len++) {
// for (size_t len = 5; len <= 5; len++) {
// for (size_t len = 8; len <= 8; len++) {
for (size_t len = 372; len <= 372; len++) {
// for (size_t len = 1; len < 20; len++) {
// for (size_t len = 1; len < TEST_ARRAY_SIZE - 1; len++) {
// for (size_t len = 1; len <= 1; len++) {
// for (size_t len = 2; len <= 2; len++) {
// for (size_t len = 3; len <= 3; len++) {
// for (size_t len = 4; len <= 4; len++) {
// for (size_t len = 5; len <= 5; len++) {
// for (size_t len = 8; len <= 8; len++) {
for (size_t len = 372; len <= 372; len++) {
__diag("================> %lu\n", len);
sparsemap_clear(map);
// set all the bits on in a random order

View file

@ -1,196 +0,0 @@
static void *
test_api_setup(const MunitParameter params[], void *user_data)
{
struct test_info *info = (struct test_info *)user_data;
(void)info;
(void)params;
ex_sl_t *slist = calloc(sizeof(ex_sl_t), 1);
if (slist == NULL)
return NULL;
sl_init(slist, uint32_key_cmp);
return (void *)(uintptr_t)slist;
}
static void
test_api_tear_down(void *fixture)
{
ex_sl_t *slist = (ex_sl_t *)fixture;
assert_ptr_not_null(slist);
sl_node *cursor = sl_begin(slist);
while (cursor) {
assert_ptr_not_null(cursor);
ex_node_t *entry = sl_get_entry(cursor, ex_node_t, snode);
assert_ptr_not_null(entry);
assert_uint32(entry->key, ==, entry->value);
cursor = sl_next(slist, cursor);
sl_erase_node(slist, &entry->snode);
sl_release_node(&entry->snode);
sl_wait_for_free(&entry->snode);
sl_free_node(&entry->snode);
free(entry);
}
sl_free(slist);
free(fixture);
}
static void *
test_api_insert_setup(const MunitParameter params[], void *user_data)
{
return test_api_setup(params, user_data);
}
static void
test_api_insert_tear_down(void *fixture)
{
test_api_tear_down(fixture);
}
static MunitResult
test_api_insert(const MunitParameter params[], void *data)
{
sl_raw *slist = (sl_raw *)data;
(void)params;
assert_ptr_not_null(data);
int n = munit_rand_int_range(128, 4096);
int key = munit_rand_int_range(0, (((uint32_t)0) - 1) / 10);
while (n--) {
ex_node_t *node = (ex_node_t *)calloc(sizeof(ex_node_t), 1);
sl_init_node(&node->snode);
node->key = key;
node->value = key;
sl_insert(slist, &node->snode);
}
return MUNIT_OK;
}
static void *
test_api_remove_setup(const MunitParameter params[], void *user_data)
{
return test_api_setup(params, user_data);
}
static void
test_api_remove_tear_down(void *fixture)
{
test_api_tear_down(fixture);
}
static MunitResult
test_api_remove(const MunitParameter params[], void *data)
{
sl_raw *slist = (sl_raw *)data;
(void)params;
(void)slist;
return MUNIT_OK;
}
static void *
test_api_find_setup(const MunitParameter params[], void *user_data)
{
return test_api_setup(params, user_data);
}
static void
test_api_find_tear_down(void *fixture)
{
test_api_tear_down(fixture);
}
static MunitResult
test_api_find(const MunitParameter params[], void *data)
{
sl_raw *slist = (sl_raw *)data;
(void)params;
(void)slist;
return MUNIT_OK;
}
static void *
test_api_update_setup(const MunitParameter params[], void *user_data)
{
return test_api_setup(params, user_data);
}
static void
test_api_update_tear_down(void *fixture)
{
test_api_tear_down(fixture);
}
static MunitResult
test_api_update(const MunitParameter params[], void *data)
{
sl_raw *slist = (sl_raw *)data;
(void)params;
(void)slist;
return MUNIT_OK;
}
static void *
test_api_delete_setup(const MunitParameter params[], void *user_data)
{
return test_api_setup(params, user_data);
}
static void
test_api_delete_tear_down(void *fixture)
{
test_api_tear_down(fixture);
}
static MunitResult
test_api_delete(const MunitParameter params[], void *data)
{
sl_raw *slist = (sl_raw *)data;
(void)params;
(void)slist;
return MUNIT_OK;
}
static void *
test_api_duplicates_setup(const MunitParameter params[], void *user_data)
{
return test_api_setup(params, user_data);
}
static void
test_api_duplicates_tear_down(void *fixture)
{
test_api_tear_down(fixture);
}
static MunitResult
test_api_duplicates(const MunitParameter params[], void *data)
{
sl_raw *slist = (sl_raw *)data;
(void)params;
(void)slist;
return MUNIT_OK;
}
static void *
test_api_size_setup(const MunitParameter params[], void *user_data)
{
return test_api_setup(params, user_data);
}
static void
test_api_size_tear_down(void *fixture)
{
test_api_tear_down(fixture);
}
static MunitResult
test_api_size(const MunitParameter params[], void *data)
{
sl_raw *slist = (sl_raw *)data;
(void)params;
(void)slist;
return MUNIT_OK;
}
static void *
test_api_iterators_setup(const MunitParameter params[], void *user_data)
{
return test_api_setup(params, user_data);
}
static void
test_api_iterators_tear_down(void *fixture)
{
test_api_tear_down(fixture);
}
static MunitResult
test_api_iterators(const MunitParameter params[], void *data)
{
sl_raw *slist = (sl_raw *)data;
(void)params;
(void)slist;
return MUNIT_OK;
}

View file

@ -16,7 +16,8 @@ uint32_t
xorshift32()
{
uint32_t x = *state = &__prng;
if (x == 0) x = 123456789;
if (x == 0)
x = 123456789;
x ^= x << 13;
x ^= x >> 17;
x ^= x << 5;
@ -25,7 +26,8 @@ xorshift32()
}
void
xorshift32_seed() {
xorshift32_seed()
{
// Seed the PRNG
#ifdef STABLE_SEED
__prng = 8675309;
@ -62,12 +64,15 @@ compare_ints(const void *a, const void *b)
}
// Check if there's already a sequence of 'r' sequential integers
int has_sequential_set(int *a, size_t l, int r) {
int
has_sequential_set(int *a, size_t l, int r)
{
int count = 1; // Start with a count of 1 for the first number
for (size_t i = 1; i < l; ++i) {
if (a[i] - a[i - 1] == 1) { // Check if the current and previous elements are sequential
count++;
if (count >= r) return 1; // Found a sequential set of length 'r'
if (count >= r)
return 1; // Found a sequential set of length 'r'
} else {
count = 1; // Reset count if the sequence breaks
}
@ -76,8 +81,11 @@ int has_sequential_set(int *a, size_t l, int r) {
}
// Function to ensure an array contains a set of 'r' sequential integers
void ensure_sequential_set(int *a, size_t l, int r) {
if (r > l) return; // If 'r' is greater than array length, cannot satisfy the condition
void
ensure_sequential_set(int *a, size_t l, int r)
{
if (r > l)
return; // If 'r' is greater than array length, cannot satisfy the condition
// Sort the array to check for existing sequences
qsort(a, l, sizeof(int), compare_ints);
@ -226,7 +234,8 @@ was_set(size_t bit, const int array[])
}
int
is_unique(int a[], size_t l, int value) {
is_unique(int a[], size_t l, int value)
{
for (size_t i = 0; i < l; ++i) {
if (a[i] == value) {
return 0; // Not unique
@ -238,14 +247,14 @@ is_unique(int a[], size_t l, int value) {
void
setup_test_array(int a[], size_t l, int max_value)
{
if (a == NULL || max_value < 0) return; // Basic error handling and validation
if (a == NULL || max_value < 0)
return; // Basic error handling and validation
for (size_t i = 0; i < l; ++i) {
int candidate;
do {
candidate = xorshift32() % (max_value + 1); // Generate a new value within the specified range
} while (!is_unique(a, i, candidate)); // Repeat until a unique value is found
a[i] = candidate; // Assign the unique value to the array
} while (!is_unique(a, i, candidate)); // Repeat until a unique value is found
a[i] = candidate; // Assign the unique value to the array
}
}

View file

@ -21,6 +21,9 @@
* SOFTWARE.
*/
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wpedantic"
/*** Configuration ***/
/* This is just where the output from the test goes. It's really just
@ -2253,3 +2256,5 @@ munit_suite_main(const MunitSuite *suite, void *user_data, int argc,
{
return munit_suite_main_custom(suite, user_data, argc, argv, NULL);
}
#pragma GCC diagnostic pop

View file

@ -10,12 +10,12 @@
#define MUNIT_NO_FORK (1)
#define MUNIT_ENABLE_ASSERT_ALIASES (1)
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <assert.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "../include/sparsemap.h"
@ -27,8 +27,7 @@
#include "common.c"
struct user_data {
};
struct user_data { };
void
__populate_map(sparsemap_t *map, size_t size, size_t max_value)
@ -48,7 +47,7 @@ test_api_setup(const MunitParameter params[], void *user_data)
{
struct test_info *info = (struct test_info *)user_data;
(void)params;
sparsemap_t *map = munit_calloc(1, sizeof(sparsemap));
sparsemap_t *map = munit_calloc(1, sizeof(sparsemap_t));
assert_ptr_not_null(map);
return (void *)(uintptr_t)map;
}
@ -106,7 +105,6 @@ test_api_clear(const MunitParameter params[], void *data)
assert_ptr_not_null(map);
assert_true(map->m_data_size == 1024);
assert_true(map->m_data_used == 412);
sparsemap_clear(map);
@ -217,27 +215,17 @@ test_api_is_set(const MunitParameter params[], void *data)
return MUNIT_OK;
}
static MunitTest api_test_suite[] = { { (char *)"/api/static_init", test_api_static_init, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL },
{ (char *)"/api/clear", test_api_clear, test_api_clear_setup, test_api_clear_tear_down, MUNIT_TEST_OPTION_NONE, NULL },
{ (char *)"/api/set_data_size", test_api_set_data_size, test_api_set_data_size_setup, test_api_set_data_size_tear_down, MUNIT_TEST_OPTION_NONE, NULL },
{ (char *)"/api/is_set", test_api_is_set, test_api_is_set_setup, test_api_is_set_tear_down, MUNIT_TEST_OPTION_NONE, NULL },
{ NULL, NULL, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL } };
static MunitTest api_test_suite[] = {
{ (char *)"/api/static_init", test_api_static_init, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL },
{ (char *)"/api/clear", test_api_clear, test_api_clear_setup,
test_api_clear_tear_down, MUNIT_TEST_OPTION_NONE, NULL },
{ (char *)"/api/set_data_size", test_api_set_data_size, test_api_set_data_size_setup,
test_api_set_data_size_tear_down, MUNIT_TEST_OPTION_NONE, NULL },
{ (char *)"/api/is_set", test_api_is_set, test_api_is_set_setup,
test_api_is_set_tear_down, MUNIT_TEST_OPTION_NONE, NULL },
{ NULL, NULL, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL }
};
static MunitTest scale_tests[] = { { NULL, NULL, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL } };
static MunitTest scale_tests[] = { { NULL, NULL, NULL, NULL,
MUNIT_TEST_OPTION_NONE, NULL } };
static MunitSuite other_test_suite[] = { { "/scale", scale_tests, NULL, 1, MUNIT_SUITE_OPTION_NONE }, { NULL, NULL, NULL, 0, MUNIT_SUITE_OPTION_NONE } };
static MunitSuite other_test_suite[] = {
{ "/scale", scale_tests, NULL, 1, MUNIT_SUITE_OPTION_NONE },
{ NULL, NULL, NULL, 0, MUNIT_SUITE_OPTION_NONE } };
static const MunitSuite main_test_suite = { (char *)"/api", api_test_suite,
other_test_suite, 1, MUNIT_SUITE_OPTION_NONE };
static const MunitSuite main_test_suite = { (char *)"/api", api_test_suite, other_test_suite, 1, MUNIT_SUITE_OPTION_NONE };
int
main(int argc, char *argv[MUNIT_ARRAY_PARAM(argc + 1)])