Acme-Tools

 view release on metacpan or  search on metacpan

t/02_general.t  view on Meta::CPAN

1997 Per      182    180     75     73
1997 Tone                    70     69
1998 Gina     171    171     64     64
1998 Hilde    168    168     62     62
1998 Per      182    183     76     74
1998 Tone                    70      0
END

my @reportB=pivot([map{$_=[@$_[0,3,2,1,4]]}(@t=@table)],"Year","Season");
ok(tablestring(\@reportB) eq <<'', 'pivot B');
Year Season Height Height Height Weight Weight Weight Weight
            Gina   Hilde  Per    Gina   Hilde  Per    Tone
---- ------ ------ ------ ------ ------ ------ ------ ------ 
1997 Summer    170    168    182     66     62     75     70
1997 Winter    158    164    180     64     61     73     69
1998 Summer    171    168    182     64     62     76     70
1998 Winter    171    168    183     64     62     74      0

my @reportC=pivot([map{$_=[@$_[1,2,0,3,4]]}(@t=@table)],"Name","Attribute");
ok(tablestring(\@reportC) eq <<'', 'pivot C');
Name  Attribute 1997   1997   1998   1998
                Summer Winter Summer Winter
----- --------- ------ ------ ------ ------ 
Gina  Height       170    158    171    171
Gina  Weight        66     64     64     64
Hilde Height       168    164    168    168
Hilde Weight        62     61     62     62
Per   Height       182    180    182    183
Per   Weight        75     73     76     74
Tone  Weight        70     69     70      0

my @reportD=pivot([map{$_=[@$_[1,2,0,3,4]]}(@t=@table)],"Name");
ok(tablestring(\@reportD) eq <<'', 'pivot D');
Name  Height Height Height Height Weight Weight Weight Weight
      1997   1997   1998   1998   1997   1997   1998   1998
      Summer Winter Summer Winter Summer Winter Summer Winter
----- ------ ------ ------ ------ ------ ------ ------ ------ 
Gina     170    158    171    171     66     64     64     64
Hilde    168    164    168    168     62     61     62     62
Per      182    180    182    183     75     73     76     74
Tone                                  70     69     70      0

#-- upper, lower (utf8?)
#ok(upper('a-zæøåäëïöüÿâêîôûãõàèìòùáéíóúýñð' x 3) eq 'A-ZÆØÅÄËÏÖÜÿÂÊÎÔÛÃÕÀÈÌÒÙÁÉÍÓÚÝÑÐ' x 3, 'upper'); #hmm ÿ
#ok(lower('A-ZÆØÅÄËÏÖÜ.ÂÊÎÔÛÃÕÀÈÌÒÙÁÉÍÓÚÝÑÐ' x 3) eq 'a-zæøåäëïöü.âêîôûãõàèìòùáéíóúýñð' x 3, 'lower'); #hmm .
ok(upper('a-zæøåäëïöü.âêîôûãõàèìòùáéíóúýñð' x 3) eq 'A-ZÆØÅÄËÏÖÜ.ÂÊÎÔÛÃÕÀÈÌÒÙÁÉÍÓÚÝÑÐ' x 3, 'upper'); #hmm ÿ
ok(lower('A-ZÆØÅÄËÏÖÜŸÂÊÎÔÛÃÕÀÈÌÒÙÁÉÍÓÚÝÑÐ' x 3) eq 'a-zæøåäëïöüŸâêîôûãõàèìòùáéíóúýñð' x 3, 'lower'); #hmm Ÿ → Ÿ

#--time_fp
ok( time_fp() =~ /^\d+\.\d+$/ , 'time_fp' );


#-fails on many systems...virtual boxes?
#$^O eq 'linux'
#? ok($diff < 0.03, "sleep_fp, diff=$diff < 0.03")    #off 30% ok
#: ok (1);


#--isnum
my @is=qw/222 2.2e123 +2 -1 -2.2123e-321/;
my @isnt=(qw/2e pi NaN Inf/,'- 2');
ok(isnum($_),'isnum')    for @is;
ok(!isnum($_),'!isnum')  for @isnt;
ok(isnum,'isnum')        for @is;
ok(!isnum,'!isnum')      for @isnt;

#--basename
sub basenametest {my($fasit,@a)=@_;my$b=basename(@a);ok($fasit eq $b,"basename $b")}
basenametest('brb.pl',       '/tmp/brb.pl');
basenametest('brb.pl',       '/tmp/123/brb.pl');
basenametest('brb.pl',       'brb.pl');
basenametest('brb',          'brb.pl','.pl');
basenametest('brb',          '/tmp/brb.pl','.pl');
basenametest('brb,pl',       '/tmp/123/brb,pl','.pl');
basenametest('report2.pl',   'report2.pl','.\w+');
basenametest('report2',      'report2.pl',qr/.\w+/);

#--dirname
ok(dirname('/tmp/brbbbb.pl') eq '/tmp'              ,'dirname');
ok(dirname('brbbbb.pl') eq '.'                      ,'dirname');

#--nicenum
# print 14.3 - 14.0;              # 0.300000000000001
# print 34.3 - 34.0;              # 0.299999999999997

#--fails sometimes, dunno why:
#http://www.cpantesters.org/cpan/report/fddd1d18-1b2c-11e7-9d0d-a625a53c07fe ( x 20, others also)
#my($inn,$n,$nn)=(0);
#my $nndebugstr=sub{++$inn;"nicenum$inn $n --> $Acme::Tools::Nicenum --> $nn"};
#$nn=nicenum( $n = 14.3 - 14.0 ); cmp_ok($nn,'==',0.3,   &$nndebugstr);
#$nn=nicenum( $n = 34.3 - 34.0 ); cmp_ok($nn,'==',0.3,   &$nndebugstr);
#$nn=nicenum( $n = 1e8+1 );       cmp_ok($nn,'==',1e8+1, &$nndebugstr);

 view all matches for this distribution
 view release on metacpan -  search on metacpan

( run in 1.724 second using v1.00-cache-2.02-grep-82fe00e-cpan-72ae3ad1e6da )