X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=tests%2Flibpspp%2Fhmap-test.c;h=fd568aec12033c0b8e135e344a0e92f8e9ee9564;hb=edf11a9f029cec53a56908f4debe887f12959512;hp=c8619a0511f5b60545e70d574798c2392f477243;hpb=373dbe766c1914b5b0d42c9d3012a28ffcb24a53;p=pspp diff --git a/tests/libpspp/hmap-test.c b/tests/libpspp/hmap-test.c index c8619a0511..fd568aec12 100644 --- a/tests/libpspp/hmap-test.c +++ b/tests/libpspp/hmap-test.c @@ -88,7 +88,6 @@ #include -#include #include #include #include @@ -285,13 +284,13 @@ random_shuffle (void *array_, size_t cnt, size_t size) typedef size_t hash_function (int data); static size_t -identity_hash (int data) +identity_hash (int data) { return data; } static size_t -constant_hash (int data UNUSED) +constant_hash (int data UNUSED) { return 0x12345678u; } @@ -356,7 +355,7 @@ check_hmap (struct hmap *hmap, const int data[], size_t cnt, count = 0; HMAP_FOR_EACH_WITH_HASH (e, struct element, node, hash (order[i]), hmap) - if (e->data == order[i]) + if (e->data == order[i]) count++; check (count == j - i); @@ -378,7 +377,7 @@ check_hmap (struct hmap *hmap, const int data[], size_t cnt, check (hmap_node_hash (&e->node) == hash (e->data)); for (j = 0; j < left; j++) - if (order[j] == e->data) + if (order[j] == e->data) { order[j] = order[--left]; goto next; @@ -448,7 +447,7 @@ test_insert_any_remove_any (hash_function *hash) for (cnt = 0; cnt <= max_elems; cnt++) { int *insertions, *deletions; - unsigned int ins_perm_cnt; + unsigned int ins_n_perms; int i; insertions = xnmalloc (cnt, sizeof *insertions); @@ -456,24 +455,24 @@ test_insert_any_remove_any (hash_function *hash) for (i = 0; i < cnt; i++) insertions[i] = i; - for (ins_perm_cnt = 0; - ins_perm_cnt == 0 || next_permutation (insertions, cnt); - ins_perm_cnt++) + for (ins_n_perms = 0; + ins_n_perms == 0 || next_permutation (insertions, cnt); + ins_n_perms++) { - unsigned int del_perm_cnt; + unsigned int del_n_perms; int i; for (i = 0; i < cnt; i++) deletions[i] = i; - for (del_perm_cnt = 0; - del_perm_cnt == 0 || next_permutation (deletions, cnt); - del_perm_cnt++) + for (del_n_perms = 0; + del_n_perms == 0 || next_permutation (deletions, cnt); + del_n_perms++) test_insert_delete (insertions, deletions, cnt, hash); - check (del_perm_cnt == factorial (cnt)); + check (del_n_perms == factorial (cnt)); } - check (ins_perm_cnt == factorial (cnt)); + check (ins_n_perms == factorial (cnt)); free (insertions); free (deletions); @@ -481,19 +480,19 @@ test_insert_any_remove_any (hash_function *hash) } static void -test_insert_any_remove_any_random_hash (void) +test_insert_any_remove_any_random_hash (void) { test_insert_any_remove_any (random_hash); } static void -test_insert_any_remove_any_identity_hash (void) +test_insert_any_remove_any_identity_hash (void) { test_insert_any_remove_any (identity_hash); } static void -test_insert_any_remove_any_constant_hash (void) +test_insert_any_remove_any_constant_hash (void) { test_insert_any_remove_any (constant_hash); } @@ -510,37 +509,37 @@ test_insert_any_remove_same (hash_function *hash) for (cnt = 0; cnt <= max_elems; cnt++) { int *values; - unsigned int permutation_cnt; + unsigned int n_permutations; int i; values = xnmalloc (cnt, sizeof *values); for (i = 0; i < cnt; i++) values[i] = i; - for (permutation_cnt = 0; - permutation_cnt == 0 || next_permutation (values, cnt); - permutation_cnt++) + for (n_permutations = 0; + n_permutations == 0 || next_permutation (values, cnt); + n_permutations++) test_insert_delete (values, values, cnt, hash); - check (permutation_cnt == factorial (cnt)); + check (n_permutations == factorial (cnt)); free (values); } } static void -test_insert_any_remove_same_random_hash (void) +test_insert_any_remove_same_random_hash (void) { test_insert_any_remove_same (random_hash); } static void -test_insert_any_remove_same_identity_hash (void) +test_insert_any_remove_same_identity_hash (void) { test_insert_any_remove_same (identity_hash); } static void -test_insert_any_remove_same_constant_hash (void) +test_insert_any_remove_same_constant_hash (void) { test_insert_any_remove_same (constant_hash); } @@ -557,7 +556,7 @@ test_insert_any_remove_reverse (hash_function *hash) for (cnt = 0; cnt <= max_elems; cnt++) { int *insertions, *deletions; - unsigned int permutation_cnt; + unsigned int n_permutations; int i; insertions = xnmalloc (cnt, sizeof *insertions); @@ -565,16 +564,16 @@ test_insert_any_remove_reverse (hash_function *hash) for (i = 0; i < cnt; i++) insertions[i] = i; - for (permutation_cnt = 0; - permutation_cnt == 0 || next_permutation (insertions, cnt); - permutation_cnt++) + for (n_permutations = 0; + n_permutations == 0 || next_permutation (insertions, cnt); + n_permutations++) { memcpy (deletions, insertions, sizeof *insertions * cnt); reverse (deletions, cnt); test_insert_delete (insertions, deletions, cnt, hash); } - check (permutation_cnt == factorial (cnt)); + check (n_permutations == factorial (cnt)); free (insertions); free (deletions); @@ -634,19 +633,19 @@ test_random_sequence (int max_elems, hash_function *hash) } static void -test_random_sequence_random_hash (void) +test_random_sequence_random_hash (void) { test_random_sequence (64, random_hash); } static void -test_random_sequence_identity_hash (void) +test_random_sequence_identity_hash (void) { test_random_sequence (64, identity_hash); } static void -test_random_sequence_constant_hash (void) +test_random_sequence_constant_hash (void) { test_random_sequence (32, constant_hash); } @@ -676,7 +675,7 @@ test_insert_ordered (int max_elems, hash_function *hash) hmap_insert (&hmap, &elements[i].node, hash (elements[i].data)); check_hmap (&hmap, values, i + 1, hash); - if (hash == identity_hash) + if (hash == identity_hash) { /* Check that every every hash bucket has (almost) the same number of nodes in it. */ @@ -684,7 +683,7 @@ test_insert_ordered (int max_elems, hash_function *hash) int max = INT_MIN; int j; - for (j = 0; j <= hmap.mask; j++) + for (j = 0; j <= hmap.mask; j++) { int count = 0; struct hmap_node *node; @@ -770,19 +769,19 @@ test_moved (int max_elems, hash_function *hash) } static void -test_moved_random_hash (void) +test_moved_random_hash (void) { test_moved (128, random_hash); } static void -test_moved_identity_hash (void) +test_moved_identity_hash (void) { test_moved (128, identity_hash); } static void -test_moved_constant_hash (void) +test_moved_constant_hash (void) { test_moved (32, constant_hash); } @@ -799,7 +798,7 @@ test_changed (hash_function *hash) { int *values, *changed_values; struct element *elements; - unsigned int permutation_cnt; + unsigned int n_permutations; int i; values = xnmalloc (cnt, sizeof *values); @@ -808,9 +807,9 @@ test_changed (hash_function *hash) for (i = 0; i < cnt; i++) values[i] = i; - for (permutation_cnt = 0; - permutation_cnt == 0 || next_permutation (values, cnt); - permutation_cnt++) + for (n_permutations = 0; + n_permutations == 0 || next_permutation (values, cnt); + n_permutations++) { for (i = 0; i < cnt; i++) { @@ -844,7 +843,7 @@ test_changed (hash_function *hash) } } } - check (permutation_cnt == factorial (cnt)); + check (n_permutations == factorial (cnt)); free (values); free (changed_values); @@ -871,7 +870,7 @@ test_changed_constant_hash (void) } static void -test_swap (int max_elems, hash_function *hash) +test_swap (int max_elems, hash_function *hash) { struct element *elements; int *values; @@ -909,7 +908,7 @@ test_swap (int max_elems, hash_function *hash) } static void -test_swap_random_hash (void) +test_swap_random_hash (void) { test_swap (128, random_hash); } @@ -955,7 +954,7 @@ test_clear (void) } static void -test_destroy_null (void) +test_destroy_null (void) { hmap_destroy (NULL); }