Permalink
Browse files

Add in some rosettacode tests and a plan.

  • Loading branch information...
1 parent e488f73 commit 73f05639e910edb66fbf1e0de1902e97d9396f5f @coke coke committed Aug 16, 2012
Showing with 100 additions and 0 deletions.
  1. +8 −0 rosettacode/README
  2. +37 −0 rosettacode/greatest_element_of_a_list.t
  3. +55 −0 rosettacode/sierpinski_triangle.t
View
@@ -0,0 +1,8 @@
+Contains tests from rosettacode.org
+
+The intent is to make it easy to initially pull down sample code from
+Rosetta (which typically emits output to $*OUT), and have to manually
+update only the expected output.
+
+Future updates from rosettacode should be able to be pulled down
+automatically.
@@ -0,0 +1,37 @@
+# http://rosettacode.org/wiki/Greatest_element_of_a_list#Perl_6
+
+use v6;
+use Test;
+
+plan 1;
+
+my $rosetta-code = {
+
+#### RC-begin
+say [max] 17, 13, 50, 56, 28, 63, 62, 66, 74, 54;
+
+say [max] 'my', 'dog', 'has', 'fleas';
+
+sub max2 (*@a) { reduce -> $x, $y { $y after $x ?? $y !! $x }, @a }
+say max2 17, 13, 50, 56, 28, 63, 62, 66, 74, 54;
+#### RC-end
+
+}
+
+my $oldOUT = $*OUT;
+my $output;
+$*OUT = class {
+ method print(*@args) {
+ $output ~= @args.join;
+ }
+}
+
+$rosetta-code.();
+
+my $expected = "74
+my
+74
+";
+
+$*OUT = $oldOUT;
+is($output, $expected, "Greatest element of a list");
@@ -0,0 +1,55 @@
+# http://rosettacode.org/wiki/Sierpinski_triangle#Perl_6
+
+use v6;
+use Test;
+
+plan 1;
+
+my $rosetta-code = {
+
+#### RC-begin
+sub sierpinski ($n) {
+ my @down = '*';
+ my $space = ' ';
+ for ^$n {
+ @down = @down.map({"$space$_$space"}), @down.map({"$_ $_"});
+ $space ~= $space;
+ }
+ return @down;
+}
+
+.say for sierpinski 4;
+#### RC-end
+
+}
+
+my $oldOUT = $*OUT;
+my $output;
+$*OUT = class {
+ method print(*@args) {
+ $output ~= @args.join;
+ }
+}
+
+$rosetta-code.();
+
+my $expected = " *
+ * *
+ * *
+ * * * *
+ * *
+ * * * *
+ * * * *
+ * * * * * * * *
+ * *
+ * * * *
+ * * * *
+ * * * * * * * *
+ * * * *
+ * * * * * * * *
+ * * * * * * * *
+* * * * * * * * * * * * * * * *
+";
+
+$*OUT = $oldOUT;
+is($output, $expected, "Sierpinski Triangle");

0 comments on commit 73f0563

Please sign in to comment.