Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[crypt.pl] refuse to add to a nonexistent rod

  • Loading branch information...
commit 2fecc9137c1a24bcb20eb8527c7e86a39ee20a1c 1 parent a68b84b
@masak authored
Showing with 11 additions and 0 deletions.
  1. +11 −0 crypt.pl
View
11 crypt.pl
@@ -166,6 +166,8 @@
method add($disk, $target) {
die X::Hanoi::NoSuchDisk.new(:$disk)
unless $disk eq any(@disks);
+ die X::Hanoi::NoSuchRod.new(:rod<target>, :name($target))
+ unless %!state.exists($target);
die X::Hanoi::DiskAlreadyOnARod.new(:$disk)
if grep { $disk eq any(@$_) }, %!state.values;
my @events = Hanoi::DiskAdded.new(:$disk, :$target);
@@ -456,6 +458,15 @@ (&code, $ex_type, $message, &followup?)
'.message attribute';
};
+ throws_exception
+ { $game.add('tiny disk', 'pineapple') },
+ X::Hanoi::NoSuchRod,
+ 'moving a disk (-) the rod does not exist',
+ {
+ is .rod, 'target', '.rod attribute';
+ is .name, 'pineapple', '.name attribute';
+ };
+
is $game.add('tiny disk', 'left'),
Hanoi::DiskAdded.new(:disk('tiny disk'), :target<left>),
'adding a disk (+)';
Please sign in to comment.
Something went wrong with that request. Please try again.