Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[crypt.pl] cannot add a disk with a made-up name

  • Loading branch information...
commit 41501d67f9e1c8e948ce155d29d0d1a9e62cdb68 1 parent 89ce144
@masak authored
Showing with 21 additions and 0 deletions.
  1. +21 −0 crypt.pl
View
21 crypt.pl
@@ -90,6 +90,14 @@
}
}
+class X::Hanoi::NoSuchDisk is Exception {
+ has $.disk;
+
+ method message($_:) {
+ "Cannot add a {.disk} because there is no such disk"
+ }
+}
+
class Hanoi::Game {
my @disks = map { "$_ disk" }, <tiny small medium large huge>;
my %size_of = @disks Z 1..5;
@@ -149,6 +157,8 @@
}
method add($disk, $target) {
+ die X::Hanoi::NoSuchDisk.new(:$disk)
+ unless $disk eq any(@disks);
my $size = $disk.words[0];
my @events = Hanoi::DiskAdded.new(:$size, :$target);
self!apply($_) for @events;
@@ -433,6 +443,17 @@ (&code, $ex_type, $message, &followup?)
is $game.add('tiny disk', 'left'),
Hanoi::DiskAdded.new(:size<tiny>, :target<left>),
'adding a disk (+)';
+
+ throws_exception
+ { $game.add('humongous disk', 'middle') },
+ X::Hanoi::NoSuchDisk,
+ 'adding a disk (-) there is no such disk',
+ {
+ is .disk, 'humongous disk', '.disk attribute';
+ is .message,
+ 'Cannot add a humongous disk because there is no such disk',
+ '.message attribute';
+ };
}
done;

0 comments on commit 41501d6

Please sign in to comment.
Something went wrong with that request. Please try again.