Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[crypt.pl] cannot remove covered disks

This exception takes precedence over the 'forbidden disk removal' one.
  • Loading branch information...
commit b6edc9c5658bd095128b7ccde640a020abc6a697 1 parent 94cf486
@masak authored
Showing with 17 additions and 2 deletions.
  1. +17 −2 crypt.pl
View
19 crypt.pl
@@ -139,15 +139,20 @@
method remove($disk) {
my $size = $disk.words[0];
- die X::Hanoi::ForbiddenDiskRemoval.new(:$disk)
- unless $size eq 'tiny';
my $source;
for %!state -> ( :key($rod), :value(@disks) ) {
if $disk eq any(@disks) {
+ sub smaller_disks {
+ grep { %size_of{$_} < %size_of{$disk} }, @disks;
+ }
+ die X::Hanoi::CoveredDisk.new(:$disk, :covered_by(smaller_disks))
+ unless @disks[*-1] eq $disk;
$source = $rod;
last;
}
}
+ die X::Hanoi::ForbiddenDiskRemoval.new(:$disk)
+ unless $size eq 'tiny';
my @events = Hanoi::DiskRemoved.new(:$size, :$source);
self!apply($_) for @events;
return @events;
@@ -348,6 +353,16 @@ (&code, $ex_type, $message, &followup?)
'Removing the small disk is forbidden',
'.message attribute';
};
+
+ throws_exception
+ { $game.remove('medium disk') },
+ X::Hanoi::CoveredDisk,
+ 'removing a disk (-) the disk is covered',
+ {
+ is .disk, 'medium disk', '.disk attribute';
+ is .covered_by, ['small disk'],
+ '.covered_by attribute';
+ };
}
done;
Please sign in to comment.
Something went wrong with that request. Please try again.