Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[crypt.pl] cannot remove an already removed disk

  • Loading branch information...
commit 50e0179cdb3d359149f6a78040c74fd09ecbc801 1 parent 8de2ebb
Carl Mäsak authored

Showing 1 changed file with 29 additions and 0 deletions. Show diff stats Hide diff stats

  1. 29  crypt.pl
29  crypt.pl
@@ -76,6 +76,15 @@
76 76
     }
77 77
 }
78 78
 
  79
+class X::Hanoi::DiskHasBeenRemoved is Exception {
  80
+    has $.disk;
  81
+    has $.action;
  82
+
  83
+    method message($_:) {
  84
+        "Cannot {.action} the {.disk} because it has been removed"
  85
+    }
  86
+}
  87
+
79 88
 class Hanoi::Game {
80 89
     my @disks = map { "$_ disk" }, <tiny small medium large huge>;
81 90
     my %size_of = @disks Z 1..5;
@@ -153,6 +162,8 @@
153 162
                 last;
154 163
             }
155 164
         }
  165
+        die X::Hanoi::DiskHasBeenRemoved.new(:action<remove>, :$disk)
  166
+            unless defined $source;
156 167
         die X::Hanoi::ForbiddenDiskRemoval.new(:$disk)
157 168
             unless $size eq 'tiny';
158 169
         my @events = Hanoi::DiskRemoved.new(:$size, :$source);
@@ -390,5 +401,23 @@ (&code, $ex_type, $message, &followup?)
390 401
             };
391 402
     }
392 403
 
  404
+    {
  405
+        my $game = Hanoi::Game.new();
  406
+
  407
+        $game.remove('tiny disk');
  408
+
  409
+        throws_exception
  410
+            { $game.remove('tiny disk') },
  411
+            X::Hanoi::DiskHasBeenRemoved,
  412
+            'removing a disk (-) the disk had already been removed',
  413
+            {
  414
+                is .disk, 'tiny disk', '.disk attribute';
  415
+                is .action, 'remove', '.action attribute';
  416
+                is .message,
  417
+                   'Cannot remove the tiny disk because it has been removed',
  418
+                   '.message attribute';
  419
+            };
  420
+    }
  421
+
393 422
     done;
394 423
 }

0 notes on commit 50e0179

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