line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Acme::Test::LogicalEquivalence; |
2
|
|
|
|
|
|
|
# ABSTRACT: Test if expressions are logically equivalent |
3
|
|
|
|
|
|
|
# KEYWORDS: test logic |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
21411
|
use 5.008; |
|
1
|
|
|
|
|
4
|
|
6
|
1
|
|
|
1
|
|
7
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
42
|
|
7
|
1
|
|
|
1
|
|
7
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
60
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = '0.001'; # VERSION |
10
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
21
|
use Exporter qw(import); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
57
|
|
12
|
1
|
|
|
1
|
|
14
|
use Test::More; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
9
|
|
13
|
1
|
|
|
1
|
|
1068
|
use namespace::clean -except => [qw(import)]; |
|
1
|
|
|
|
|
16349
|
|
|
1
|
|
|
|
|
7
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our @EXPORT_OK = qw(is_logically_equivalent); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub is_logically_equivalent { |
19
|
19
|
|
|
19
|
1
|
2449
|
my $numvars = shift; |
20
|
19
|
|
|
|
|
20
|
my $sub1 = shift; |
21
|
19
|
|
|
|
|
14
|
my $sub2 = shift; |
22
|
|
|
|
|
|
|
|
23
|
19
|
|
|
|
|
19
|
my $equivalence = 1; |
24
|
|
|
|
|
|
|
|
25
|
19
|
|
|
|
|
55
|
for (my $i = 0; $i < 2 ** $numvars; ++$i) { |
26
|
74
|
|
|
|
|
455
|
my @vars = split(//, substr(unpack("B32", pack('N', $i)), -$numvars)); |
27
|
|
|
|
|
|
|
|
28
|
74
|
|
|
|
|
155
|
(local $a, local $b) = @vars; |
29
|
74
|
|
|
|
|
163
|
my $r1 = !!$sub1->(@vars); |
30
|
|
|
|
|
|
|
|
31
|
74
|
|
|
|
|
246
|
(local $a, local $b) = @vars; |
32
|
74
|
|
|
|
|
117
|
my $r2 = !!$sub2->(@vars); |
33
|
|
|
|
|
|
|
|
34
|
74
|
|
50
|
|
|
418
|
my $test = !($r1 xor $r2); |
35
|
|
|
|
|
|
|
|
36
|
74
|
100
|
|
|
|
98
|
my $args = join(', ', map { $_ ? 'T' : 'F' } @vars); |
|
162
|
|
|
|
|
355
|
|
37
|
74
|
|
|
|
|
286
|
ok($test, "expr1($args) <=> expr2($args)"); |
38
|
|
|
|
|
|
|
|
39
|
74
|
50
|
|
|
|
27274
|
$equivalence = '' if !$test; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
19
|
|
|
|
|
41
|
return $equivalence; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
1; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
__END__ |