/[ascend]/trunk/base/generic/general/test/test_hashpjw.c
ViewVC logotype

Contents of /trunk/base/generic/general/test/test_hashpjw.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1243 - (show annotations) (download) (as text)
Fri Jan 26 12:35:17 2007 UTC (15 years, 5 months ago) by johnpye
File MIME type: text/x-csrc
File size: 3918 byte(s)
Removed header files from test_general. We can do without them.
1 /*
2 * Unit test functions for ASCEND: general/hashpjw.c
3 *
4 * Copyright (C) 2005 Jerry St.Clair
5 *
6 * This file is part of the Ascend Environment.
7 *
8 * The Ascend Environment is free software; you can redistribute it
9 * and/or modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of the
11 * License, or (at your option) any later version.
12 *
13 * The Ascend Environment is distributed in hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with the program; if not, write to the Free Software Foundation,
20 * Inc., 675 Mass Ave, Cambridge, MA 02139 USA. Check the file named
21 * COPYING.
22 */
23
24 #include <utilities/ascConfig.h>
25 #include <utilities/ascMalloc.h>
26 #include <general/hashpjw.h>
27 #include "CUnit/CUnit.h"
28 #include "assertimpl.h"
29
30 static void test_hashpjw(void)
31 {
32 unsigned long hash1;
33 unsigned long hash2;
34
35 unsigned long prior_meminuse;
36
37 prior_meminuse = ascmeminuse();
38
39 /* test hashpjw */
40
41 #ifndef ASC_NO_ASSERTIONS
42 asc_assert_catch(TRUE); /* prepare to test assertions */
43
44 asc_assert_reset();
45 if (0 == setjmp(g_asc_test_env))
46 hash1 = hashpjw(NULL, 1); /* error - str NULL */
47 CU_TEST(TRUE == asc_assert_failed());
48
49 asc_assert_reset();
50 if (0 == setjmp(g_asc_test_env))
51 hash1 = hashpjw("string", 0); /* error - size == 0 */
52 CU_TEST(TRUE == asc_assert_failed());
53
54 asc_assert_catch(FALSE); /* done testing assertions */
55 #endif /* !ASC_NO_ASSERTIONS */
56
57 hash1 = hashpjw("", 1); /* empty string, minimum size */
58 CU_TEST(1 > hash1);
59
60 hash1 = hashpjw("", 500); /* empty string */
61 CU_TEST(500 > hash1);
62
63 hash1 = hashpjw("string1", 500); /* regular string */
64 hash2 = hashpjw("string1", 500);
65 CU_TEST(500 > hash1);
66 CU_TEST(500 > hash2);
67 CU_TEST(hash1 == hash2);
68
69 hash2 = hashpjw("string1", 10);
70
71 CU_TEST(10 > hash2);
72 CU_TEST(hash1 != hash2);
73
74 hash2 = hashpjw("string2", 500);
75
76 CU_TEST(500 > hash2);
77 CU_TEST(hash1 != hash2);
78
79 hash2 = hashpjw("string2", 1);
80
81 CU_TEST(1 > hash2);
82 CU_TEST(hash1 != hash2);
83
84 /* test hashpjw_int */
85
86 #ifndef ASC_NO_ASSERTIONS
87 asc_assert_catch(TRUE); /* prepare to test assertions */
88
89 asc_assert_reset();
90 if (0 == setjmp(g_asc_test_env))
91 hash1 = hashpjw_int(100, 0); /* error - size == 0 */
92 CU_TEST(TRUE == asc_assert_failed());
93
94 asc_assert_catch(FALSE); /* done testing assertions */
95 #endif /* !ASC_NO_ASSERTIONS */
96
97 hash1 = hashpjw_int(0, 1); /* minimum size */
98 CU_TEST(1 > hash1);
99
100 hash1 = hashpjw_int(0, 500);
101 CU_TEST(500 > hash1);
102
103 hash1 = hashpjw_int(100, 500);
104 hash2 = hashpjw_int(100, 500);
105 CU_TEST(500 > hash1);
106 CU_TEST(500 > hash2);
107 CU_TEST(hash1 == hash2);
108
109 hash2 = hashpjw_int(100, 10);
110
111 CU_TEST(10 > hash2);
112 CU_TEST(hash1 != hash2);
113
114 hash2 = hashpjw_int(-23464236, 500);
115
116 CU_TEST(500 > hash2);
117 CU_TEST(hash1 != hash2);
118
119 hash2 = hashpjw_int(-23464236, 1);
120
121 CU_TEST(1 > hash2);
122 CU_TEST(hash1 != hash2);
123
124 CU_TEST(prior_meminuse == ascmeminuse()); /* make sure we cleaned up after ourselves */
125 }
126
127 /*===========================================================================*/
128 /* Registration information */
129
130 static CU_TestInfo hashpjw_test_list[] = {
131 {"test_hashpjw", test_hashpjw},
132 CU_TEST_INFO_NULL
133 };
134
135 static CU_SuiteInfo suites[] = {
136 {"test_general_hashpjw", NULL, NULL, hashpjw_test_list},
137 CU_SUITE_INFO_NULL
138 };
139
140 /*-------------------------------------------------------------------*/
141 CU_ErrorCode test_register_general_hashpjw(void)
142 {
143 return CU_register_suites(suites);
144 }

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22