Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[crypt.pl] cannot move from a rod with no disks

  • Loading branch information...
commit efa9ba6fdb1a179af0c41c40f656a3fe40b8360e 1 parent 4b7c1d2
Carl Mäsak authored
Showing with 20 additions and 0 deletions.
  1. +20 −0 crypt.pl
20 crypt.pl
View
@@ -34,6 +34,14 @@
}
}
+class X::Hanoi::RodHasNoDisks is Exception {
+ has $.name;
+
+ method message($_:) {
+ "Cannot move from the {.name} rod because there is no disk there"
+ }
+}
+
class HanoiGame {
my @names = map { "$_ disk" }, <tiny small medium big huge>;
my %size_of = @names Z 1..5;
@@ -50,6 +58,8 @@
die X::Hanoi::NoSuchRod.new(:rod<target>, :name($to))
unless %!state.exists($to);
my @from_rod := %!state{$from};
+ die X::Hanoi::RodHasNoDisks.new(:name($from))
+ unless @from_rod;
my @to_rod := %!state{$to};
my $moved_disk = @from_rod[*-1];
if @to_rod {
@@ -131,5 +141,15 @@ (&code, $ex_type, &followup?)
'.message attribute';
};
+ throws_exception
+ { $game.move('right', 'middle') },
+ X::Hanoi::RodHasNoDisks,
+ {
+ is .name, 'right', '.name attribute';
+ is .message,
+ q[Cannot move from the right rod because there is no disk there],
+ '.message attribute';
+ };
+
done;
}
Please sign in to comment.
Something went wrong with that request. Please try again.