summaryrefslogtreecommitdiff
path: root/t/rotors.t
blob: 509d88dbfc852a69548c0f34152145f87122b808 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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();