Esempio n. 1
0
char *test_speed() {
    size_t N = 100000;
    int i = 0;
    clock_t fastest = LONG_MAX;

    RadixMap *source_map = RadixMap_create(N);
    mu_assert(source_map != NULL, "Failed to make the map.");
    mu_assert(make_random(source_map), "Didn't make a random fake radix map.");

    for(i = 0; i < 100; i++) {
        RadixMap *map = RadixMap_create(N);
        mu_assert(map != NULL, "Failed to make the map.");

        mu_assert(RadixMap_copy(source_map, map) == 0,
                "Copying unsorted RadixMap failed.");

        clock_t elapsed = -clock();
        RadixMap_sort(map, 0, map->end);
        elapsed += clock();

        if(elapsed < fastest) fastest = elapsed;
        mu_assert(check_order(map), "Failed to sort the RadixMap.");

        RadixMap_destroy(map);
    }

    RadixMap_destroy(source_map);
    debug("Fastest time for size %zu: %f", N, ((float)fastest)/CLOCKS_PER_SEC);

    return NULL;
}
Esempio n. 2
0
static char *test_operations()
{
    size_t N = 200;

    RadixMap *map = RadixMap_create(N);
    mu_assert(map != NULL, "Failed to make map");
    mu_assert(make_random(map), "Didn't make a random fake radix map");

    RadixMap_sort(map);
    mu_assert(check_order(map),
            "Failed to properly sort the RadixMap");

    mu_assert(test_search(map), "Failed the search test");
    mu_assert(check_order(map), "RadixMap didn't stay sorted after search");

    while (map->end > 0) {
        RMElement *el = RadixMap_find(map,
                map->contents[map->end/2].data.key);
        mu_assert(el != NULL, "Should get a result");

        size_t old_end = map->end;

        mu_assert(RadixMap_delete(map, el) == 0, "Didn't delete it");
        mu_assert(old_end - 1 == map->end, "Wrong size after delete");

        // test that the end is now the old value
        // but uint32 max so it trails off
        mu_assert(check_order(map),
                "RadixMap didn't stay sorted after delete");
    }
    RadixMap_destroy(map);

    return NULL;
}
Esempio n. 3
0
// test for large number of elements
static char *test_operations() {
    size_t N = 200;
    RadixMap *map = RadixMap_create(N);
    mu_assert(map != NULL, "failed to make the map");
    mu_assert(make_random(map), "did not make a random fake radix map");

    RadixMap_sort(map);
    mu_assert(check_order(map), "failed to properly sort the RadixMap");
    mu_assert(test_search(map), "failed the search test");
    mu_assert(check_order(map), "RadixMap not sorted after seach");

    while (map->end > 0) {
        RMElement *el = RadixMap_find(map, map->contents[map->end / 2].data.key);
        mu_assert(el != NULL, "should get a result");

        size_t old_end = map->end;

        mu_assert(RadixMap_delete(map, el) == 0, "did not delete element");
        mu_assert(old_end - 1 == map->end, "wrong size after delete");
        mu_assert(check_order(map), "did not stay sorted after delete");
    }
    RadixMap_destroy(map);

    return NULL;
}
Esempio n. 4
0
static char *test_operations()
{
    size_t N = 200;

    RadixMap *map = RadixMap_create(N);
    mu_assert(map != NULL, "Failed to make the map.");

    mu_assert(make_random(map), "Didn't make a random fake radix map.");
    //In Zed's code was:
    //RadixMap_sort(map, 0);
    //I think we should sort it again because we do it every time we add a new value
    mu_assert(check_order(map), "Failed to properly sort the RadixMap.");

    mu_assert(test_search(map), "Failed to search test.");
    mu_assert(check_order(map), "RadixMap didn't stay sorted after search.");

    while(map->end > 0) {

        RMElement *el = RadixMap_find(map, map->contents[map->end / 2].data.key);
        mu_assert(el != NULL, "Should get a result.");

        size_t old_end = map->end;

        mu_assert(RadixMap_delete(map, el) == 0, "Didn't delete it.");
        mu_assert(old_end - 1 == map->end, "Wrong size after delete.");

        //test taht the end is now the old value, but uint32 max so it trails off
        mu_assert(check_order(map), "RadixMap didn't stay sorted after delete.");
    }

    RadixMap_destroy(map);

    return NULL;
}
Esempio n. 5
0
void rm_lifecycle()
{
    size_t N = 500;
    RadixMap *perf = RadixMap_create(N);
    make_random(perf);
    RadixMap_destroy(perf);
}
Esempio n. 6
0
static char *test_RadixMap_simulate()
{
   uint32_t fd = (uint32_t)(rand() | (rand() << 16));
   int i = 0;
   size_t key = 0;
   int connects = 0, disconnects = 0, activities = 0;
   RMElement *el = NULL;
   RadixMap *map = RadixMap_create(50000);
   // start the counter at just near max to test that out
   map->counter = UINT32_MAX - 100;

   debug("COUNTER: %u", map->counter);

   for(i = 0; i < 10; i++) {
       // seed it up
       RadixMap_push(map, fd++);
   }

   debug("ENTERING LOOP");
   for(i = 0; i < 1000000; i++) {
       switch((rand() + 1) % 4) {
           case 0:
               // connect, so add it on
               RadixMap_push(map, fd++);
               connects++;
               break;
           case 1:
               // disconnect, so remove
               if(map->end > 0) {
                   key = (rand() + 1) % map->end;
                   el = &map->contents[key];
                   el = RadixMap_find(map, el->data.key);
                   mu_assert(el != NULL, "Failed to find the key.");
                   RadixMap_delete(map, el);
               }
               disconnects++;
               break;

           default:
               // activity so find for doing stuff
               if(map->end > 0) {
                   key = (rand() + 1) % map->end;
                   el = &map->contents[key];
                   el = RadixMap_find(map, el->data.key);
                   mu_assert(el != NULL, "Failed to find the key.");
               }
               activities++;
               break;
       }

       if(map->end == 0) {
           // make a new connect if we're empty
           RadixMap_push(map, fd++);
       }
   }

   RadixMap_destroy(map);
   return NULL;
}
Esempio n. 7
0
// test for big number of elements
static char *test_RadixMap_operations()
{
    size_t N = 200;

    RadixMap *map = RadixMap_create(N);
    mu_assert(map != NULL, "Failed to make the map.");
    mu_assert(make_random(map), "Didn't make a random fake radix map.");

    RadixMap_sort(map);
    mu_assert(check_order(map), "Failed to properly sort the RadixMap.");

    mu_assert(test_search(map), "Failed the search test.");
    mu_assert(check_order(map), "RadixMap didn't stay sorted after search.");

    RadixMap_destroy(map);

    map = RadixMap_create(N);
    mu_assert(map != NULL, "Failed to make the map.");

    debug("PUSHING VALUES");
    mu_assert(push_random_values(map), "Didn't push random values.");
    debug("VALUES PUSHED!");

    mu_assert(check_order(map), "Map wasn't sorted after pushes.");

    debug("DOING DELETES");
    while(map->end > 0) {
        RMElement *el = RadixMap_find(map, map->contents[map->end / 2].data.key);
        mu_assert(el != NULL, "Should get a result.");

        size_t old_end = map->end;

        mu_assert(RadixMap_delete(map, el) == 0, "Didn't delete it.");
        mu_assert(old_end - 1 == map->end, "Wrong size after delete.");

        // test that the end is now the old value, but uint32 max so it trails off
        mu_assert(check_order(map), "RadixMap didn't stay sorted after delete.");
    }

    RadixMap_destroy(map);

    return NULL;
}
Esempio n. 8
0
char *test_copy() {
    size_t N = 100;
    RadixMap *src = RadixMap_create(N);
    RadixMap *copy = RadixMap_create(N);

    RadixMap_copy(src, copy);

    mu_assert(src->max == copy->max, "Didn't copy max.");
    mu_assert(src->end == copy->end, "Didn't copy end.");
    mu_assert(src->high == copy->high, "Didn't copy high.");
    mu_assert(src->low == copy->low, "Didn't copy low.");
    mu_assert(src->counter == copy->counter, "Didn't copy counter.");
    mu_assert(src->counter == copy->counter, "Didn't copy counter.");

    RadixMap_destroy(copy);
    RadixMap_destroy(src);

    return NULL;
}
Esempio n. 9
0
void Register_destroy()
{
    darray_destroy(REGISTRATIONS);
    RadixMap_destroy(REG_ID_TO_FD);
}