use strict; use warnings; use Math::GMPz qw(:mpz); use Test::More; my $s; # Create a string of 20000 bits for(1..20000) { $s .= int(rand(2)); } # Visually inspect the value #open (my $fh, '>', 'val.txt') or warn "Open: $!"; #print $fh $s; #close $fh; # Vectorize that string into a # Math::GMPz object my $mpz = Math::GMPz->new($s, 2); # Check that the no. of set bits is in # the range 9655..10345 cmp_ok(Math::GMPz::Rmonobit($mpz), '==', 1, 'monobit test'); # Check that the longest run of the same bit is # shorter than 34 cmp_ok(Math::GMPz::Rlong_run($mpz), '==', 1, 'long run test'); # Check that the numbers of 1-bit runs, 2-bit runs, # 3-bit runs 4-bit runs, 5-bit runs and 6-bit runs # (of both zeros and ones) meet expectations. cmp_ok(Math::GMPz::Rruns($mpz), '==', 1, 'runs test'); # Check that the no. of occurrences of the various # 4-bit sequences meets expectations. cmp_ok(Math::GMPz::Rpoker($mpz), '==', 1, 'poker test'); # Check that the number of times that # bit[pos] == bit[pos + 2] is in the # range 9655..10345. my @ret = Math::GMPz::autocorrelation($mpz, 2); cmp_ok($ret[0], '>', 9654, 'autocorrelation count > lower limit'); cmp_ok($ret[0], '<', 10346, 'autocorrelation count < upper limit'); done_testing();