From 1c2cfdcd8efd4406207ecdbde2e69a10b2dfeaa7 Mon Sep 17 00:00:00 2001 From: nbm Date: Mon, 10 Apr 2006 09:15:36 +0000 Subject: [PATCH] Test for the on-disk-hashing storage manager's hashing algorithm. --- tests/storage/testHash.php | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+), 0 deletions(-) create mode 100644 tests/storage/testHash.php diff --git a/tests/storage/testHash.php b/tests/storage/testHash.php new file mode 100644 index 0000000..c3387d2 --- /dev/null +++ b/tests/storage/testHash.php @@ -0,0 +1,36 @@ + '00/1', + 600 => '06/600', + 2300 => '23/2300', + 12300 => '01/23/12300', +); + +function blah($iId) { + $str = (string)$iId; + if (strlen($str) < 4) { + $str = sprintf('%s%s', str_repeat('0', 4 - strlen($str)), $str); + } + if (strlen($str) % 2 == 1) { + $str = sprintf('0%s', $str); + } + + $str = substr($str, 0, -2); + + return sprintf("%s/%d", preg_replace('#(\d\d)(\d\d)#', '\1/\2', $str), $iId); +} + +foreach ($aExpectedResults as $iInput => $sWanted) { + $sResult = blah($iInput); + if ($sResult !== $sWanted) { + print "Expected result was $sWanted, but got $sResult for $iInput\n"; + } +} + + +$aResults = array(); +for ($c = 0; $c < 1000000; $c++) { + $sResult = blah($c); + print $sResult . "\n"; +} -- libgit2 0.21.4