Permalink
Browse files

[crypt.pl] fixed CoveredDisk exception message

It got in an extra 'and ' in the case of 1-item lists.
  • Loading branch information...
1 parent 26f2c6b commit 8de2ebbf5092a2449e747d9ea961d6f3d887a126 @masak committed Jul 1, 2012
Showing with 17 additions and 1 deletion.
  1. +17 −1 crypt.pl
View
@@ -61,7 +61,9 @@
sub last_and(@things) {
map { "{'and ' if $_ == @things.end}@things[$_]" }, ^@things
}
- my $disklist = join ', ', last_and map { "the $_" }, @.covered_by;
+ my $disklist = @.covered_by > 1
+ ?? join ', ', last_and map { "the $_" }, @.covered_by
+ !! "the @.covered_by[0]";
"Cannot move the {.disk}: it is covered by $disklist"
}
}
@@ -339,6 +341,20 @@ (&code, $ex_type, $message, &followup?)
{
my $game = Hanoi::Game.new();
+ throws_exception
+ { $game.move('small disk', 'right') },
+ X::Hanoi::CoveredDisk,
+ 'naming source disk instead of the rod (-) no and for one-item lists',
+ {
+ is .message,
+ 'Cannot move the small disk: it is covered by the tiny disk',
+ '.message attribute';
+ };
+ }
+
+ {
+ my $game = Hanoi::Game.new();
+
is $game.remove('tiny disk'),
Hanoi::DiskRemoved.new(:size<tiny>, :source<left>),
'removing a disk (+)';

0 comments on commit 8de2ebb

Please sign in to comment.