diff options
author | dakkar <dakkar@thenautilus.net> | 2011-08-29 13:06:32 +0100 |
---|---|---|
committer | dakkar <dakkar@thenautilus.net> | 2011-08-29 13:06:32 +0100 |
commit | 556f1e542cdeadb7dc2f549ec7915fe28f5bb112 (patch) | |
tree | 71585b0df498c971b485222a3b5cfd74b84ec413 /t/rotors.t | |
download | Enigmatic-556f1e542cdeadb7dc2f549ec7915fe28f5bb112.tar.gz Enigmatic-556f1e542cdeadb7dc2f549ec7915fe28f5bb112.tar.bz2 Enigmatic-556f1e542cdeadb7dc2f549ec7915fe28f5bb112.zip |
static rotors
Diffstat (limited to 't/rotors.t')
-rw-r--r-- | t/rotors.t | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/t/rotors.t b/t/rotors.t new file mode 100644 index 0000000..509d88d --- /dev/null +++ b/t/rotors.t @@ -0,0 +1,59 @@ +#!perl +use DAKKAR::p 'test'; +use List::Util 'shuffle'; + +use Enigmatic::Rotor; + +sub test_the_rotor { + my ($r,$out,$name) = @_; + + my @in = 'A'..'Z'; + my %map;@map{@in}=@$out; + + for my $c ('A' .. 'Z') { + is($r->map($c), + $map{$c}, + "$name on $c"); + } +} + +subtest 'identity rotor' => sub { + my @in = 'A'..'Z'; + my $r = Enigmatic::Rotor->new(@in->join); + test_the_rotor($r,\@in,'identity'); +}; + + +subtest 'scramble rotor' => sub { + my @out = shuffle 'A'..'Z'; + + my $r = Enigmatic::Rotor->new(@out->join); + test_the_rotor($r,\@out,'shuffle'); +}; + +subtest 'identity rotor, non-default ring setting' => sub { + my @out = (('B'..'Z'),'A'); + + my $r = Enigmatic::Rotor->new( + wiring => ['A'..'Z']->join, + ring_setting => 1, + ); + test_the_rotor($r,\@out,'ring=1'); +}; + +subtest 'constraints' => sub { + my @bad_params = ( + 'ABCD', + 'ABCDEFGHIJKLMNOPQRSTUVWXYZABCD', + 'AACDEFGHIJKLMNOPQRSTUVWXYZ', + '12CDEFGHIJKLMNOPQRSTUVWXYZABCD', + ); + + for my $bad_param (@bad_params) { + dies_ok { + Enigmatic::Rotor->new($bad_param); + } "bad parameter $bad_param"; + } +}; + +done_testing(); |