view release on metacpan or search on metacpan
t/02_general.t view on Meta::CPAN
# make test
# perl Makefile.PL && make && perl -Iblib/lib t/02_general.t
use lib '.'; BEGIN{require 't/common.pl'}
use Test::More tests => 204;
use Digest::MD5 qw(md5_hex);
my @empty;
#-- min, max
ok(min(1,2,3,undef,4)==1, 'min');
ok(max(undef,1,4,3,4)==4, 'max');
ok(not defined min());
ok(not defined max());
ok(not defined min(@empty));
t/03_bloomfilter.t view on Meta::CPAN
# perl Makefile.PL;make;perl -Iblib/lib t/3_bloomfilter.t
# perl Makefile.PL;make;ATDEBUG=1 perl -Iblib/lib t/3_bloomfilter.t
# time ( perl Makefile.PL;make;ATDEBUG=1 perl -Iblib/lib t/03_bloomfilter.t )
# perl Makefile.PL;make;perl -Iblib/lib t/03_bloomfilter.t
use lib '.'; BEGIN{require 't/common.pl'}
use Test::More tests => 28;
my $error_rate=0.02;
my $capacity=10000;
my $bf=bfinit($error_rate, $capacity);
my $t=time_fp();
bfadd($bf, map $_*2,0..$capacity-1);
#deb "Adds pr sec: ".int($capacity/(time_fp()-$t))."\n";
#bfadd($bf, $_) for map $_*2,0..$capacity-1;
t/04_resolve.t view on Meta::CPAN
# perl Makefile.PL && make && perl -Iblib/lib t/04_resolve.t
use lib '.'; BEGIN{require 't/common.pl'}
use Test::More tests => 17;
if($ENV{ATDEBUG}){
deb "Resolve: ".resolve(sub{my($x)=(@_); $x**2 - 4*$x -1},20,2)."\n";
deb "Resolve: ".resolve(sub{my($x)=@_; $x**log($x)-$x},0,3)."\n";
deb "Resolve: ".resolve(sub{$_[0]})." iters=$Acme::Tools::Resolve_iterations\n";
}
my $e;
ok(resolve(sub{my($x)=@_; $x**2 - 4*$x -21}) == -3 ,'first solution');
t/05_distance.t view on Meta::CPAN
#perl Makefile.PL;make;perl -Iblib/lib t/05_distance.t
use lib '.'; BEGIN{require 't/common.pl'}
use Test::More tests => 4;
#--oslo-rio = 10434.047 meter iflg http://www.daftlogic.com/projects-google-maps-distance-calculator.htm
my @oslo=(59.933983, 10.756037);
my @rio=(-22.97673,-43.19508);
my @london=(51.507726,-0.128079); #1156
my @jakarta=(-6.175381,106.828176); # 10936
my @test=( ['@oslo,@rio', 10431.5],
['@rio, @oslo', 10431.5],
['@oslo,@london', 1153.6],
t/06_conv.t view on Meta::CPAN
#perl Makefile.PL;make;perl -Iblib/lib t/06_conv.t
#perl -I/ext t/06_conv.t
use lib '.'; BEGIN{require 't/common.pl'}
use Test::More tests => 42;
sub check {
my($n, $from, $to, $answer) = @_;
my $c=conv( $n, $from => $to );
my $eq=sub{$_[0]=~/\d/?($_[0]==$_[1]||abs(1-$_[0]/$_[1])<1e-6):($_[0] eq $_[1])};
$answer=&$answer if ref($answer);
ok( &$eq($c,$answer), sprintf('%9s %-14s => %20s %-14s correct: %20s %s',$n,$from,$c,$to,$answer,$to) );
}
#perl Makefile.PL;make;perl -Iblib/lib t/07_big.t
use lib '.'; BEGIN{require 't/common.pl'}
BEGIN{our $T=15}
use Test::More tests => $T;
eval{big(1)};
exit if $@ and print "<<$@>>\n" and map ok(1),1..$T; #Math::BigInt or Math::BigFloat is missing
my $num1 = big(3); #returns a new Math::BigInt-object
my $num2 = big('3.0'); #returns a new Math::BigFloat-object
my $num3 = big(3.0); #returns a new Math::BigInt-object
my $num4 = big(3.1); #returns a new Math::BigFloat-object
my $num5 = big('2/7'); #returns a new Math::BigRat-object
#perl Makefile.PL;make;perl -Iblib/lib t/08_eta.t
use lib '.'; BEGIN{require 't/common.pl'}
use Test::More tests => 6;
eta(1,100);
#warn serialize(\%Acme::Tools::Eta,'Eta','',1);
my $k=(keys%Acme::Tools::Eta)[0];
ok( @{$Acme::Tools::Eta{$k}}==1, 'ok aref');
ok(!defined eta("x",6,10,70) ,'!def');
ok( eta("x",8,10,80) == 90 ,'ok 90');
ok( eta("x",8,10,80) == 90 ,'ok 90');
ok( @{$Acme::Tools::Eta{'x'}} == 2 ,'ok len' );
t/09_rank_pushsort_binsearch.t view on Meta::CPAN
#perl Makefile.PL;make; perl -Iblib/lib t/09_rank_pushsort_binsearch.t
#perl Makefile.PL;make;ATDEBUG=1 perl -Iblib/lib t/09_rank_pushsort_binsearch.t
use lib '.'; BEGIN{require 't/common.pl'}
use Test::More tests => 62;
my @a=(1,10,20,50,70,90,120,130);
testsearch(1,@a);
@a=(1..20); testsearch(1,@a);
@a=(1..1000); testsearch(0,@a);
@a=(1..2000); testsearch(0,@a);
@a=(1..4000); testsearch(0,@a);
#@a=(1..8000); testsearch(0,@a);
t/10_md5sum.t view on Meta::CPAN
# perl Makefile.PL;make;perl -Iblib/lib t/10_md5sum.t
use lib '.'; BEGIN{require 't/common.pl'}
use Test::More tests => 4;
my $s=join"",1..1e4;
is( md5sum(\"abc"), '900150983cd24fb0d6963f7d28e17f72', 'stringref');
is( md5sum(\$s), '6784cd80458707896e40532a50f69b82', 'stringref longer');
my $tmp=tmp();
if(-d$tmp and -w$tmp){
writefile("$tmp/attest-md5sum","asdf\cJ");
my$m;ok(($m=md5sum("$tmp/attest-md5sum")) eq '2b00042f7481c7b056c4b410d28f33cf', "md5 $m");
eval{md5sum($tmp)};
t/11_part.t view on Meta::CPAN
# perl Makefile.PL;make;perl -Iblib/lib t/11_part.t
use lib '.'; BEGIN{require 't/common.pl'}
use Test::More tests => 8;
my( $odd, $even ) = part {$_%2} 1..8;
ok_ref($odd, [1,3,5,7],'odd');
ok_ref($even,[2,4,6,8],'even');
my @words=qw/These are the words of this array/;
my %h=parth { uc(substr($_,0,1)) } @words;
#warn serialize(\%h);
t/12_ht2t.t view on Meta::CPAN
# perl Makefile.PL;make;perl -Iblib/lib t/12_ht2t.t
use lib '.'; BEGIN{require 't/common.pl'}
use Test::More tests => 5;
my $html=join"",<DATA>;
my %ent=(amp => '&', 160 => ' ');
my $entqr=join"|",keys%ent;
#$html=~s,&#?($entqr);,$ent{$1},g;
my @t0=ht2t($html);
my @t1=ht2t($html,"Tab"); #die serialize(\@t1,'t1','',1);
my @t2=ht2t($html,"Table-2");
#my @k=ht2t($html,"Oslo fylke");#print serialize(\@k,'k','',1);
my $aa;
t/13_random.t view on Meta::CPAN
# make test
# perl Makefile.PL; make; perl -Iblib/lib t/13_random.t
use lib '.'; BEGIN{require 't/common.pl'}
use Test::More tests => 18;
#--random, mix
for( #|hmm|#
[ sub{random([1..5])}, 2000, 1.0, 1.5, 5],
[ sub{random(["head","tail"])},1000, 1.0, 1.5, 2],
[ sub{random(1,6)}, 1000, 1.0, 1.9, 6],
[ sub{random(2)}, 1000, 1.0, 1.4, 3],
[ sub{join(",",mix(1..4))}, 1000, 1.0, 6.0, 4*3*2*1],
[ sub{random({head=>0.48,tail=>0.48,edge=>0.04})}, 2000, 12-4,12+8, 3],
t/14_brainfu.t view on Meta::CPAN
# make test
# perl Makefile.PL; make; perl -Iblib/lib t/14_brainfu.t
use lib '.'; BEGIN{require 't/common.pl'}
use Test::More tests => 3;
my @test=(
'>++++++++[<++++++++>-]<++++++++.>++++++[<++++++>-]<---.',
'Hi',
'++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>-.>---..++++++.++++++>>.<<--.
----.+++++++++.>><<-----.>++++++++++.+++.<+++.>>.++++++++++++++++++.--.+.+++.,.,.,.',
'Geek oktober 2014xyz',
# make test
# perl Makefile.PL; make; perl -Iblib/lib t/15_zip.t
use lib '.'; BEGIN{require 't/common.pl'}
use Test::More tests => 19;
eval{ require Compress::Zlib }; if($@){ ok(1) for 1..19; exit }
#--zip
ok_ref( [zip([1,3,5])], [1,3,5], 'zip 1' );
ok_ref( [zip([1,3,5],[2,4,6])], [1..6], 'zip 2' );
ok_ref( [zip([1,4,7],[2,5,8],[3,6,9])], [1..9], 'zip 3' );
sub ziperr{eval{zip(@_)};$@=~/ERROR.*zip/}
ok( ziperr([1,2],[3,4],5), 'zip err 1');
ok( ziperr([1,2],[3,4,5]), 'zip err 2');
t/16_fractional.t view on Meta::CPAN
# make test
# perl Makefile.PL; make; perl -Iblib/lib t/16_fractional.t
use lib '.'; BEGIN{require 't/common.pl'}
use Test::More tests => 1;
ok(1); #NOT FINISHED
exit;
#my $n=2135.135135135135135135;
#my $n=0.725234234234*100000000;
#my $n=12/7;
#my $n=big(13)/(2*2*2*2*3*3*7);
#my $n=0.15/(2*2*2*3*3*7);
t/17_roman.t view on Meta::CPAN
# make test
# perl Makefile.PL; make; perl -Iblib/lib t/17_roman.t
use lib '.'; BEGIN{require 't/common.pl'}
use Test::More tests => 31;
use Carp;
my %rom=(MCCXXXIV=>1234,MCMLXXI=>1971,IV=>4,VI=>6,I=>1,V=>5,X=>10,L=>50,C=>100,D=>500,M=>1000,CDXCVII=>497);
my$rom;ok( ($rom=int2roman($rom{$_})) eq $_, sprintf"int2roman %8d => %-10s %-10s",$rom{$_},$_,"($rom)") for sort keys%rom;
my$int;ok( ($int=roman2int($_)) eq $rom{$_}, sprintf"roman2int %-8s => %10d %10d",$_,$rom{$_},$int) for sort keys%rom;
ok( do{eval{roman2int("a")};$@=~/invalid/i}, "croaks ok" );
ok( roman2int("-MCCXXXIV")==-1234, 'negative ok');
ok( int2roman(0) eq '', 'zero');
ok( !defined(int2roman(undef)), 'undef');
ok( defined(int2roman("")) && !length(int2roman("")), 'empty');
# make test
# perl Makefile.PL; make; perl -Iblib/lib t/18_pad.t
use lib '.'; BEGIN{require 't/common.pl'}
use Test::More tests => 20;
for(
['rpad','gomle',9,undef,'gomle '],
['lpad','gomle',9,undef,' gomle'],
['rpad','gomle',9,'-','gomle----'],
['lpad','gomle',9,'+','++++gomle'],
['rpad','gomle',4,undef,'goml'],
['lpad','gomle',4,undef,'goml'],
['rpad','gomle',7,'xyz','gomlexy'],
t/19_serialize.t view on Meta::CPAN
# make test
# perl Makefile.PL; make; perl -Iblib/lib t/19_serialize.t
use lib '.'; BEGIN{require 't/common.pl'}
use Test::More tests => 1;
ok_ref( [serialize({1=>2,2=>3})], ['(\'1\'=>\'2\',
\'2\'=>\'3\'
)'] );
#TODO: lots
t/20_range_globr.t view on Meta::CPAN
# make test
# perl Makefile.PL; make; perl -Iblib/lib t/20_range_globr.t
use lib '.'; BEGIN{require 't/common.pl'}
use Test::More tests => 7+15;
ok_ref([range(11)], [0,1,2,3,4,5,6,7,8,9,10], 'range(11)' );
ok_ref([range(2,11)], [2,3,4,5,6,7,8,9,10], 'range(2,11)' );
ok_ref([range(11,2,-1)],[11,10,9,8,7,6,5,4,3], 'range(11,2,-1)' );
ok_ref([range(2,11,3)], [2,5,8], 'range(2,11,3)' );
ok_ref([range(11,2,-3)],[11,8,5], 'range(11,2,-3)' );
ok_ref([range(2,11,1,0.1)], [2, 3, 4.1, 5.3, 6.6, 8, 9.5 ],'range(2,11,1,0.1)');
ok_ref([range(2,11,1,0.1,-0.01)],[2, 3, 4.1, 5.29, 6.56, 7.9, 9.3, 10.75],'range(2,11,1,0.1,-0.01)');
t/21_read_conf.t view on Meta::CPAN
# make test
# perl Makefile.PL; make; perl -Iblib/lib t/21_read_conf.t
use lib '.'; BEGIN{require 't/common.pl'}
use Test::More tests => 3;
my $c=<<'END';
#tester
hei: fdas #heihei
hopp: and {u dont stoppp #
#dfsa
dfsa
dsa
t/22_trim.t view on Meta::CPAN
# make test
# perl Makefile.PL; make; perl -Iblib/lib t/22_trim.t
use lib '.'; BEGIN{require 't/common.pl'}
use Test::More tests => 7;
#--trim
ok( trim(" asdf \t\n 123 ") eq "asdf 123", 'trim 1');
ok( trim(" asdf\t\n 123 ") eq "asdf\t123", 'trim 2');
ok( trim(" asdf\n\t 123\n") eq "asdf\n123", 'trim 3');
my($trimstr,@trim)=(' please ', ' please ', ' remove ', ' my ', ' spaces ');
ok( join('',map"<$_>",trim(@trim)) eq '<please><remove><my><spaces>', 'trim array');
trim(\$trimstr);
ok($trimstr eq 'please', 'trim inplace');
# make test
# perl Makefile.PL; make; perl -Iblib/lib t/23_ed.t
use lib '.'; BEGIN{require 't/common.pl'}
use Test::More tests => 17;
sub tst {
my($start,$cmds,$end)=@_;
my $ed=ed($start,$cmds);
ok($ed eq $end, $ed eq $end ? "Ok ed() -> $ed" : "Got: $ed Expected: $end");
}
#--test sub ed
tst('','hello world', 'hello world' );
tst('','"Hello World!"', 'Hello World!' );
# make test
# perl Makefile.PL; make; perl -Iblib/lib t/24_db.t
no strict;
no warnings;
#use lib '.'; BEGIN{require 't/common.pl'}
use Acme::Tools;
use Test::More tests => 10;
ok(1) for 1..10;exit;#4now
my $f='/tmp/acme-tools.sqlite'; unlink($f);
print repl($f,'x','y'),"\n";
dlogin($f);
ddo(<<"");
create table tst (
a integer primary key,
t/25_pwgen.t view on Meta::CPAN
# make test
# perl Makefile.PL; make; perl -Iblib/lib t/25_pwgen.t
use lib '.'; BEGIN{require 't/common.pl'}
use Test::More tests => 11; if($^O ne 'linux'){ ok(1) for 1..11; exit }
sub tstr{sprintf(" (%d trials, %.5f sec)",$Acme::Tools::Pwgen_trials, $Acme::Tools::Pwgen_sec)}
SKIP: {
skip "- strangely pwgen-croak-test fails on windows sometime", 2 if $^O ne 'linux';
local $Acme::Tools::Pwgen_max_sec=0.001;
eval{pwgen(3)}; ok($@=~/pwgen.*25_pwgen.t/,"pwgen croak works: ".trim($@));
local $Acme::Tools::Pwgen_max_trials=3;
eval{pwgen(3)}; ok($@=~/pwgen.*after 3 .*25_pwgen.t/,"pwgen croak works: ".trim($@));
t/26_openstr.t view on Meta::CPAN
# make test
# perl Makefile.PL; make; perl -Iblib/lib t/26_openstr.t
use lib '.'; BEGIN{require 't/common.pl'}
use Test::More tests => 16;
#if( $^O =~ /linux/i ) { plan tests => 16 }
#else { plan skip_all => 'skips, not linux' }
sub tst {
my($s,$f)=@_;
my $o=eval{openstr($s)};
if($@=~/(\w+ not found)/){ok(1,$1);return}
$o=~s,/\S+/,,g;
ok($o eq $f, "$s --> $f (is $o)");
t/27_timestuff.t view on Meta::CPAN
# tms() and other time stuff
# make test
# perl Makefile.PL; make; perl -Iblib/lib t/27_timestuff.t
use lib '.'; BEGIN{require 't/common.pl'}
use Test::More;
use Digest::MD5 'md5_hex';
if( $^O=~/(?<!cyg)win/i ) { plan skip_all => 'POSIX::tzset not ok on windows' }
else { plan tests => 61 }
$ENV{TZ}='CET';
#$ENV{TZ}='Europe/Oslo';
#$ENV{TZ}='Asia/Kolkata';
require POSIX; POSIX::tzset();
t/28_wipe.t view on Meta::CPAN
# make test
# perl Makefile.PL; make; perl -Iblib/lib t/28_wipe.t
use lib '.'; BEGIN{require 't/common.pl'}
use Test::More tests => 3;
if($^O eq 'linux'){
my $f=tmp().'/acme-tools.wipe.tmp';
writefile($f,join(" ",map rand(),1..1000)); #system("ls -l $f");
my $ntrp=sub{length(gz(readfile($f).""))};
my $n=&$ntrp;
wipe($f,undef,1);
my $ratio=$n/&$ntrp;
ok($ratio>50 || !$INC{'Compress/Zlib.pm'}, "ratio $ratio > 50");
ok(-s$f>5e3);
t/29_cmd_z2z.t view on Meta::CPAN
# make test
# perl Makefile.PL; make; perl -Iblib/lib t/29_cmd_z2z.t
use lib '.'; BEGIN{require 't/common.pl'}
use Test::More tests => 8;
warn <<"" and map ok(1),1..8 and exit if $^O!~/^(linux|cygwin)$/;
Tests for cmd_z2z not available for $^O, only linux and cygwin
my $tmp=tmp();
my $tf="$tmp/acme-tools.cmd_z2z";
writefile($tf,join" ",1..500);
#print qx(ls -l $tf)."\n";
my($last,$n)=("",0);
for(qw(gz bz2 xz gz xz bz2 gz)){
t/30_cnttbl.t view on Meta::CPAN
# make test
# perl Makefile.PL; make; perl -Iblib/lib t/30_cnttbl.t
use lib '.'; BEGIN{require 't/common.pl'}
use Test::More tests => 2;
#---------- test 1
my $tbl=cnttbl({Norway=>5214890,Sweden=>9845155,Denmark=>5699220,Finland=>5496907,Iceland=>331310});
#print $tbl;
ok($tbl eq <<"END");
Iceland 331310 1.25%
Norway 5214890 19.61%
Finland 5496907 20.67%
Denmark 5699220 21.44%
t/31_readable.t view on Meta::CPAN
# make test
# perl Makefile.PL; make; perl -Iblib/lib t/31_readable.t
use lib '.'; BEGIN{require 't/common.pl'}
use Test::More tests => 37;
#----------bytes_readable
my %br=(
999 => '999 B',
1000 => '1000 B',
1024 => '1.00 kB',
1153433 => '1.10 MB',
1181116006 => '1.10 GB',
1209462790553 => '1.10 TB',