xref: /PHP-5.6/ext/hash/tests/fnv164.phpt (revision d05ce257)
1--TEST--
2FNV
3--SKIPIF--
4<?php extension_loaded('hash') or die ('Skip - hash extension not available'); ?>
5--FILE--
6<?php
7
8function R10($t) {
9	return str_repeat($t, 10);
10}
11
12function R500($t) {
13	return str_repeat($t, 500);
14}
15
16$tests = array(
17	array( "", "cbf29ce484222325" ),
18	array( "a", "af63bd4c8601b7be" ),
19	array( "b", "af63bd4c8601b7bd" ),
20	array( "c", "af63bd4c8601b7bc" ),
21	array( "d", "af63bd4c8601b7bb" ),
22	array( "e", "af63bd4c8601b7ba" ),
23	array( "f", "af63bd4c8601b7b9" ),
24	array( "fo", "08326207b4eb2f34" ),
25	array( "foo", "d8cbc7186ba13533" ),
26	array( "foob", "0378817ee2ed65cb" ),
27	array( "fooba", "d329d59b9963f790" ),
28	array( "foobar", "340d8765a4dda9c2" ),
29	array( "\0", "af63bd4c8601b7df" ),
30	array( "a\0", "08326707b4eb37da" ),
31	array( "b\0", "08326607b4eb3627" ),
32	array( "c\0", "08326507b4eb3474" ),
33	array( "d\0", "08326407b4eb32c1" ),
34	array( "e\0", "08326307b4eb310e" ),
35	array( "f\0", "08326207b4eb2f5b" ),
36	array( "fo\0", "d8cbc7186ba1355c" ),
37	array( "foo\0", "0378817ee2ed65a9" ),
38	array( "foob\0", "d329d59b9963f7f1" ),
39	array( "fooba\0", "340d8765a4dda9b0" ),
40	array( "foobar\0", "50a6d3b724a774a6" ),
41	array( "ch", "08326507b4eb341c" ),
42	array( "cho", "d8d5c8186ba98bfb" ),
43	array( "chon", "1ccefc7ef118dbef" ),
44	array( "chong", "0c92fab3ad3db77a" ),
45	array( "chongo", "9b77794f5fdec421" ),
46	array( "chongo ", "0ac742dfe7874433" ),
47	array( "chongo w", "d7dad5766ad8e2de" ),
48	array( "chongo wa", "a1bb96378e897f5b" ),
49	array( "chongo was", "5b3f9b6733a367d2" ),
50	array( "chongo was ", "b07ce25cbea969f6" ),
51	array( "chongo was h", "8d9e9997f9df0d6a" ),
52	array( "chongo was he", "838c673d9603cb7b" ),
53	array( "chongo was her", "8b5ee8a5e872c273" ),
54	array( "chongo was here", "4507c4e9fb00690c" ),
55	array( "chongo was here!", "4c9ca59581b27f45" ),
56	array( "chongo was here!\n", "e0aca20b624e4235" ),
57	array( "ch\0", "d8d5c8186ba98b94" ),
58	array( "cho\0", "1ccefc7ef118db81" ),
59	array( "chon\0", "0c92fab3ad3db71d" ),
60	array( "chong\0", "9b77794f5fdec44e" ),
61	array( "chongo\0", "0ac742dfe7874413" ),
62	array( "chongo \0", "d7dad5766ad8e2a9" ),
63	array( "chongo w\0", "a1bb96378e897f3a" ),
64	array( "chongo wa\0", "5b3f9b6733a367a1" ),
65	array( "chongo was\0", "b07ce25cbea969d6" ),
66	array( "chongo was \0", "8d9e9997f9df0d02" ),
67	array( "chongo was h\0", "838c673d9603cb1e" ),
68	array( "chongo was he\0", "8b5ee8a5e872c201" ),
69	array( "chongo was her\0", "4507c4e9fb006969" ),
70	array( "chongo was here\0", "4c9ca59581b27f64" ),
71	array( "chongo was here!\0", "e0aca20b624e423f" ),
72	array( "chongo was here!\n\0", "13998e580afa800f" ),
73	array( "cu", "08326507b4eb3401" ),
74	array( "cur", "d8d5ad186ba95dc1" ),
75	array( "curd", "1c72e17ef0ca4e97" ),
76	array( "curds", "2183c1b327c38ae6" ),
77	array( "curds ", "b66d096c914504f2" ),
78	array( "curds a", "404bf57ad8476757" ),
79	array( "curds an", "887976bd815498bb" ),
80	array( "curds and", "3afd7f02c2bf85a5" ),
81	array( "curds and ", "fc4476b0eb70177f" ),
82	array( "curds and w", "186d2da00f77ecba" ),
83	array( "curds and wh", "f97140fa48c74066" ),
84	array( "curds and whe", "a2b1cf49aa926d37" ),
85	array( "curds and whey", "0690712cd6cf940c" ),
86	array( "curds and whey\n", "f7045b3102b8906e" ),
87	array( "cu\0", "d8d5ad186ba95db3" ),
88	array( "cur\0", "1c72e17ef0ca4ef3" ),
89	array( "curd\0", "2183c1b327c38a95" ),
90	array( "curds\0", "b66d096c914504d2" ),
91	array( "curds \0", "404bf57ad8476736" ),
92	array( "curds a\0", "887976bd815498d5" ),
93	array( "curds an\0", "3afd7f02c2bf85c1" ),
94	array( "curds and\0", "fc4476b0eb70175f" ),
95	array( "curds and \0", "186d2da00f77eccd" ),
96	array( "curds and w\0", "f97140fa48c7400e" ),
97	array( "curds and wh\0", "a2b1cf49aa926d52" ),
98	array( "curds and whe\0", "0690712cd6cf9475" ),
99	array( "curds and whey\0", "f7045b3102b89064" ),
100	array( "curds and whey\n\0", "74f762479f9d6aea" ),
101	array( "line 1\nline 2\nline 3", "a64e5f36c9e2b0e3" ),
102	array( "chongo <Landon Curt Noll> /\\../\\", "8fd0680da3088a04" ),
103	array( "chongo <Landon Curt Noll> /\\../\\\0", "67aad32c078284cc" ),
104	array( "chongo (Landon Curt Noll) /\\../\\", "b37d55d81c57b331" ),
105	array( "chongo (Landon Curt Noll) /\\../\\\0", "55ac0f3829057c43" ),
106	array( "http://antwrp.gsfc.nasa.gov/apod/astropix.html", "cb27f4b8e1b6cc20" ),
107	array( "http://en.wikipedia.org/wiki/Fowler_Noll_Vo_hash", "26caf88bcbef2d19" ),
108	array( "http://epod.usra.edu/", "8e6e063b97e61b8f" ),
109	array( "http://exoplanet.eu/", "b42750f7f3b7c37e" ),
110	array( "http://hvo.wr.usgs.gov/cam3/", "f3c6ba64cf7ca99b" ),
111	array( "http://hvo.wr.usgs.gov/cams/HMcam/", "ebfb69b427ea80fe" ),
112	array( "http://hvo.wr.usgs.gov/kilauea/update/deformation.html", "39b50c3ed970f46c" ),
113	array( "http://hvo.wr.usgs.gov/kilauea/update/images.html", "5b9b177aa3eb3e8a" ),
114	array( "http://hvo.wr.usgs.gov/kilauea/update/maps.html", "6510063ecf4ec903" ),
115	array( "http://hvo.wr.usgs.gov/volcanowatch/current_issue.html", "2b3bbd2c00797c7a" ),
116	array( "http://neo.jpl.nasa.gov/risk/", "f1d6204ff5cb4aa7" ),
117	array( "http://norvig.com/21-days.html", "4836e27ccf099f38" ),
118	array( "http://primes.utm.edu/curios/home.php", "82efbb0dd073b44d" ),
119	array( "http://slashdot.org/", "4a80c282ffd7d4c6" ),
120	array( "http://tux.wr.usgs.gov/Maps/155.25-19.5.html", "305d1a9c9ee43bdf" ),
121	array( "http://volcano.wr.usgs.gov/kilaueastatus.php", "15c366948ffc6997" ),
122	array( "http://www.avo.alaska.edu/activity/Redoubt.php", "80153ae218916e7b" ),
123	array( "http://www.dilbert.com/fast/", "fa23e2bdf9e2a9e1" ),
124	array( "http://www.fourmilab.ch/gravitation/orbits/", "d47e8d8a2333c6de" ),
125	array( "http://www.fpoa.net/", "7e128095f688b056" ),
126	array( "http://www.ioccc.org/index.html", "2f5356890efcedab" ),
127	array( "http://www.isthe.com/cgi-bin/number.cgi", "95c2b383014f55c5" ),
128	array( "http://www.isthe.com/chongo/bio.html", "4727a5339ce6070f" ),
129	array( "http://www.isthe.com/chongo/index.html", "b0555ecd575108e9" ),
130	array( "http://www.isthe.com/chongo/src/calc/lucas-calc", "48d785770bb4af37" ),
131	array( "http://www.isthe.com/chongo/tech/astro/venus2004.html", "09d4701c12af02b1" ),
132	array( "http://www.isthe.com/chongo/tech/astro/vita.html", "79f031e78f3cf62e" ),
133	array( "http://www.isthe.com/chongo/tech/comp/c/expert.html", "52a1ee85db1b5a94" ),
134	array( "http://www.isthe.com/chongo/tech/comp/calc/index.html", "6bd95b2eb37fa6b8" ),
135	array( "http://www.isthe.com/chongo/tech/comp/fnv/index.html", "74971b7077aef85d" ),
136	array( "http://www.isthe.com/chongo/tech/math/number/howhigh.html", "b4e4fae2ffcc1aad" ),
137	array( "http://www.isthe.com/chongo/tech/math/number/number.html", "2bd48bd898b8f63a" ),
138	array( "http://www.isthe.com/chongo/tech/math/prime/mersenne.html", "e9966ac1556257f6" ),
139	array( "http://www.isthe.com/chongo/tech/math/prime/mersenne.html#largest", "92a3d1cd078ba293" ),
140	array( "http://www.lavarnd.org/cgi-bin/corpspeak.cgi", "f81175a482e20ab8" ),
141	array( "http://www.lavarnd.org/cgi-bin/haiku.cgi", "5bbb3de722e73048" ),
142	array( "http://www.lavarnd.org/cgi-bin/rand-none.cgi", "6b4f363492b9f2be" ),
143	array( "http://www.lavarnd.org/cgi-bin/randdist.cgi", "c2d559df73d59875" ),
144	array( "http://www.lavarnd.org/index.html", "f75f62284bc7a8c2" ),
145	array( "http://www.lavarnd.org/what/nist-test.html", "da8dd8e116a9f1cc" ),
146	array( "http://www.macosxhints.com/", "bdc1e6ab76057885" ),
147	array( "http://www.mellis.com/", "fec6a4238a1224a0" ),
148	array( "http://www.nature.nps.gov/air/webcams/parks/havoso2alert/havoalert.cfm", "c03f40f3223e290e" ),
149	array( "http://www.nature.nps.gov/air/webcams/parks/havoso2alert/timelines_24.cfm", "1ed21673466ffda9" ),
150	array( "http://www.paulnoll.com/", "df70f906bb0dd2af" ),
151	array( "http://www.pepysdiary.com/", "f3dcda369f2af666" ),
152	array( "http://www.sciencenews.org/index/home/activity/view", "9ebb11573cdcebde" ),
153	array( "http://www.skyandtelescope.com/", "81c72d9077fedca0" ),
154	array( "http://www.sput.nl/~rob/sirius.html", "0ec074a31be5fb15" ),
155	array( "http://www.systemexperts.com/", "2a8b3280b6c48f20" ),
156	array( "http://www.tq-international.com/phpBB3/index.php", "fd31777513309344" ),
157	array( "http://www.travelquesttours.com/index.htm", "194534a86ad006b6" ),
158	array( "http://www.wunderground.com/global/stations/89606.html", "3be6fdf46e0cfe12" ),
159	array( R10("21701"), "017cc137a07eb057" ),
160	array( R10("M21701"), "9428fc6e7d26b54d" ),
161	array( R10("2^21701-1"), "9aaa2e3603ef8ad7" ),
162	array( R10("\x54\xc5"), "82c6d3f3a0ccdf7d" ),
163	array( R10("\xc5\x54"), "c86eeea00cf09b65" ),
164	array( R10("23209"), "705f8189dbb58299" ),
165	array( R10("M23209"), "415a7f554391ca69" ),
166	array( R10("2^23209-1"), "cfe3d49fa2bdc555" ),
167	array( R10("\x5a\xa9"), "f0f9c56039b25191" ),
168	array( R10("\xa9\x5a"), "7075cb6abd1d32d9" ),
169	array( R10("391581216093"), "43c94e2c8b277509" ),
170	array( R10("391581*2^216093-1"), "3cbfd4e4ea670359" ),
171	array( R10("\x05\xf9\x9d\x03\x4c\x81"), "c05887810f4d019d" ),
172	array( R10("FEDCBA9876543210"), "14468ff93ac22dc5" ),
173	array( R10("\xfe\xdc\xba\x98\x76\x54\x32\x10"), "ebed699589d99c05" ),
174	array( R10("EFCDAB8967452301"), "6d99f6df321ca5d5" ),
175	array( R10("\xef\xcd\xab\x89\x67\x45\x23\x01"), "0cd410d08c36d625" ),
176	array( R10("0123456789ABCDEF"), "ef1b2a2c86831d35" ),
177	array( R10("\x01\x23\x45\x67\x89\xab\xcd\xef"), "3b349c4d69ee5f05" ),
178	array( R10("1032547698BADCFE"), "55248ce88f45f035" ),
179	array( R10("\x10\x32\x54\x76\x98\xba\xdc\xfe"), "aa69ca6a18a4c885" ),
180	array( R500("\x00"), "1fe3fce62bd816b5" ),
181	array( R500("\x07"), "0289a488a8df69d9" ),
182	array( R500("~"), "15e96e1613df98b5" ),
183	array( R500("\x7f"), "e6be57375ad89b99" ),
184);
185
186$i = 0;
187$pass = true;
188foreach($tests as $test) {
189	$result = hash('fnv164', $test[0]);
190	if ($result != $test[1]) {
191		echo "Iteration " . $i . " failed - expected '" . $test[1] . "', got '" . $result . "' for '" . $test[1] . "'\n";
192        $pass = false;
193	}
194	$i++;
195}
196
197if($pass) {
198    echo "PASS";
199}
200?>
201--EXPECT--
202PASS
203