Example #1
0
char *test_delete()
{
	bstring deleted = (bstring) BSTree_delete(map, &test1);
	mu_assert(deleted != NULL, "Got NULL on delete.");
	mu_assert(deleted == &expect1, "Should get test1");
	bstring result = BSTree_get(map, &test1);
	mu_assert(result == NULL, "Should delete.");

	deleted = (bstring) BSTree_delete(map, &test1);
	mu_assert(deleted == NULL, "Should get NULL on delete.");

	deleted = (bstring) BSTree_delete(map, &test2);
	mu_assert(deleted != NULL, "Got NULL on delete.");
	mu_assert(deleted == &expect2, "Should get test2");
	result = BSTree_get(map, &test2);
	mu_assert(result == NULL, "Should delete.");

	deleted = (bstring) BSTree_delete(map, &test3);
	mu_assert(deleted != NULL, "Got NULL on delete.");
	mu_assert(deleted == &expect3, "Should get test3");
	result = BSTree_get(map, &test3);
	mu_assert(result == NULL, "Should delete.");

	// test deleting non-existent stuff
	deleted = (bstring) BSTree_delete(map, &test3);
	mu_assert(deleted == NULL, "Should get a NULL");

	return NULL;
}
Example #2
0
char *test_fuzzing()
{
	BSTree *store = BSTree_create(NULL);
	int i = 0;
	int j = 0;
	bstring numbers[100] = {NULL};
	bstring data[100] = {NULL};
	srand((unsigned int)time(NULL));

	for(i = 0; i < 100; i++) {
		int num = rand();
		numbers[i] = bformat("%d", num);
		data[i] = bformat("data %d", num);
		BSTree_set(store, numbers[i], data[i]);
	}

	for(i = 0; i < 100; i++) {
		bstring value = BSTree_delete(store, numbers[i]);
		mu_assert(value == data[i], "Failed to delete the right number.");

		mu_assert(BSTree_delete(store, numbers[i]) == NULL, "Should get nothing.");

		for(j = j+1; j < 99 - i; j++) {
			bstring value = BSTree_get(store, numbers[j]);
			mu_assert(value == data[j], "Failed to get the right number.");
		}

		bdestroy(value);
		bdestroy(numbers[i]);
	}

	BSTree_destroy(store);

	return NULL;
}
Example #3
0
char *test_delete()
{
    char *deleted = (char *)BSTree_delete(map, test1);
    mu_assert(deleted != NULL, "Got NULL on delete.");
    mu_assert(deleted == expect1, "Should get test1");
    char *result = BSTree_get(map, test1);
    mu_assert(result == NULL, "Should delete.");

    deleted = (char *)BSTree_delete(map, &test1);
    mu_assert(deleted == NULL, "Should get NULL on delete");

    deleted = (char *)BSTree_delete(map, test2);
    mu_assert(deleted != NULL, "Got NULL on delete.");
    mu_assert(deleted == expect2, "Should get test2");
    result = BSTree_get(map, test2);
    mu_assert(result == NULL, "Should delete.");

    deleted = (char *)BSTree_delete(map, test3);
    mu_assert(deleted != NULL, "Got NULL on delete.");
    mu_assert(deleted == expect3, "Should get test3");
    result = BSTree_get(map, test3);
    mu_assert(result == NULL, "Should delete.");

    deleted = (char *)BSTree_delete(map, test3);
    mu_assert(deleted == NULL, "Should get NULL");
 
    return NULL;
}
Example #4
0
char *test_delete()
{
	bstring deleted = (bstring)BSTree_delete(map, &test1);
	mu_assert(deleted != NULL, "Got NULL on delete.");
	mu_assert(deleted == &expect1, "Should got test1.");
	bstring result = BSTree_get(map, &test1);
	mu_assert(result == NULL, "Should delete.");
	
	deleted = (bstring)BSTree_delete(map, &test1);
	mu_assert(deleted == NULL, "Should got NULL on delete.");
	
	deleted = (bstring)BSTree_delete(map, &test2);
	mu_assert(deleted != NULL, "Got NULL on delete.");
	mu_assert(deleted == &expect2, "Should got test2.");
	result = BSTree_get(map, &test2);
	mu_assert(result == NULL, "Should delete.");
	
	deleted = (bstring)BSTree_delete(map, &test3);
	mu_assert(deleted != NULL, "Got NULL on delete.");
	mu_assert(deleted == &expect3, "Should got test3.");
	result = BSTree_get(map, &test3);
	mu_assert(result == NULL, "Should delete.");
	
	deleted = (bstring)BSTree_delete(map, &test3);
	mu_assert(deleted == NULL, "Should got NULL on delete.");

	return NULL;
}
Example #5
0
char *test_fuzzing()
{
    BSTree *store = BSTree_create(NULL);
    int i = 0;
    int j = 0;
    /*char *numbers[100] = {NULL};*/
    int numbers[100] = {0};
    char *data[100] = {NULL};
    srand((unsigned int)time(NULL));

    for(i = 0; i < 100; i++) {
        int num = rand();
        char *buf = calloc(1, sizeof(char *));
        /*sprintf(buf, "%d", num);*/
        /*numbers[i] = buf;*/
        numbers[i] = num;
        sprintf(buf, "data %d", i);
        data[i] = buf;
        buf = NULL;
        /*debug("Val: %d", *numbers[i]);*/
        BSTree_set(store, &numbers[i], data[i]);
    }

    for(i = 0; i < 100; i++) {
        char *value = BSTree_delete(store, &numbers[i]);
        mu_assert(value == data[i], "Failed to delete the right number.");
        mu_assert(BSTree_delete(store, &numbers[i]) == NULL, "Should get nothing.");
    
        for(j = i+1; j < 99 - i; j++) {
            char *value = BSTree_get(store, &numbers[j]);
            mu_assert(value == data[j], "Failed to get the right number.");
        }
    
        value = NULL;
    }

    BSTree_destroy(store);

    return NULL;
}