#!perl # ABSTRACT: Test if expressions are logically equivalent # PODNAME: test-logical-equivalence =head1 SYNOPSIS # be sure to escape $ and other special characters from your shell test-logical-equivalence '$a && $b' '$b && $a' =head1 SEE ALSO =for :list * L =cut use 5.008; use warnings FATAL => 'all'; use strict; use Test::More; use Acme::Test::LogicalEquivalence qw(is_logically_equivalent); sub usage { print < $numvars2 ? $numvars1 : $numvars2; if ($num < 1) { print STDERR 'No variables detected. Variables should be one or more of $a, $b, ..., $z', "\n"; exit 2; } # convert $a-style vars to $_[0]-style to support more than just $a and $b $expr1 =~ s/\$([a-z])/'$_['.(ord($1) - 97).']'/ge; $expr2 =~ s/\$([a-z])/'$_['.(ord($1) - 97).']'/ge; my $sub1 = eval "sub { $expr1 }" or die "Expression 1: $@\n"; ## no critic (ProhibitStringyEval) my $sub2 = eval "sub { $expr2 }" or die "Expression 2: $@\n"; ## no critic (ProhibitStringyEval) plan tests => (2 ** $num); note "Testing for logical equivalence of two expressions with $num variable(s)..."; my $equivalence = is_logically_equivalent($num, $sub1, $sub2); note $equivalence ? 'Logical equivalence proved!' : 'Bummer...';