Exemplo n.º 1
0
    }
    print ")\n";
}
$chash = new CHash();
$chash->useExceptions(false);
// Execute tests
print "\n";
test_start('addTarget');
for ($index = 1; $index <= TARGETS; $index++) {
    test_step($chash->addTarget(sprintf('target%03d', $index)));
}
test_step($chash->getTargetsCount() == TARGETS ? 0 : -1, 'invalid targets count ' . $chash->getTargetsCount());
test_end('added ' . $chash->getTargetsCount() . ' targets');
test_start('removeTarget');
for ($index = 10; $index < 30; $index++) {
    test_step($chash->removeTarget(sprintf('target%03d', $index)));
}
test_step($chash->getTargetsCount() == TARGETS - 20 ? 0 : -1, 'invalid targets count ' . $chash->getTargetsCount());
test_end('targets count is now ' . $chash->getTargetsCount());
test_start('clearTargets');
test_step($chash->clearTargets(), 'targets count is still ' . $chash->getTargetsCount());
test_end('');
test_start('setTargets');
$targets = array();
for ($index = 1; $index <= TARGETS; $index++) {
    $targets[sprintf('target%03d', $index)] = 1;
}
test_step(($count = $chash->setTargets($targets)) < 0 ? $count : 0);
test_end('set ' . $count . ' targets');
test_start('serialize');
test_step(($serialized1 = $chash->serialize()) == '' ? -1 : 0);