Skip to content

Commit 2c5cbdc

Browse files
committed
Generate full Perl tests for simple-cipher
1 parent 4db330d commit 2c5cbdc

File tree

11 files changed

+278
-202
lines changed

11 files changed

+278
-202
lines changed

exercises/practice/simple-cipher/.meta/solutions/Cipher.pm

Lines changed: 0 additions & 60 deletions
This file was deleted.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package SimpleCipher;
2+
3+
use Moo;
4+
use feature qw<say>;
5+
6+
has key => (
7+
is => 'lazy',
8+
);
9+
10+
sub encode {
11+
my ($self) = @_;
12+
return undef;
13+
}
14+
15+
sub decode {
16+
my ($self) = @_;
17+
return undef;
18+
}
19+
20+
sub _build_key {
21+
return undef;
22+
}
23+
24+
1;

exercises/practice/simple-cipher/.meta/solutions/cipher.t

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
requires 'Moo';
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../simple-cipher.t
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
methods: key encode decode
2+
moo: true
3+
tests: |
4+
my $cipher;
5+
properties:
6+
key:
7+
test: |-
8+
use Data::Dmp;
9+
sprintf(<<~'END', $case->{expected}{match}, dmp($case->{description}));
10+
$cipher = SimpleCipher->new;
11+
like(
12+
$cipher->key,
13+
qr/%s/,
14+
%s,
15+
);
16+
END
17+
18+
encode:
19+
test: |-
20+
use Data::Dmp;
21+
use List::Util qw<any>;
22+
if ($case->{input}{key}) {
23+
sprintf(<<~'END', map {dmp($_)} @{$case->{input}}{qw<key plaintext>}, @{$case}{qw<expected description>});
24+
$cipher = SimpleCipher->new(key => %s);
25+
is(
26+
$cipher->encode(%s),
27+
%s,
28+
%s,
29+
);
30+
END
31+
}
32+
else {
33+
sprintf(<<~'END', dmp($case->{input}{plaintext}), length($case->{input}{plaintext}), dmp($case->{description}));
34+
$cipher = SimpleCipher->new;
35+
is(
36+
$cipher->encode(%s),
37+
substr( $cipher->key, 0, %u ),
38+
%s,
39+
);
40+
END
41+
}
42+
43+
decode:
44+
test: |-
45+
use Data::Dmp;
46+
use List::Util qw<any>;
47+
if ($case->{input}{key}) {
48+
if ($case->{input}{plaintext}) {
49+
sprintf(<<~'END', map {dmp($_)} @{$case->{input}}{qw<key plaintext>}, @{$case}{qw<expected description>});
50+
$cipher = SimpleCipher->new( key => %s );
51+
is(
52+
$cipher->decode($cipher->encode(%s)),
53+
%s,
54+
%s,
55+
);
56+
END
57+
}
58+
else {
59+
sprintf(<<~'END', map {dmp($_)} @{$case->{input}}{qw<key ciphertext>}, @{$case}{qw<expected description>});
60+
$cipher = SimpleCipher->new( key => %s );
61+
is(
62+
$cipher->decode(%s),
63+
%s,
64+
%s,
65+
);
66+
END
67+
}
68+
}
69+
elsif ($case->{input}{plaintext}) {
70+
sprintf(<<~'END', map {dmp($_)} $case->{input}{plaintext}, @{$case}{qw<expected description>});
71+
$cipher = SimpleCipher->new;
72+
is(
73+
$cipher->decode($cipher->encode(%s)),
74+
%s,
75+
%s,
76+
);
77+
END
78+
}
79+
else {
80+
sprintf(<<~'END', length($case->{expected}), map {dmp($_)} @{$case}{qw<expected description>});
81+
$cipher = SimpleCipher->new;
82+
is(
83+
$cipher->decode( substr( $cipher->key, 0, %u ) ),
84+
%s,
85+
%s,
86+
);
87+
END
88+
}
89+
90+
example: |-
91+
has key => (
92+
is => 'lazy',
93+
);
94+
95+
sub encode {
96+
my ($self) = @_;
97+
return undef;
98+
}
99+
100+
sub decode {
101+
my ($self) = @_;
102+
return undef;
103+
}
104+
105+
sub _build_key {
106+
return undef;
107+
}
108+
109+
stub: |-
110+
has key => (
111+
is => 'lazy',
112+
);
113+
114+
sub encode {
115+
my ($self) = @_;
116+
return undef;
117+
}
118+
119+
sub decode {
120+
my ($self) = @_;
121+
return undef;
122+
}
123+
124+
sub _build_key {
125+
return undef;
126+
}

exercises/practice/simple-cipher/Cipher.pm

Lines changed: 0 additions & 24 deletions
This file was deleted.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package SimpleCipher;
2+
3+
use Moo;
4+
use feature qw<say>;
5+
6+
has key => (
7+
is => 'lazy',
8+
);
9+
10+
sub encode {
11+
my ($self) = @_;
12+
return undef;
13+
}
14+
15+
sub decode {
16+
my ($self) = @_;
17+
return undef;
18+
}
19+
20+
sub _build_key {
21+
return undef;
22+
}
23+
24+
1;

exercises/practice/simple-cipher/cipher.t

Lines changed: 0 additions & 117 deletions
This file was deleted.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
recommends 'Moo'; # https://perldoc.pl/Moo
2+
suggests 'Mo'; # https://perldoc.pl/Mo
3+
suggests 'Moose'; # https://perldoc.pl/Moose
4+
suggests 'Object::Pad'; # https://perldoc.pl/Object::Pad
5+
suggests 'Class::Tiny'; # https://perldoc.pl/Class::Tiny#Why-this-instead-of-Moose-or-Moo?

0 commit comments

Comments
 (0)