Skip to content

Commit 995c411

Browse files
simple-cipher: add test for random keys
1 parent 4c90d91 commit 995c411

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ end}}
1616
end
1717
end}}
1818

19-
using Xunit;
20-
2119
public class {{ testClass }}
2220
{
2321
{{- for test in tests }}
@@ -31,6 +29,13 @@ public class {{ testClass }}
3129
Assert.Equal({{- test.expected | string.literal }}, sut.Decode({{ test | decode_arg }}));
3230
{{- else if test.property == "key" }}
3331
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);
3439
{{ end -}}
3540
}
3641
{{ 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)