X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=tests%2Flibpspp%2Fhmapx-test.c;h=18b7aad9d6cc5fd3f0f56dd949e8b1d9e3d95e8b;hb=6b3d097998657df76b4cb67bce8fd3a0549c434a;hp=fc08ca6161040a89d1c54574cb6f6ec2866886fb;hpb=a1efcf97ca2f75f4be6a0389ff2372c03ed2d4e1;p=pspp diff --git a/tests/libpspp/hmapx-test.c b/tests/libpspp/hmapx-test.c index fc08ca6161..18b7aad9d6 100644 --- a/tests/libpspp/hmapx-test.c +++ b/tests/libpspp/hmapx-test.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 2007, 2008 Free Software Foundation, Inc. + Copyright (C) 2007, 2008, 2009, 2010 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -262,6 +262,7 @@ check_hmapx (struct hmapx *hmapx, const int data[], size_t cnt, size_t i, j; int *order; + check (hmapx_is_empty (hmapx) == (cnt == 0)); check (hmapx_count (hmapx) == cnt); check (cnt <= hmapx_capacity (hmapx)); @@ -934,6 +935,44 @@ test_swap_random_hash (void) test_swap (128, random_hash); } +/* Inserts elements into an HMAPX in ascending order, then clears the hash + table using hmapx_clear(). */ +static void +test_clear (void) +{ + const int max_elems = 128; + struct element *elements; + struct hmapx_node **nodes; + int *values; + struct hmapx hmapx; + int cnt; + + elements = xnmalloc (max_elems, sizeof *elements); + nodes = xnmalloc (max_elems, sizeof *nodes); + values = xnmalloc (max_elems, sizeof *values); + + hmapx_init (&hmapx); + for (cnt = 0; cnt <= max_elems; cnt++) + { + int i; + + for (i = 0; i < cnt; i++) + { + values[i] = elements[i].data = i; + nodes[i] = hmapx_insert (&hmapx, &elements[i], + random_hash (elements[i].data)); + check_hmapx (&hmapx, values, i + 1, random_hash); + } + hmapx_clear (&hmapx); + check_hmapx (&hmapx, NULL, 0, random_hash); + } + hmapx_destroy (&hmapx); + + free (elements); + free (nodes); + free (values); +} + static void test_destroy_null (void) { @@ -1025,6 +1064,8 @@ main (void) run_test (test_swap_random_hash, "test swapping tables"); + run_test (test_clear, "test clearing hash table"); + run_test (test_destroy_null, "test destroying null table"); run_test (test_shrink_empty, "test shrinking an empty table");