Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[crypt.pl] refuse to add to a nonexistent rod

  • Loading branch information...
commit 2fecc9137c1a24bcb20eb8527c7e86a39ee20a1c 1 parent a68b84b
Carl Mäsak authored

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

  1. 11  crypt.pl
11  crypt.pl
@@ -166,6 +166,8 @@
166 166
     method add($disk, $target) {
167 167
         die X::Hanoi::NoSuchDisk.new(:$disk)
168 168
             unless $disk eq any(@disks);
  169
+        die X::Hanoi::NoSuchRod.new(:rod<target>, :name($target))
  170
+            unless %!state.exists($target);
169 171
         die X::Hanoi::DiskAlreadyOnARod.new(:$disk)
170 172
             if grep { $disk eq any(@$_) }, %!state.values;
171 173
         my @events = Hanoi::DiskAdded.new(:$disk, :$target);
@@ -456,6 +458,15 @@ (&code, $ex_type, $message, &followup?)
456 458
                     '.message attribute';
457 459
             };
458 460
 
  461
+        throws_exception
  462
+            { $game.add('tiny disk', 'pineapple') },
  463
+            X::Hanoi::NoSuchRod,
  464
+            'moving a disk (-) the rod does not exist',
  465
+            {
  466
+                is .rod, 'target', '.rod attribute';
  467
+                is .name, 'pineapple', '.name attribute';
  468
+            };
  469
+
459 470
         is $game.add('tiny disk', 'left'),
460 471
            Hanoi::DiskAdded.new(:disk('tiny disk'), :target<left>),
461 472
            'adding a disk (+)';

0 notes on commit 2fecc91

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