ex/statistics.pl

filter: Statementstmt 100% 26 / 26 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod n/a totaltotal 100% 31 / 31 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« ex/prime.pl ↑ Summary
1 1 ▶use v5.24;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use Test::More;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Q::S::L;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 sub is_with_precision
7 3 ▶{
Subroutine is_with_precision: called CC=1 SCAR=0.0
8 3 my ($num, $exp, $note) = @_;
9 3 is sprintf("%.5f", $num), sprintf("%.5f", $exp), $note;
10 }
11  
12 my $dataset =
13  
14 # numbers from 1 to 9, with weights from 9 to 1
15 9 superpos(map { [$_, 10 - $_] } 1 .. 9)
16 *
17  
18 # even numbers from 100 to 200, with weight from 1 to 25 to 1
19 1 superpos(map { [25 - abs(25 - $_), 100 + $_ * 2] } 1 .. 49)
20 ;
21  
22 1 my $stats = $dataset->stats;
23  
24 1 note "most probable outcome: " . $stats->most_probable->to_ket_notation;
25 1 note "least probable outcome: " . $stats->least_probable->to_ket_notation;
26 1 note "median: " . $stats->median;
27 1 note "expected value: " . $stats->expected_value . " ± " . $stats->standard_deviation;
28 1 note "random roll: " . $dataset->collapse;
29  
30 1 is_with_precision $stats->median, 360, "median ok";
31 1 is_with_precision $stats->mean, 550, "mean ok";
32 1 is_with_precision $stats->most_probable->states->[0]->weight, "0.008", "most probable weight ok";
33  
34 1 done_testing;
35  
36 __END__
« ex/prime.pl ↑ Summary