From 995c4111cef013e3c5515da166d89426128fea68 Mon Sep 17 00:00:00 2001 From: Erik Schierboom Date: Wed, 23 Apr 2025 14:28:08 +0200 Subject: [PATCH] simple-cipher: add test for random keys --- exercises/practice/simple-cipher/.meta/Generator.tpl | 9 +++++++-- exercises/practice/simple-cipher/SimpleCipherTests.cs | 7 +++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/exercises/practice/simple-cipher/.meta/Generator.tpl b/exercises/practice/simple-cipher/.meta/Generator.tpl index 930a028f84..a52c102301 100644 --- a/exercises/practice/simple-cipher/.meta/Generator.tpl +++ b/exercises/practice/simple-cipher/.meta/Generator.tpl @@ -16,8 +16,6 @@ end}} end end}} -using Xunit; - public class {{ testClass }} { {{- for test in tests }} @@ -31,6 +29,13 @@ public class {{ testClass }} Assert.Equal({{- test.expected | string.literal }}, sut.Decode({{ test | decode_arg }})); {{- else if test.property == "key" }} Assert.Matches({{- test.expected.match | string.literal }}, sut.Key); + } + + [Fact(Skip = "Remove this Skip property to run this test")] + public void Random_key_cipher_key_is_random() + { + var keys = Enumerable.Range(0, 1000).Select(_ => new SimpleCipher().Key).ToArray(); + Assert.InRange(keys.Distinct().Count(), keys.Length - 100, keys.Length); {{ end -}} } {{ end -}} diff --git a/exercises/practice/simple-cipher/SimpleCipherTests.cs b/exercises/practice/simple-cipher/SimpleCipherTests.cs index 096881b31e..51a3ccceb2 100644 --- a/exercises/practice/simple-cipher/SimpleCipherTests.cs +++ b/exercises/practice/simple-cipher/SimpleCipherTests.cs @@ -28,6 +28,13 @@ public void Random_key_cipher_key_is_made_only_of_lowercase_letters() Assert.Matches("^[a-z]+$", sut.Key); } + [Fact(Skip = "Remove this Skip property to run this test")] + public void Random_key_cipher_key_is_random() + { + var keys = Enumerable.Range(0, 1000).Select(_ => new SimpleCipher().Key).ToArray(); + Assert.InRange(keys.Distinct().Count(), keys.Length - 100, keys.Length); + } + [Fact(Skip = "Remove this Skip property to run this test")] public void Substitution_cipher_can_encode() {