line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::RandomCheck::ProbMonad; |
2
|
4
|
|
|
4
|
|
14
|
use strict; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
93
|
|
3
|
4
|
|
|
4
|
|
11
|
use warnings; |
|
4
|
|
|
|
|
21
|
|
|
4
|
|
|
|
|
82
|
|
4
|
4
|
|
|
4
|
|
13
|
use Exporter qw(import); |
|
4
|
|
|
|
|
4
|
|
|
4
|
|
|
|
|
1199
|
|
5
|
|
|
|
|
|
|
our @EXPORT = qw( |
6
|
|
|
|
|
|
|
gen const range elements variant |
7
|
|
|
|
|
|
|
); |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub gen (&) { |
10
|
0
|
|
|
0
|
0
|
|
my $code = shift; |
11
|
0
|
|
|
|
|
|
bless $code => __PACKAGE__; |
12
|
|
|
|
|
|
|
} |
13
|
|
|
|
|
|
|
|
14
|
0
|
|
|
0
|
0
|
|
sub const (@) { my @args = @_; gen { @args } } |
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub range ($$) { |
17
|
0
|
|
|
0
|
0
|
|
my ($min, $max) = @_; |
18
|
0
|
|
|
0
|
|
|
gen { $_[0]->next_int($min, $max) }; |
|
0
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub elements (@) { |
22
|
0
|
|
|
0
|
0
|
|
my $ref_elems = \@_; |
23
|
0
|
|
|
0
|
|
|
(range 0, $#$ref_elems)->map(sub { $ref_elems->[shift] }); |
|
0
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub pick { |
27
|
0
|
|
|
0
|
1
|
|
my ($self, $rand, $size) = @_; |
28
|
0
|
|
|
|
|
|
$self->($rand, $size); |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub map { |
32
|
0
|
|
|
0
|
1
|
|
my ($self, $f) = @_; |
33
|
0
|
|
|
0
|
|
|
gen { $f->($self->pick(@_)) }; |
|
0
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub flat_map { |
37
|
0
|
|
|
0
|
1
|
|
my ($self, $f) = @_; |
38
|
|
|
|
|
|
|
gen { |
39
|
0
|
|
|
0
|
|
|
my ($rand, $size) = @_; |
40
|
0
|
|
|
|
|
|
$f->($self->pick($rand, $size))->pick($rand, $size); |
41
|
0
|
|
|
|
|
|
}; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
1; |
45
|
|
|
|
|
|
|
__END__ |