X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=tests%2Flibpspp%2Fllx-test.c;h=f8fe9b73618578f50f8dad56f18a3c261122b3f3;hb=373dbe766c1914b5b0d42c9d3012a28ffcb24a53;hp=7c8d41be44e6c0415aac5d4960e4357390083809;hpb=f5c108becd49d78f4898cab11352291f5689d24e;p=pspp-builds.git diff --git a/tests/libpspp/llx-test.c b/tests/libpspp/llx-test.c index 7c8d41be..f8fe9b73 100644 --- a/tests/libpspp/llx-test.c +++ b/tests/libpspp/llx-test.c @@ -1,20 +1,18 @@ -/* PSPP - computes sample statistics. - Copyright (C) 2006 Free Software Foundation, Inc. +/* PSPP - a program for statistical analysis. + Copyright (C) 2006, 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 the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. + 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. */ + along with this program. If not, see . */ /* This is a test program for the llx_* routines defined in ll.c. This test program aims to be as comprehensive as @@ -867,6 +865,34 @@ test_find_equal (void) test_examine_equal_range (test_find_equal_helper); } +/* Tests llx_find(). */ +static void +test_find (void) +{ + const int max_elems = 8; + + int cnt; + + for (cnt = 0; cnt <= max_elems; cnt++) + { + struct llx_list list; + struct element **elems; + struct llx **elemp; + int *values; + + int i; + + allocate_ascending (cnt, &list, &elems, &elemp, &values); + + for (i = 0; i < cnt; i++) + check (llx_find (llx_head (&list), llx_null (&list), elems[i]) + == elemp[i]); + check (llx_find (llx_head (&list), llx_null (&list), NULL) == NULL); + + free_elements (cnt, &list, elems, elemp, values); + } +} + /* Helper function for testing llx_find_if. */ static void test_find_if_helper (int r0, int r1, int eq_pat, struct llx **elemp) @@ -2042,6 +2068,7 @@ main (void) run_test (test_remove_equal, "remove_equal"); run_test (test_remove_if, "remove_if"); run_test (test_find_equal, "find_equal"); + run_test (test_find, "find"); run_test (test_find_if, "find_if"); run_test (test_find_adjacent_equal, "find_adjacent_equal"); run_test (test_count_range, "count_range");