Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[bin/crypt] removing a non-existent disk

Should give the appropriate exception NoSuchDisk.
  • Loading branch information...
commit 45fb27113b9d47d1a65ce446ea9b517e25328f6c 1 parent 289fb0c
@masak authored
Showing with 19 additions and 0 deletions.
  1. +19 −0 bin/crypt
View
19 bin/crypt
@@ -161,6 +161,8 @@ class Hanoi::Game {
}
method remove($disk) {
+ die X::Hanoi::NoSuchDisk.new(:action<remove>, :$disk)
+ unless $disk eq any(@disks);
my $source = self!rod_with_disk($disk, 'remove');
die X::Hanoi::ForbiddenDiskRemoval.new(:$disk)
unless $disk eq 'tiny disk';
@@ -596,5 +598,22 @@ multi MAIN('test', 'hanoi') {
};
}
+ {
+ my $game = Hanoi::Game.new();
+
+ throws_exception
+ { $game.remove('masakian disk') },
+ X::Hanoi::NoSuchDisk,
+ 'removing a disk (-) the disk does not exist',
+ {
+ is .action, 'remove', '.action attribute';
+ is .disk, 'masakian disk', '.disk attribute';
+ is .message,
+ 'Cannot remove a masakian disk because there is no such disk',
+ '.message attribute';
+ };
+
+ }
+
done;
}
Please sign in to comment.
Something went wrong with that request. Please try again.