Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[crypt.pl] cannot remove an already removed disk

  • Loading branch information...
commit 50e0179cdb3d359149f6a78040c74fd09ecbc801 1 parent 8de2ebb
@masak authored
Showing with 29 additions and 0 deletions.
  1. +29 −0 crypt.pl
View
29 crypt.pl
@@ -76,6 +76,15 @@
}
}
+class X::Hanoi::DiskHasBeenRemoved is Exception {
+ has $.disk;
+ has $.action;
+
+ method message($_:) {
+ "Cannot {.action} the {.disk} because it has been removed"
+ }
+}
+
class Hanoi::Game {
my @disks = map { "$_ disk" }, <tiny small medium large huge>;
my %size_of = @disks Z 1..5;
@@ -153,6 +162,8 @@
last;
}
}
+ die X::Hanoi::DiskHasBeenRemoved.new(:action<remove>, :$disk)
+ unless defined $source;
die X::Hanoi::ForbiddenDiskRemoval.new(:$disk)
unless $size eq 'tiny';
my @events = Hanoi::DiskRemoved.new(:$size, :$source);
@@ -390,5 +401,23 @@ (&code, $ex_type, $message, &followup?)
};
}
+ {
+ my $game = Hanoi::Game.new();
+
+ $game.remove('tiny disk');
+
+ throws_exception
+ { $game.remove('tiny disk') },
+ X::Hanoi::DiskHasBeenRemoved,
+ 'removing a disk (-) the disk had already been removed',
+ {
+ is .disk, 'tiny disk', '.disk attribute';
+ is .action, 'remove', '.action attribute';
+ is .message,
+ 'Cannot remove the tiny disk because it has been removed',
+ '.message attribute';
+ };
+ }
+
done;
}
Please sign in to comment.
Something went wrong with that request. Please try again.