示例#1
0
文件: chash_test.php 项目: EQ4/chash
test_step(($count = $chash->unserialize($serialized1)) < 0 ? $count : 0);
test_end('continuum count is ' . $count);
test_start('serialize coherency');
test_step(($serialized2 = $chash->serialize()) == '' ? -1 : 0);
test_step($serialized1 != $serialized2 ? -1 : 0);
test_end('');
test_start('serializeToFile');
@unlink(SERIALIZEPATH);
test_step(($size1 = $chash->serializeToFile(SERIALIZEPATH)) < 0 ? $size1 : 0);
test_end('serialized size is ' . $size1 . ' bytes');
$chash = new CHash();
test_start('unserializeFromFile');
test_step(($count = $chash->unserializeFromFile(SERIALIZEPATH)) < 0 ? $count : 0);
test_end('continuum count is ' . $count);
test_start('file serialize coherency');
test_step(($serialized2 = $chash->serialize()) == '' ? -1 : 0);
test_step($serialized1 != $serialized2 ? -1 : 0);
test_end('');
test_start('lookupList');
$lookups = array();
for ($index = 0; $index < CANDIDATES; $index++) {
    $targets = $chash->lookupList(sprintf('candidate%07d', $index));
    test_step(count($targets) != 1 ? -1 : 0);
    @$lookups[$targets[0]]++;
}
$mean = 0;
$deviation = 0;
foreach ($lookups as $value) {
    $mean += $value;
}
$mean = $mean / count($lookups);