Exemplo n.º 1
0
 public function testSetAttempts()
 {
     $hashcash = new Hashcash();
     $this->assertEquals(0, $hashcash->getAttempts());
     $hashcash->setAttempts(10);
     $this->assertEquals(10, $hashcash->getAttempts());
 }
Exemplo n.º 2
0
print 'signal setup: ' . ($sig ? 'ok' : 'failed') . "\n";
fwrite(STDOUT, 'bits: ' . BITS . "\n");
fwrite(STDOUT, 'tests: ' . TESTS . "\n");
$diffMin = TIME_MAX;
$diffMax = 0;
for ($testno = 1; $testno <= TESTS && !$exit; $testno++) {
    $hashcash = new Hashcash(BITS, '*****@*****.**');
    $stamp = '';
    $start = time();
    fwrite(STDOUT, 'mint ' . $testno . '/' . TESTS . ': ');
    pcntl_alarm(TIME_MAX);
    $stamp = $hashcash->mint();
    pcntl_alarm(null);
    $diff = time() - $start;
    if ($diff > $diffMax) {
        $diffMax = $diff;
    }
    if ($diff < $diffMin) {
        $diffMin = $diff;
    }
    fwrite(STDOUT, $diff . ' sec "' . $stamp . '"   ' . $hashcash->getAttempts() . "\n");
    $times[] = $diff;
    if (!$stamp) {
        break;
    }
}
fwrite(STDOUT, 'bits: ' . BITS . "\n");
fwrite(STDOUT, 'tests: ' . TESTS . "\n");
fwrite(STDOUT, 'min: ' . $diffMin . ' seconds' . "\n");
fwrite(STDOUT, 'max: ' . $diffMax . ' seconds' . "\n");
fwrite(STDOUT, 'avg: ' . array_sum($times) / TESTS . ' seconds' . "\n");