diff --git a/exercises/practice/alphametics/.meta/Generator.tpl b/exercises/practice/alphametics/.meta/Generator.tpl new file mode 100644 index 0000000000..45695ebef9 --- /dev/null +++ b/exercises/practice/alphametics/.meta/Generator.tpl @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using Xunit; + +public class AlphameticsTests +{ + {{for test in tests}} + [Fact{{if !for.first}}(Skip = "Remove this Skip property to run this test"){{end}}] + public void {{test.methodName}}() + { + {{if test.expected}} + var actual = Alphametics.Solve({{test.input.puzzle | string.literal}}); + var expected = new Dictionary + { + {{for key in test.expected | object.keys}} + ['{{key}}'] = {{test.expected[key]}}{{if !for.last}},{{end}} + {{end}} + }; + Assert.Equal(expected, actual); + {{else}} + Assert.Throws(() => Alphametics.Solve({{test.input.puzzle | string.literal}})); + {{end}} + } + {{end}} +} diff --git a/exercises/practice/anagram/.meta/Generator.tpl b/exercises/practice/anagram/.meta/Generator.tpl new file mode 100644 index 0000000000..53d4277f33 --- /dev/null +++ b/exercises/practice/anagram/.meta/Generator.tpl @@ -0,0 +1,19 @@ +using Xunit; + +public class AnagramTests +{ + {{for test in tests}} + [Fact{{if !for.first}}(Skip = "Remove this Skip property to run this test"){{end}}] + public void {{test.methodName}}() + { + string[] candidates = {{test.input.candidates}}; + var sut = new Anagram({{test.input.subject | string.literal}}); + {{if test.expected.empty?}} + Assert.Empty(sut.FindAnagrams(candidates)); + {{else}} + string[] expected = {{test.expected}}; + Assert.Equal(expected, sut.FindAnagrams(candidates)); + {{end}} + } + {{end}} +} diff --git a/exercises/practice/anagram/.meta/tests.toml b/exercises/practice/anagram/.meta/tests.toml index 8a3708bbf9..4d90562705 100644 --- a/exercises/practice/anagram/.meta/tests.toml +++ b/exercises/practice/anagram/.meta/tests.toml @@ -46,6 +46,11 @@ description = "detects anagrams using case-insensitive possible matches" [7cc195ad-e3c7-44ee-9fd2-d3c344806a2c] description = "does not detect an anagram if the original word is repeated" +include = false + +[630abb71-a94e-4715-8395-179ec1df9f91] +description = "does not detect an anagram if the original word is repeated" +reimplements = "7cc195ad-e3c7-44ee-9fd2-d3c344806a2c" [9878a1c9-d6ea-4235-ae51-3ea2befd6842] description = "anagrams must use all letters exactly once" @@ -73,3 +78,9 @@ include = false [33d3f67e-fbb9-49d3-a90e-0beb00861da7] description = "words other than themselves can be anagrams" reimplements = "a0705568-628c-4b55-9798-82e4acde51ca" + +[a6854f66-eec1-4afd-a137-62ef2870c051] +description = "handles case of greek letters" + +[fd3509e5-e3ba-409d-ac3d-a9ac84d13296] +description = "different characters may have the same bytes" diff --git a/exercises/practice/anagram/AnagramTests.cs b/exercises/practice/anagram/AnagramTests.cs index 3cf5e3cbc7..d99ad5814c 100644 --- a/exercises/practice/anagram/AnagramTests.cs +++ b/exercises/practice/anagram/AnagramTests.cs @@ -5,7 +5,7 @@ public class AnagramTests [Fact] public void No_matches() { - var candidates = new[] { "hello", "world", "zombies", "pants" }; + string[] candidates = ["hello", "world", "zombies", "pants"]; var sut = new Anagram("diaper"); Assert.Empty(sut.FindAnagrams(candidates)); } @@ -13,16 +13,16 @@ public void No_matches() [Fact(Skip = "Remove this Skip property to run this test")] public void Detects_two_anagrams() { - var candidates = new[] { "lemons", "cherry", "melons" }; + string[] candidates = ["lemons", "cherry", "melons"]; var sut = new Anagram("solemn"); - var expected = new[] { "lemons", "melons" }; + string[] expected = ["lemons", "melons"]; Assert.Equal(expected, sut.FindAnagrams(candidates)); } [Fact(Skip = "Remove this Skip property to run this test")] public void Does_not_detect_anagram_subsets() { - var candidates = new[] { "dog", "goody" }; + string[] candidates = ["dog", "goody"]; var sut = new Anagram("good"); Assert.Empty(sut.FindAnagrams(candidates)); } @@ -30,34 +30,34 @@ public void Does_not_detect_anagram_subsets() [Fact(Skip = "Remove this Skip property to run this test")] public void Detects_anagram() { - var candidates = new[] { "enlists", "google", "inlets", "banana" }; + string[] candidates = ["enlists", "google", "inlets", "banana"]; var sut = new Anagram("listen"); - var expected = new[] { "inlets" }; + string[] expected = ["inlets"]; Assert.Equal(expected, sut.FindAnagrams(candidates)); } [Fact(Skip = "Remove this Skip property to run this test")] public void Detects_three_anagrams() { - var candidates = new[] { "gallery", "ballerina", "regally", "clergy", "largely", "leading" }; + string[] candidates = ["gallery", "ballerina", "regally", "clergy", "largely", "leading"]; var sut = new Anagram("allergy"); - var expected = new[] { "gallery", "regally", "largely" }; + string[] expected = ["gallery", "regally", "largely"]; Assert.Equal(expected, sut.FindAnagrams(candidates)); } [Fact(Skip = "Remove this Skip property to run this test")] public void Detects_multiple_anagrams_with_different_case() { - var candidates = new[] { "Eons", "ONES" }; + string[] candidates = ["Eons", "ONES"]; var sut = new Anagram("nose"); - var expected = new[] { "Eons", "ONES" }; + string[] expected = ["Eons", "ONES"]; Assert.Equal(expected, sut.FindAnagrams(candidates)); } [Fact(Skip = "Remove this Skip property to run this test")] public void Does_not_detect_non_anagrams_with_identical_checksum() { - var candidates = new[] { "last" }; + string[] candidates = ["last"]; var sut = new Anagram("mass"); Assert.Empty(sut.FindAnagrams(candidates)); } @@ -65,34 +65,34 @@ public void Does_not_detect_non_anagrams_with_identical_checksum() [Fact(Skip = "Remove this Skip property to run this test")] public void Detects_anagrams_case_insensitively() { - var candidates = new[] { "cashregister", "Carthorse", "radishes" }; + string[] candidates = ["cashregister", "Carthorse", "radishes"]; var sut = new Anagram("Orchestra"); - var expected = new[] { "Carthorse" }; + string[] expected = ["Carthorse"]; Assert.Equal(expected, sut.FindAnagrams(candidates)); } [Fact(Skip = "Remove this Skip property to run this test")] public void Detects_anagrams_using_case_insensitive_subject() { - var candidates = new[] { "cashregister", "carthorse", "radishes" }; + string[] candidates = ["cashregister", "carthorse", "radishes"]; var sut = new Anagram("Orchestra"); - var expected = new[] { "carthorse" }; + string[] expected = ["carthorse"]; Assert.Equal(expected, sut.FindAnagrams(candidates)); } [Fact(Skip = "Remove this Skip property to run this test")] public void Detects_anagrams_using_case_insensitive_possible_matches() { - var candidates = new[] { "cashregister", "Carthorse", "radishes" }; + string[] candidates = ["cashregister", "Carthorse", "radishes"]; var sut = new Anagram("orchestra"); - var expected = new[] { "Carthorse" }; + string[] expected = ["Carthorse"]; Assert.Equal(expected, sut.FindAnagrams(candidates)); } [Fact(Skip = "Remove this Skip property to run this test")] public void Does_not_detect_an_anagram_if_the_original_word_is_repeated() { - var candidates = new[] { "go Go GO" }; + string[] candidates = ["goGoGO"]; var sut = new Anagram("go"); Assert.Empty(sut.FindAnagrams(candidates)); } @@ -100,7 +100,7 @@ public void Does_not_detect_an_anagram_if_the_original_word_is_repeated() [Fact(Skip = "Remove this Skip property to run this test")] public void Anagrams_must_use_all_letters_exactly_once() { - var candidates = new[] { "patter" }; + string[] candidates = ["patter"]; var sut = new Anagram("tapper"); Assert.Empty(sut.FindAnagrams(candidates)); } @@ -108,7 +108,7 @@ public void Anagrams_must_use_all_letters_exactly_once() [Fact(Skip = "Remove this Skip property to run this test")] public void Words_are_not_anagrams_of_themselves() { - var candidates = new[] { "BANANA" }; + string[] candidates = ["BANANA"]; var sut = new Anagram("BANANA"); Assert.Empty(sut.FindAnagrams(candidates)); } @@ -116,7 +116,7 @@ public void Words_are_not_anagrams_of_themselves() [Fact(Skip = "Remove this Skip property to run this test")] public void Words_are_not_anagrams_of_themselves_even_if_letter_case_is_partially_different() { - var candidates = new[] { "Banana" }; + string[] candidates = ["Banana"]; var sut = new Anagram("BANANA"); Assert.Empty(sut.FindAnagrams(candidates)); } @@ -124,7 +124,7 @@ public void Words_are_not_anagrams_of_themselves_even_if_letter_case_is_partiall [Fact(Skip = "Remove this Skip property to run this test")] public void Words_are_not_anagrams_of_themselves_even_if_letter_case_is_completely_different() { - var candidates = new[] { "banana" }; + string[] candidates = ["banana"]; var sut = new Anagram("BANANA"); Assert.Empty(sut.FindAnagrams(candidates)); } @@ -132,9 +132,26 @@ public void Words_are_not_anagrams_of_themselves_even_if_letter_case_is_complete [Fact(Skip = "Remove this Skip property to run this test")] public void Words_other_than_themselves_can_be_anagrams() { - var candidates = new[] { "LISTEN", "Silent" }; + string[] candidates = ["LISTEN", "Silent"]; var sut = new Anagram("LISTEN"); - var expected = new[] { "Silent" }; + string[] expected = ["Silent"]; Assert.Equal(expected, sut.FindAnagrams(candidates)); } + + [Fact(Skip = "Remove this Skip property to run this test")] + public void Handles_case_of_greek_letters() + { + string[] candidates = ["ΒΓΑ", "ΒΓΔ", "γβα", "αβγ"]; + var sut = new Anagram("ΑΒΓ"); + string[] expected = ["ΒΓΑ", "γβα"]; + Assert.Equal(expected, sut.FindAnagrams(candidates)); + } + + [Fact(Skip = "Remove this Skip property to run this test")] + public void Different_characters_may_have_the_same_bytes() + { + string[] candidates = ["€a"]; + var sut = new Anagram("a⬂"); + Assert.Empty(sut.FindAnagrams(candidates)); + } } diff --git a/exercises/practice/armstrong-numbers/.meta/Generator.tpl b/exercises/practice/armstrong-numbers/.meta/Generator.tpl new file mode 100644 index 0000000000..57a683a92a --- /dev/null +++ b/exercises/practice/armstrong-numbers/.meta/Generator.tpl @@ -0,0 +1,12 @@ +using Xunit; + +public class ArmstrongNumbersTests +{ + {{for test in tests}} + [Fact{{if !for.first}}(Skip = "Remove this Skip property to run this test"){{end}}] + public void {{test.methodName}}() + { + Assert.{{test.expected ? "True" : "False"}}(ArmstrongNumbers.IsArmstrongNumber({{test.input.number}})); + } + {{end}} +} diff --git a/exercises/practice/atbash-cipher/.meta/Generator.tpl b/exercises/practice/atbash-cipher/.meta/Generator.tpl new file mode 100644 index 0000000000..3698894da0 --- /dev/null +++ b/exercises/practice/atbash-cipher/.meta/Generator.tpl @@ -0,0 +1,12 @@ +using Xunit; + +public class AtbashCipherTests +{ + {{for test in tests}} + [Fact{{if !for.first}}(Skip = "Remove this Skip property to run this test"){{end}}] + public void {{test.shortMethodName}}() + { + Assert.Equal({{test.expected | string.literal}}, AtbashCipher.{{test.property | string.capitalize}}({{test.input.phrase | string.literal}})); + } + {{end}} +} diff --git a/generators.deprecated/Exercises/Generators/AllYourBase.cs b/generators.deprecated/Exercises/Generators/AllYourBase.cs deleted file mode 100644 index 3cf7eceef8..0000000000 --- a/generators.deprecated/Exercises/Generators/AllYourBase.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System; -using System.Collections.Generic; -using Exercism.CSharp.Output; -using Newtonsoft.Json.Linq; - -namespace Exercism.CSharp.Exercises.Generators; - -internal class AllYourBase : ExerciseGenerator -{ - protected override void UpdateTestMethod(TestMethod testMethod) - { - if (testMethod.Input["digits"] is JArray) - testMethod.Input["digits"] = Array.Empty(); - - if (testMethod.ExpectedIsError) - testMethod.ExceptionThrown = typeof(ArgumentException); - - testMethod.UseVariablesForInput = true; - testMethod.UseVariableForExpected = true; - } - - protected override void UpdateNamespaces(ISet namespaces) => namespaces.Add(typeof(Array).Namespace!); -} \ No newline at end of file diff --git a/generators.deprecated/Exercises/Generators/Alphametics.cs b/generators.deprecated/Exercises/Generators/Alphametics.cs deleted file mode 100644 index 1fe876e322..0000000000 --- a/generators.deprecated/Exercises/Generators/Alphametics.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using Exercism.CSharp.Output; - -namespace Exercism.CSharp.Exercises.Generators; - -internal class Alphametics : ExerciseGenerator -{ - protected override void UpdateTestMethod(TestMethod testMethod) - { - testMethod.UseVariableForExpected = true; - testMethod.UseVariableForTested = true; - - if (testMethod.Expected == null) - testMethod.ExceptionThrown = typeof(ArgumentException); - else - testMethod.Expected = ConvertExpected(testMethod); - } - - private static dynamic ConvertExpected(TestMethod testMethod) - { - Dictionary expected = testMethod.Expected!; - return expected.ToDictionary(kv => kv.Key[0], kv => Convert.ToInt32(kv.Value)); - } - - protected override void UpdateNamespaces(ISet namespaces) => namespaces.Add(typeof(Dictionary).Namespace!); -} \ No newline at end of file diff --git a/generators.deprecated/Exercises/Generators/Anagram.cs b/generators.deprecated/Exercises/Generators/Anagram.cs deleted file mode 100644 index f4829c888c..0000000000 --- a/generators.deprecated/Exercises/Generators/Anagram.cs +++ /dev/null @@ -1,14 +0,0 @@ -using Exercism.CSharp.Output; - -namespace Exercism.CSharp.Exercises.Generators; - -internal class Anagram : ExerciseGenerator -{ - protected override void UpdateTestMethod(TestMethod testMethod) - { - testMethod.UseVariablesForInput = true; - testMethod.UseVariableForExpected = true; - testMethod.ConstructorInputParameters = new[] { "subject" }; - testMethod.TestedMethodType = TestedMethodType.InstanceMethod; - } -} \ No newline at end of file diff --git a/generators.deprecated/Exercises/Generators/ArmstrongNumbers.cs b/generators.deprecated/Exercises/Generators/ArmstrongNumbers.cs deleted file mode 100644 index 5956bdc25f..0000000000 --- a/generators.deprecated/Exercises/Generators/ArmstrongNumbers.cs +++ /dev/null @@ -1,5 +0,0 @@ -namespace Exercism.CSharp.Exercises.Generators; - -internal class ArmstrongNumbers : ExerciseGenerator -{ -} \ No newline at end of file diff --git a/generators.deprecated/Exercises/Generators/AtbashCipher.cs b/generators.deprecated/Exercises/Generators/AtbashCipher.cs deleted file mode 100644 index 4da1082c72..0000000000 --- a/generators.deprecated/Exercises/Generators/AtbashCipher.cs +++ /dev/null @@ -1,5 +0,0 @@ -namespace Exercism.CSharp.Exercises.Generators; - -internal class AtbashCipher : ExerciseGenerator -{ -} \ No newline at end of file