App-Dazz

 view release on metacpan or  search on metacpan

lib/App/Dazz/Common.pm  view on Meta::CPAN

                @solns = [ $substr, $start, $o ];
            }
            elsif ( $l == $best ) {
                push @solns, [ $substr, $start, $o ];
            }
        }
    }
    return @solns;
}

sub histogram_percentile {
    my $hist_of  = shift;
    my $fraction = shift;

    my @keys = sort { $a <=> $b } keys %{$hist_of};
    if ( scalar @keys == 0 ) {
        return 0;
    }

    my $target     = List::Util::sum( values %{$hist_of} ) * $fraction;
    my $cumulative = 0;

t/90-common.t  view on Meta::CPAN

        my @results = App::Dazz::Common::lcss( @{$refs} );
        is_deeply( \@results, $expect, "lcss array $i" );
    }
}

{
    print "#histogram\n";
    my @bins = ( 1 .. 100 );
    my %hist_of = map { ( $_, 1 ) } @bins;

    is( App::Dazz::Common::histogram_percentile( \%hist_of, 0.5 ), 50,  "median" );
    is( App::Dazz::Common::histogram_percentile( \%hist_of, 0.25 ), 25,  "quartile" );
    is( App::Dazz::Common::histogram_percentile( \%hist_of, 1 ),   100, "all" );
}

done_testing();



( run in 0.381 second using v1.01-cache-2.11-cpan-709fd43a63f )