<grammar-nazi>Percent.</grammar-nazi>
:-)

2011/10/26 Nikolay Mishin <[email protected]>:
> Moscow-pm, Hi
>
> как вам такая реализация?
> use 5.01;
> use Test::More qw/no_plan/;
> use POSIX;
> my $calc_value = 22;
> my $orig_value = 23;
> my $persent    = 10;      #%
> my $message    = 'BIG_SYSTEM';
>
> test_10_persent( $calc_value, $orig_value, $persent, $message );
>
> #test if bigger or lower not lower then 10%
> sub test_10_persent {
>    my ( $calc_value, $orig_value, $persent, $message ) = @_;
>
>    if ( $calc_value >= $orig_value ) {
>        cmp_ok( $calc_value, '>=', $orig_value,
>            $message . " $calc_value >= $orig_value " );
>    }
>    else {
>        my $cal_persent =
>          floor( abs( ( ( $calc_value - $orig_value ) / $orig_value ) * 100 ) 
> );
>        cmp_ok( $cal_persent, '<=', $persent,
>            $message . " $calc_value <= $orig_value but not lower then 10 %" );
>    }
> }
>
>
> --
> Nikolay Mishin
> --
> Moscow.pm mailing list
> [email protected] | http://moscow.pm.org
>
-- 
Moscow.pm mailing list
[email protected] | http://moscow.pm.org

Ответить