Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[t/spec] add integration test by Donald Knuth, "Man or Boy"

(for stress-testing lexical variables and subs). pugs++ passes them.


git-svn-id: http://svn.pugscode.org/pugs@23072 c213334d-75ef-0310-aa23-eaa082d1ae64
  • Loading branch information...
commit c53b1e76f1f50cdb4e5afdbbbf2dc0a6aaa8191b 1 parent 919fc4f
moritz authored
Showing with 28 additions and 0 deletions.
  1. +28 −0 integration/man-or-boy.t
View
28 integration/man-or-boy.t
@@ -0,0 +1,28 @@
+use Test;
+
+# stress test for lexicals and lexical subs
+# See
+# http://en.wikipedia.org/w/index.php?title=Man_or_boy_test&oldid=249795453#Perl
+
+my @results = 1, 0, -2, 0, 1, 0, 1, -1, -10, -30, -67, -138;
+
+plan +@results;
+
+sub A($k is copy, &x1, &x2, &x3, &x4, &x5) {
+ my $B;
+ $B = sub { A(--$k, $B, &x1, &x2, &x3, &x4) };
+ if ($k <= 0) {
+ return x4($k, &x1, &x2, &x3, &x4, &x5)
+ + x5($k, &x1, &x2, &x3, &x4, &x5);
+ }
+ return $B();
+}
+
+for ^@results -> $i {
+ is A($i, sub {1}, sub {-1}, sub {-1}, sub {1}, sub {0}),
+ @results[$i],
+ "man-or-boy test for start value $i";
+}
+
+
+# vim: ft=perl6
Please sign in to comment.
Something went wrong with that request. Please try again.