Hydra::Math: add an exponential_backoff function

This commit is contained in:
Graham Christensen
2021-08-26 12:54:38 -04:00
parent 29738364fb
commit 42c2d2f387
2 changed files with 49 additions and 0 deletions

19
t/Math.t Normal file
View File

@ -0,0 +1,19 @@
use strict;
use warnings;
use Setup;
use Hydra::Math qw(exponential_backoff);
use Test2::V0;
subtest "exponential_backoff" => sub {
is(exponential_backoff(0), 1);
is(exponential_backoff(1), 2);
is(exponential_backoff(2), 4);
is(exponential_backoff(9), 512);
is(exponential_backoff(10), 1024);
is(exponential_backoff(11), 1024, "we're clamped to 1024 seconds");
is(exponential_backoff(11000), 1024, "we're clamped to 1024 seconds");
};
done_testing;