summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordakkar <dakkar@thenautilus.net>2011-08-29 14:24:53 +0100
committerdakkar <dakkar@thenautilus.net>2011-08-29 14:24:53 +0100
commitebae593425aef965ca2504db727c56e70d308d87 (patch)
treea69b4a03d646232fd8383dbf870ca90bbdd41eb1
parenttest ring_setting is writable (diff)
downloadEnigmatic-ebae593425aef965ca2504db727c56e70d308d87.tar.gz
Enigmatic-ebae593425aef965ca2504db727c56e70d308d87.tar.bz2
Enigmatic-ebae593425aef965ca2504db727c56e70d308d87.zip
notches
-rw-r--r--lib/Enigmatic/Rotor.pm10
-rw-r--r--lib/Enigmatic/RotorBox.pm20
-rw-r--r--t/rotors.t27
3 files changed, 47 insertions, 10 deletions
diff --git a/lib/Enigmatic/Rotor.pm b/lib/Enigmatic/Rotor.pm
index 792c7b5..e0a3b97 100644
--- a/lib/Enigmatic/Rotor.pm
+++ b/lib/Enigmatic/Rotor.pm
@@ -1,6 +1,7 @@
package Enigmatic::Rotor;
use DAKKAR::p 'class';
use Enigmatic::Types qw(WiringMap Letter RotorPos);
+use MooseX::Types::Set::Object;
has wiring => (
is => 'ro',
@@ -14,6 +15,15 @@ has ring_setting => (
default => 0,
);
+has notches => (
+ isa => 'Set::Object',
+ coerce => 1,
+ handles => {
+ has_notch_at => 'member',
+ },
+ default => sub { [] },
+);
+
with 'Enigmatic::Role::WithWiring';
sub map {
diff --git a/lib/Enigmatic/RotorBox.pm b/lib/Enigmatic/RotorBox.pm
index 08a6b22..57f0a47 100644
--- a/lib/Enigmatic/RotorBox.pm
+++ b/lib/Enigmatic/RotorBox.pm
@@ -17,16 +17,16 @@ has rotorset => (
sub _build_rotorset {
my %rotors = (
- I => 'EKMFLGDQVZNTOWYHXUSPAIBRCJ',
- II => 'AJDKSIRUXBLHWTMCQGZNPYFVOE',
- III => 'BDFHJLCPRTXVZNYEIWGAKMUSQO',
- IV => 'ESOVPZJAYQUIRHXLNFTGKDCMWB',
- V => 'VZBRGITYUPSDNHLXAWMJQOFECK',
- VI => 'JPGVOUMFYQBENHZRDKASXLICTW',
- VII => 'NZJHGRCXMYSWBOUFAIVLPEKQDT',
- VIII => 'FKQHTLXOCBJSPDZRAMEWNIUYGV',
- Beta => 'LEYJVCNIXWPBQMDRTAKZGFUHOS',
- Gamma => 'FSOKANUERHMBTIYCWLQPZXVGJD',
+ I => { wiring => 'EKMFLGDQVZNTOWYHXUSPAIBRCJ', notches => ['Q'] },
+ II => { wiring => 'AJDKSIRUXBLHWTMCQGZNPYFVOE', notches => ['E'] },
+ III => { wiring => 'BDFHJLCPRTXVZNYEIWGAKMUSQO', notches => ['V'] },
+ IV => { wiring => 'ESOVPZJAYQUIRHXLNFTGKDCMWB', notches => ['J'] },
+ V => { wiring => 'VZBRGITYUPSDNHLXAWMJQOFECK', notches => ['Z'] },
+ VI => { wiring => 'JPGVOUMFYQBENHZRDKASXLICTW', notches => ['M','Z'] },
+ VII => { wiring => 'NZJHGRCXMYSWBOUFAIVLPEKQDT', notches => ['M','Z'] },
+ VIII => { wiring => 'FKQHTLXOCBJSPDZRAMEWNIUYGV', notches => ['M','Z'] },
+ Beta => { wiring => 'LEYJVCNIXWPBQMDRTAKZGFUHOS', notches => [] },
+ Gamma => { wiring => 'FSOKANUERHMBTIYCWLQPZXVGJD', notches => [''] },
);
$_ = Enigmatic::Rotor->new($_) for values %rotors;
diff --git a/t/rotors.t b/t/rotors.t
index 9e0b2f8..4676a55 100644
--- a/t/rotors.t
+++ b/t/rotors.t
@@ -67,6 +67,18 @@ subtest 'rotor box' => sub {
Beta => 'LEYJVCNIXWPBQMDRTAKZGFUHOS',
Gamma => 'FSOKANUERHMBTIYCWLQPZXVGJD',
);
+ my %notch_at = (
+ I => ['Q'],
+ II => ['E'],
+ III => ['V'],
+ IV => ['J'],
+ V => ['Z'],
+ VI => ['Z','M'],
+ VII => ['Z','M'],
+ VIII => ['Z','M'],
+ Beta => [],
+ Gamma => [],
+ );
my $box = Enigmatic::RotorBox->new();
@@ -77,6 +89,21 @@ subtest 'rotor box' => sub {
Test::Enigmatic::test_static_map(
$r,$out,
"rotor $rotor from box");
+
+ my @notches = $notch_at{$rotor}->flatten;
+ my @not_notches = do {
+ my %tmp;@tmp{'A'..'Z'}=();
+ delete @tmp{@notches};
+ keys %tmp;
+ };
+ for my $l (@notches) {
+ ok($r->has_notch_at($l),
+ "rotor $rotor has notch at $l");
+ }
+ for my $l (@not_notches) {
+ ok(! $r->has_notch_at($l),
+ "rotor $rotor has no notch at $l");
+ }
});
};