summaryrefslogtreecommitdiff
path: root/t/lib/Test/Enigmatic.pm
blob: 644f8972ae49784b639b4f67431f015ae090701f (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
package Test::Enigmatic; 
use DAKKAR::p 'test';
 
sub test_static_map {
    my ($mapper,$out,$name) = @_;
 
    my @in = 'A'..'Z';
    my %map;@map{@in}=@$out;
 
    for my $c ('A' .. 'Z') {
        is($mapper->map($c),
           $map{$c},
           "$name on $c");
    }
}
 
 
sub test_full_machine {
    my ($factory,$input,$exp_output) = @_;
 
    $input =~ s{\s+}{}g;$input=$input->uc;
 
    my $output = $factory->()->map_string($input);
 
    note "output: $output";
 
    my $back = $factory->()->map_string($output);
 
    note "back: $back";
 
    is($back,
       $input,
       'round tripped');
    if ($exp_output) {
        $exp_output =~ s{\s+}{}g;$exp_output=$exp_output->uc;
        is($output,
           $exp_output,
           'got expected output');
    }
}
 
__END__
 
=head1 AUTHOR
 
Gianni Ceccarelli <dakkar@thenautilus.net>
 
=head1 COPYRIGHT AND LICENSE
 
This software is copyright (c) 2011 by Gianni Ceccarelli.
 
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, version 3.
 
=cut