initial commit
[chaz/p5-Acme-Test-LogicalEquivalence] / t / 01-universal-laws.t
1 #!perl
2
3 use warnings;
4 use strict;
5
6 use Test::More;
7
8 use Acme::Test::LogicalEquivalence qw(is_logically_equivalent);
9
10 note "Let's see if the universe still makes sense...";
11
12 note 'Identity laws';
13 is_logically_equivalent 1,
14 sub { $a && 1 },
15 sub { $a };
16 is_logically_equivalent 1,
17 sub { $a || 0 },
18 sub { $a };
19
20 note 'Domination laws';
21 is_logically_equivalent 1,
22 sub { $a || 1 },
23 sub { 1 };
24 is_logically_equivalent 1,
25 sub { $a && 0 },
26 sub { 0 };
27
28 note 'Idempotent laws';
29 is_logically_equivalent 1,
30 sub { $a && $a },
31 sub { $a };
32 is_logically_equivalent 1,
33 sub { $a || $a },
34 sub { $a };
35
36 note 'Double negation law';
37 is_logically_equivalent 1,
38 sub { !!$a },
39 sub { $a };
40
41 note 'Commutative laws';
42 is_logically_equivalent 2,
43 sub { $a || $b },
44 sub { $b || $a };
45 is_logically_equivalent 2,
46 sub { $a && $b },
47 sub { $b && $a };
48
49 note 'Associative laws';
50 is_logically_equivalent 3,
51 sub { ($_[0] || $_[1]) || $_[2] },
52 sub { $_[0] || ($_[1] || $_[2]) };
53 is_logically_equivalent 3,
54 sub { ($_[0] && $_[1]) && $_[2] },
55 sub { $_[0] && ($_[1] && $_[2]) };
56
57 note 'Distributive laws';
58 is_logically_equivalent 3,
59 sub { $_[0] || ($_[1] && $_[2]) },
60 sub { ($_[0] || $_[1]) && ($_[0] || $_[2]) };
61 is_logically_equivalent 3,
62 sub { $_[0] && ($_[1] || $_[2]) },
63 sub { ($_[0] && $_[1]) || ($_[0] && $_[2]) };
64
65 note 'De Morgan\'s laws';
66 is_logically_equivalent 2,
67 sub { !($a && $b) },
68 sub { !$a || !$b };
69 is_logically_equivalent 2,
70 sub { !($a || $b) },
71 sub { !$a && !$b };
72
73 note 'Absorption laws';
74 is_logically_equivalent 2,
75 sub { $a || ($a && $b) },
76 sub { $a };
77 is_logically_equivalent 2,
78 sub { $a && ($a || $b) },
79 sub { $a };
80
81 note 'Negation laws';
82 is_logically_equivalent 1,
83 sub { $a || !$a },
84 sub { 1 };
85 is_logically_equivalent 1,
86 sub { $a && !$a },
87 sub { 0 };
88
89 done_testing;
90
This page took 0.034727 seconds and 5 git commands to generate.