diff options
author | dakkar <dakkar@thenautilus.net> | 2011-08-29 19:16:26 +0100 |
---|---|---|
committer | dakkar <dakkar@thenautilus.net> | 2011-08-29 19:16:26 +0100 |
commit | 2b28ab91084f37a5e9014737d0df694587fe60cf (patch) | |
tree | 5aa4089d4b3589584d1b6e945184a2fad51b62e6 /t | |
parent | full-machine and tests (diff) | |
download | Enigmatic-2b28ab91084f37a5e9014737d0df694587fe60cf.tar.gz Enigmatic-2b28ab91084f37a5e9014737d0df694587fe60cf.tar.bz2 Enigmatic-2b28ab91084f37a5e9014737d0df694587fe60cf.zip |
fixed rotor ring settings
and removed debug prints
Diffstat (limited to 't')
-rw-r--r-- | t/basic-enigma.t | 1 | ||||
-rw-r--r-- | t/full-enigma.t | 29 | ||||
-rw-r--r-- | t/lib/Test/Enigmatic.pm | 8 | ||||
-rw-r--r-- | t/rotors.t | 31 | ||||
-rw-r--r-- | t/simple-enigma.t | 15 |
5 files changed, 27 insertions, 57 deletions
diff --git a/t/basic-enigma.t b/t/basic-enigma.t index 0760737..9ed8c90 100644 --- a/t/basic-enigma.t +++ b/t/basic-enigma.t @@ -24,5 +24,4 @@ Test::Enigmatic::test_full_machine( 'AAAAA', 'EWTYX'); - done_testing(); diff --git a/t/full-enigma.t b/t/full-enigma.t index 0015b46..872b199 100644 --- a/t/full-enigma.t +++ b/t/full-enigma.t @@ -1,6 +1,6 @@ #!perl use DAKKAR::p 'test'; - +use Test::Enigmatic; use Enigmatic::Machine; sub real_machine { @@ -27,7 +27,6 @@ SSEN ACHX EKNS VIER MBFA ELLT YNNN NNNO OOVI ERYS ICHT EINS NULL EOPLAIN -$plaintext =~ s{\s+}{}g; my $ciphertext = <<'EOCIPHER'; NCZW VUSX PNYM INHZ XMQX @@ -43,27 +42,11 @@ ANJM OLBG FFLE OPRG TFLV RHOW OPBE KVWM UQFM PWPA RMFH AGKX IIBG EOCIPHER -$ciphertext =~ s{\s+}{}g; - -note "encrypt real"; - -my $check = real_machine->map_string($plaintext); -p $check; -is($check,$ciphertext, - 'ok crypt'); - -note "round-trip check"; - -$check = real_machine->map_string($check); -p $check; -is($check,$plaintext, - 'round tripped'); - -note "decrypt real"; -$check = real_machine->map_string($ciphertext); -p $check; -is($check,$plaintext, - 'ok plain'); +Test::Enigmatic::test_full_machine( + \&real_machine, + $plaintext, + $ciphertext); +done_testing(); diff --git a/t/lib/Test/Enigmatic.pm b/t/lib/Test/Enigmatic.pm index 9958667..6e35070 100644 --- a/t/lib/Test/Enigmatic.pm +++ b/t/lib/Test/Enigmatic.pm @@ -18,9 +18,9 @@ sub test_static_map { sub test_full_machine { my ($factory,$input,$exp_output) = @_; - $input =~ s{\s+}{}g; + $input =~ s{\s+}{}g;$input=$input->uc; - my $output = $factory->()->map_string(uc $input); + my $output = $factory->()->map_string($input); note "output: $output"; @@ -32,9 +32,9 @@ sub test_full_machine { $input, 'round tripped'); if ($exp_output) { - $exp_output =~ s{\s+}{}g; + $exp_output =~ s{\s+}{}g;$exp_output=$exp_output->uc; is($output, - uc($exp_output), + $exp_output, 'got expected output'); } } @@ -19,26 +19,6 @@ subtest 'scramble rotor' => sub { Test::Enigmatic::test_static_map($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::Enigmatic::test_static_map($r,\@out,'ring=1'); -}; - -subtest 'identity rotor, moved ring setting' => sub { - my @out = (('B'..'Z'),'A'); - - my $r = Enigmatic::Rotor->new( - wiring => ['A'..'Z']->join, - ); - $r->ring_setting(1); - Test::Enigmatic::test_static_map($r,\@out,'ring moved to 1'); -}; - subtest 'constraints' => sub { my @bad_params = ( 'ABCD', @@ -107,4 +87,15 @@ subtest 'rotor box' => sub { }); }; +subtest 'ring-setting on real rotor' => sub { + my $r = Enigmatic::RotorBox->new->get('I'); + $r->ring_setting(1); + + my $out = 'EKMFLGDQVZNTOWYHXUSPAIBRCJ'->split(qr//); + $out->unshift($out->pop); + $out->each_value(sub{$_[0] =~ tr[A-Z][B-ZA]}); + + Test::Enigmatic::test_static_map($r,$out,'ring I moved to 1'); +}; + done_testing(); diff --git a/t/simple-enigma.t b/t/simple-enigma.t index b2bcbdd..889f0c0 100644 --- a/t/simple-enigma.t +++ b/t/simple-enigma.t @@ -1,6 +1,6 @@ #!perl use DAKKAR::p 'test'; - +use Test::Enigmatic; use Enigmatic::Machine; sub real_machine { @@ -13,11 +13,8 @@ sub real_machine { }); } -my $plaintext = 'this is a simple text to be encrypted by an enigma machine'->uc; -note "encrypt simple"; -my $ciphertext = real_machine->map_string($plaintext);note $ciphertext; -note "decrypt simple"; -my $check = real_machine->map_string($ciphertext);note $check; -$plaintext =~ s{\s+}{}g; -is($check,$plaintext, - 'round tripped'); +Test::Enigmatic::test_full_machine( + \&real_machine, + 'this is a simple text to be encrypted by an enigma machine'); + +done_testing(); |