Skip to content

Commit e0bdee9

Browse files
simple-cipher: add test for random keys (#2415)
1 parent 13fcb10 commit e0bdee9

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

exercises/practice/simple-cipher/.meta/Generator.tpl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ public class {{ testClass }}
2929
Assert.Equal({{- test.expected | string.literal }}, sut.Decode({{ test | decode_arg }}));
3030
{{- else if test.property == "key" }}
3131
Assert.Matches({{- test.expected.match | string.literal }}, sut.Key);
32+
}
33+
34+
[Fact(Skip = "Remove this Skip property to run this test")]
35+
public void Random_key_cipher_key_is_random()
36+
{
37+
var keys = Enumerable.Range(0, 1000).Select(_ => new SimpleCipher().Key).ToArray();
38+
Assert.InRange(keys.Distinct().Count(), keys.Length - 100, keys.Length);
3239
{{ end -}}
3340
}
3441
{{ end -}}

exercises/practice/simple-cipher/SimpleCipherTests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ public void Random_key_cipher_key_is_made_only_of_lowercase_letters()
2828
Assert.Matches("^[a-z]+$", sut.Key);
2929
}
3030

31+
[Fact(Skip = "Remove this Skip property to run this test")]
32+
public void Random_key_cipher_key_is_random()
33+
{
34+
var keys = Enumerable.Range(0, 1000).Select(_ => new SimpleCipher().Key).ToArray();
35+
Assert.InRange(keys.Distinct().Count(), keys.Length - 100, keys.Length);
36+
}
37+
3138
[Fact(Skip = "Remove this Skip property to run this test")]
3239
public void Substitution_cipher_can_encode()
3340
{

0 commit comments

Comments
 (0)