Commit 1c2cfdcd8efd4406207ecdbde2e69a10b2dfeaa7
1 parent
2d4a47af
Test for the on-disk-hashing storage manager's hashing algorithm.
git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@5224 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
1 changed file
with
36 additions
and
0 deletions
tests/storage/testHash.php
0 → 100644
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +$aExpectedResults = array( | ||
| 4 | + 1 => '00/1', | ||
| 5 | + 600 => '06/600', | ||
| 6 | + 2300 => '23/2300', | ||
| 7 | + 12300 => '01/23/12300', | ||
| 8 | +); | ||
| 9 | + | ||
| 10 | +function blah($iId) { | ||
| 11 | + $str = (string)$iId; | ||
| 12 | + if (strlen($str) < 4) { | ||
| 13 | + $str = sprintf('%s%s', str_repeat('0', 4 - strlen($str)), $str); | ||
| 14 | + } | ||
| 15 | + if (strlen($str) % 2 == 1) { | ||
| 16 | + $str = sprintf('0%s', $str); | ||
| 17 | + } | ||
| 18 | + | ||
| 19 | + $str = substr($str, 0, -2); | ||
| 20 | + | ||
| 21 | + return sprintf("%s/%d", preg_replace('#(\d\d)(\d\d)#', '\1/\2', $str), $iId); | ||
| 22 | +} | ||
| 23 | + | ||
| 24 | +foreach ($aExpectedResults as $iInput => $sWanted) { | ||
| 25 | + $sResult = blah($iInput); | ||
| 26 | + if ($sResult !== $sWanted) { | ||
| 27 | + print "Expected result was $sWanted, but got $sResult for $iInput\n"; | ||
| 28 | + } | ||
| 29 | +} | ||
| 30 | + | ||
| 31 | + | ||
| 32 | +$aResults = array(); | ||
| 33 | +for ($c = 0; $c < 1000000; $c++) { | ||
| 34 | + $sResult = blah($c); | ||
| 35 | + print $sResult . "\n"; | ||
| 36 | +} |