t/op/not.t: Add descriptions to all tests.
authorJames E Keenan <jkeenan@cpan.org>
Sat, 29 Dec 2012 16:23:56 +0000 (11:23 -0500)
committerJames E Keenan <jkeenan@cpan.org>
Sat, 5 Jan 2013 19:13:02 +0000 (14:13 -0500)
Also, add note() before tests 4 and 5 explaining rationale for addition of
parentheses to second arguments.

t/op/not.t

index aa3e192..4aae02c 100644 (file)
@@ -9,14 +9,19 @@ BEGIN {
 plan tests => 16;
 
 # not() tests
-pass() if not();
-is(not(), 1);
-is(not(), not(0));
+pass("logical negation of empty list") if not();
+is(not(), 1, "logical negation of empty list in numeric comparison");
+is(not(), not(0),
+    "logical negation of empty list compared with logical negation of false value");
 
 # test not(..) and !
-is(! 1, (not 1));
-is(! 0, (not 0));
-is(! (0, 0), not(0, 0));
+note("parens needed around second argument in next two tests\nto preserve list context inside function call");
+is(! 1, (not 1),
+    "high- and low-precedence logical negation of true value");
+is(! 0, (not 0),
+    "high- and low-precedence logical negation of false value");
+is(! (0, 0), not(0, 0),
+    "high- and low-precedence logical negation of lists");
 
 # test the return of !
 {
@@ -24,13 +29,18 @@ is(! (0, 0), not(0, 0));
     my $not1 = ! 1;
 
     no warnings;
-    ok($not1 == undef);
-    ok($not1 == ());
+    ok($not1 == undef,
+        "logical negation (high-precedence) of true value is numerically equal to undefined value");
+    ok($not1 == (),
+        "logical negation (high-precedence) of true value is numerically equal to empty list");
 
     use warnings;
-    ok($not1 eq '');
-    ok($not1 == 0);
-    ok($not0 == 1);
+    ok($not1 eq '',
+        "logical negation (high-precedence) of true value in string context is equal to empty string");
+    ok($not1 == 0,
+        "logical negation (high-precedence) of true value is false in numeric context");
+    ok($not0 == 1,
+        "logical negation (high-precedence) of false value is true in numeric context");
 }
 
 # test the return of not
@@ -39,11 +49,16 @@ is(! (0, 0), not(0, 0));
     my $not1 = not 1;
 
     no warnings;
-    ok($not1 == undef);
-    ok($not1 == ());
+    ok($not1 == undef,
+        "logical negation (low-precedence) of true value is numerically equal to undefined value");
+    ok($not1 == (),
+        "logical negation (low-precedence) of true value is numerically equal to empty list");
 
     use warnings;
-    ok($not1 eq '');
-    ok($not1 == 0);
-    ok($not0 == 1);
+    ok($not1 eq '',
+        "logical negation (low-precedence) of true value in string context is equal to empty string");
+    ok($not1 == 0,
+        "logical negation (low-precedence) of true value is false in numeric context");
+    ok($not0 == 1,
+        "logical negation (low-precedence) of false value is true in numeric context");
 }