Commit | Line | Data |
bf4b1e52 |
1 | #!./perl |
2 | |
3 | # |
4 | # test the logical operators '&&', '||', '!', 'and', 'or', 'not' |
5 | # |
6 | |
7 | BEGIN { |
8 | chdir 't' if -d 't'; |
20822f61 |
9 | @INC = '../lib'; |
bf4b1e52 |
10 | } |
11 | |
07f3cdf5 |
12 | print "1..11\n"; |
bf4b1e52 |
13 | |
14 | my $test = 0; |
15 | for my $i (undef, 0 .. 2, "", "0 but true") { |
16 | my $true = 1; |
17 | my $false = 0; |
18 | for my $j (undef, 0 .. 2, "", "0 but true") { |
19 | $true &&= !( |
20 | ((!$i || !$j) != !($i && $j)) |
21 | or (!($i || $j) != (!$i && !$j)) |
22 | or (!!($i || $j) != !(!$i && !$j)) |
23 | or (!(!$i || !$j) != !!($i && $j)) |
24 | ); |
25 | $false ||= ( |
26 | ((!$i || !$j) == !!($i && $j)) |
27 | and (!!($i || $j) == (!$i && !$j)) |
28 | and ((!$i || $j) == ($i && !$j)) |
29 | and (($i || !$j) != (!$i && $j)) |
30 | ); |
31 | } |
32 | if (not $true) { |
33 | print "not "; |
34 | } elsif ($false) { |
35 | print "not "; |
36 | } |
37 | print "ok ", ++$test, "\n"; |
38 | } |
39 | |
40 | # $test == 6 |
41 | my $i = 0; |
42 | (($i ||= 1) &&= 3) += 4; |
43 | print "not " unless $i == 7; |
44 | print "ok ", ++$test, "\n"; |
edbe35ea |
45 | |
46 | my ($x, $y) = (1, 8); |
47 | $i = !$x || $y; |
48 | print "not " unless $i == 8; |
49 | print "ok ", ++$test, "\n"; |
50 | |
07f3cdf5 |
51 | ++$y; |
52 | $i = !$x || !$x || !$x || $y; |
edbe35ea |
53 | print "not " unless $i == 9; |
54 | print "ok ", ++$test, "\n"; |
07f3cdf5 |
55 | |
56 | $x = 0; |
57 | ++$y; |
58 | $i = !$x && $y; |
59 | print "not " unless $i == 10; |
60 | print "ok ", ++$test, "\n"; |
61 | |
62 | ++$y; |
63 | $i = !$x && !$x && !$x && $y; |
64 | print "not " unless $i == 11; |
65 | print "ok ", ++$test, "\n"; |