1
0
mirror of https://github.com/moparisthebest/curl synced 2024-12-21 23:58:49 -05:00

tests: added test for Curl_splaygetbest to unit1309

This checks the new behavior of Curl_splaygetbest, so that the smallest
node not larger than the key is removed, and FIFO behavior is kept even
when there are multiple nodes with the same key.

Closes #1358
This commit is contained in:
Dániel Bakai 2017-04-03 09:16:21 +02:00 committed by Daniel Stenberg
parent de05bcb706
commit 6193770ee1
2 changed files with 146 additions and 3 deletions

View File

@ -1451,6 +1451,117 @@ remove pointer 5, payload 659
Tree look:
0.177[0]
remove pointer 6, payload 177
Removing nodes not larger than 0
removed payload 0[0]
Removing nodes not larger than 100
removed payload 39[0]
removed payload 49[0]
removed payload 49[1]
removed payload 59[0]
removed payload 59[1]
removed payload 59[2]
removed payload 98[0]
removed payload 98[1]
removed payload 98[2]
Removing nodes not larger than 200
removed payload 108[0]
removed payload 118[0]
removed payload 118[1]
removed payload 157[0]
removed payload 157[1]
removed payload 167[0]
removed payload 167[1]
removed payload 167[2]
removed payload 177[0]
Removing nodes not larger than 300
removed payload 216[0]
removed payload 226[0]
removed payload 226[1]
removed payload 236[0]
removed payload 236[1]
removed payload 236[2]
removed payload 275[0]
removed payload 275[1]
removed payload 275[2]
removed payload 285[0]
removed payload 295[0]
removed payload 295[1]
Removing nodes not larger than 400
removed payload 334[0]
removed payload 334[1]
removed payload 344[0]
removed payload 344[1]
removed payload 344[2]
removed payload 354[0]
removed payload 393[0]
Removing nodes not larger than 500
removed payload 403[0]
removed payload 403[1]
removed payload 413[0]
removed payload 413[1]
removed payload 413[2]
removed payload 462[0]
removed payload 472[0]
removed payload 472[1]
Removing nodes not larger than 600
removed payload 521[0]
removed payload 521[1]
removed payload 521[2]
removed payload 531[0]
removed payload 541[0]
removed payload 541[1]
removed payload 580[0]
removed payload 580[1]
removed payload 590[0]
removed payload 590[1]
removed payload 590[2]
removed payload 600[0]
Removing nodes not larger than 700
removed payload 639[0]
removed payload 649[0]
removed payload 649[1]
removed payload 659[0]
removed payload 659[1]
removed payload 659[2]
removed payload 698[0]
removed payload 698[1]
removed payload 698[2]
Removing nodes not larger than 800
removed payload 708[0]
removed payload 718[0]
removed payload 718[1]
removed payload 757[0]
removed payload 757[1]
removed payload 767[0]
removed payload 767[1]
removed payload 767[2]
removed payload 777[0]
Removing nodes not larger than 900
removed payload 816[0]
removed payload 826[0]
removed payload 826[1]
removed payload 836[0]
removed payload 836[1]
removed payload 836[2]
removed payload 875[0]
removed payload 875[1]
removed payload 875[2]
removed payload 885[0]
removed payload 895[0]
removed payload 895[1]
Removing nodes not larger than 1000
removed payload 934[0]
removed payload 934[1]
removed payload 944[0]
removed payload 944[1]
removed payload 944[2]
removed payload 954[0]
Removing nodes not larger than 1100
removed payload 1003[0]
removed payload 1003[1]
removed payload 1013[0]
removed payload 1013[1]
removed payload 1013[2]
</stdout>
</verify>

View File

@ -70,12 +70,14 @@ UNITTEST_START
/* number of nodes to add to the splay tree */
#define NUM_NODES 50
struct Curl_tree *root;
struct Curl_tree nodes[NUM_NODES];
struct Curl_tree *root, *removed;
struct Curl_tree nodes[NUM_NODES*3];
int rc;
int i;
int i, j;
struct timeval tv_now = {0, 0};
root = NULL; /* the empty tree */
/* add nodes */
for(i = 0; i < NUM_NODES; i++) {
struct timeval key;
@ -103,6 +105,36 @@ UNITTEST_START
}
}
fail_unless(root == NULL, "tree not empty after removing all nodes");
/* rebuild tree */
for(i = 0; i < NUM_NODES; i++) {
struct timeval key;
key.tv_sec = 0;
key.tv_usec = (541*i)%1023;
/* add some nodes with the same key */
for(j = 0; j <= i % 3; j++) {
nodes[i*3+j].payload = (void *)(key.tv_usec*10 + j); /* for simplicity */
root = Curl_splayinsert(key, root, &nodes[i*3+j]);
}
}
removed = NULL;
for(i = 0; i <= 1100; i+= 100) {
printf("Removing nodes not larger than %d\n", i);
tv_now.tv_usec = i;
root = Curl_splaygetbest(tv_now, root, &removed);
while(removed != NULL) {
printf("removed payload %ld[%ld]\n", (long)(removed->payload) / 10,
(long)(removed->payload) % 10);
root = Curl_splaygetbest(tv_now, root, &removed);
}
}
fail_unless(root == NULL, "tree not empty when it should be");
UNITTEST_STOP