Skip to content

Commit d7ceef1

Browse files
And-more-generators (#2361)
* alphametics: add generator * anagram: add generator * armstrong-numbers: add generator * Remove old generators * atbash-cipher: add generator [no important files changed]
1 parent 9d88508 commit d7ceef1

File tree

11 files changed

+120
-99
lines changed

11 files changed

+120
-99
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using Xunit;
4+
5+
public class AlphameticsTests
6+
{
7+
{{for test in tests}}
8+
[Fact{{if !for.first}}(Skip = "Remove this Skip property to run this test"){{end}}]
9+
public void {{test.methodName}}()
10+
{
11+
{{if test.expected}}
12+
var actual = Alphametics.Solve({{test.input.puzzle | string.literal}});
13+
var expected = new Dictionary<char, int>
14+
{
15+
{{for key in test.expected | object.keys}}
16+
['{{key}}'] = {{test.expected[key]}}{{if !for.last}},{{end}}
17+
{{end}}
18+
};
19+
Assert.Equal(expected, actual);
20+
{{else}}
21+
Assert.Throws<ArgumentException>(() => Alphametics.Solve({{test.input.puzzle | string.literal}}));
22+
{{end}}
23+
}
24+
{{end}}
25+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using Xunit;
2+
3+
public class AnagramTests
4+
{
5+
{{for test in tests}}
6+
[Fact{{if !for.first}}(Skip = "Remove this Skip property to run this test"){{end}}]
7+
public void {{test.methodName}}()
8+
{
9+
string[] candidates = {{test.input.candidates}};
10+
var sut = new Anagram({{test.input.subject | string.literal}});
11+
{{if test.expected.empty?}}
12+
Assert.Empty(sut.FindAnagrams(candidates));
13+
{{else}}
14+
string[] expected = {{test.expected}};
15+
Assert.Equal(expected, sut.FindAnagrams(candidates));
16+
{{end}}
17+
}
18+
{{end}}
19+
}

exercises/practice/anagram/.meta/tests.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ description = "detects anagrams using case-insensitive possible matches"
4646

4747
[7cc195ad-e3c7-44ee-9fd2-d3c344806a2c]
4848
description = "does not detect an anagram if the original word is repeated"
49+
include = false
50+
51+
[630abb71-a94e-4715-8395-179ec1df9f91]
52+
description = "does not detect an anagram if the original word is repeated"
53+
reimplements = "7cc195ad-e3c7-44ee-9fd2-d3c344806a2c"
4954

5055
[9878a1c9-d6ea-4235-ae51-3ea2befd6842]
5156
description = "anagrams must use all letters exactly once"
@@ -73,3 +78,9 @@ include = false
7378
[33d3f67e-fbb9-49d3-a90e-0beb00861da7]
7479
description = "words other than themselves can be anagrams"
7580
reimplements = "a0705568-628c-4b55-9798-82e4acde51ca"
81+
82+
[a6854f66-eec1-4afd-a137-62ef2870c051]
83+
description = "handles case of greek letters"
84+
85+
[fd3509e5-e3ba-409d-ac3d-a9ac84d13296]
86+
description = "different characters may have the same bytes"

exercises/practice/anagram/AnagramTests.cs

Lines changed: 41 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,136 +5,153 @@ public class AnagramTests
55
[Fact]
66
public void No_matches()
77
{
8-
var candidates = new[] { "hello", "world", "zombies", "pants" };
8+
string[] candidates = ["hello", "world", "zombies", "pants"];
99
var sut = new Anagram("diaper");
1010
Assert.Empty(sut.FindAnagrams(candidates));
1111
}
1212

1313
[Fact(Skip = "Remove this Skip property to run this test")]
1414
public void Detects_two_anagrams()
1515
{
16-
var candidates = new[] { "lemons", "cherry", "melons" };
16+
string[] candidates = ["lemons", "cherry", "melons"];
1717
var sut = new Anagram("solemn");
18-
var expected = new[] { "lemons", "melons" };
18+
string[] expected = ["lemons", "melons"];
1919
Assert.Equal(expected, sut.FindAnagrams(candidates));
2020
}
2121

2222
[Fact(Skip = "Remove this Skip property to run this test")]
2323
public void Does_not_detect_anagram_subsets()
2424
{
25-
var candidates = new[] { "dog", "goody" };
25+
string[] candidates = ["dog", "goody"];
2626
var sut = new Anagram("good");
2727
Assert.Empty(sut.FindAnagrams(candidates));
2828
}
2929

3030
[Fact(Skip = "Remove this Skip property to run this test")]
3131
public void Detects_anagram()
3232
{
33-
var candidates = new[] { "enlists", "google", "inlets", "banana" };
33+
string[] candidates = ["enlists", "google", "inlets", "banana"];
3434
var sut = new Anagram("listen");
35-
var expected = new[] { "inlets" };
35+
string[] expected = ["inlets"];
3636
Assert.Equal(expected, sut.FindAnagrams(candidates));
3737
}
3838

3939
[Fact(Skip = "Remove this Skip property to run this test")]
4040
public void Detects_three_anagrams()
4141
{
42-
var candidates = new[] { "gallery", "ballerina", "regally", "clergy", "largely", "leading" };
42+
string[] candidates = ["gallery", "ballerina", "regally", "clergy", "largely", "leading"];
4343
var sut = new Anagram("allergy");
44-
var expected = new[] { "gallery", "regally", "largely" };
44+
string[] expected = ["gallery", "regally", "largely"];
4545
Assert.Equal(expected, sut.FindAnagrams(candidates));
4646
}
4747

4848
[Fact(Skip = "Remove this Skip property to run this test")]
4949
public void Detects_multiple_anagrams_with_different_case()
5050
{
51-
var candidates = new[] { "Eons", "ONES" };
51+
string[] candidates = ["Eons", "ONES"];
5252
var sut = new Anagram("nose");
53-
var expected = new[] { "Eons", "ONES" };
53+
string[] expected = ["Eons", "ONES"];
5454
Assert.Equal(expected, sut.FindAnagrams(candidates));
5555
}
5656

5757
[Fact(Skip = "Remove this Skip property to run this test")]
5858
public void Does_not_detect_non_anagrams_with_identical_checksum()
5959
{
60-
var candidates = new[] { "last" };
60+
string[] candidates = ["last"];
6161
var sut = new Anagram("mass");
6262
Assert.Empty(sut.FindAnagrams(candidates));
6363
}
6464

6565
[Fact(Skip = "Remove this Skip property to run this test")]
6666
public void Detects_anagrams_case_insensitively()
6767
{
68-
var candidates = new[] { "cashregister", "Carthorse", "radishes" };
68+
string[] candidates = ["cashregister", "Carthorse", "radishes"];
6969
var sut = new Anagram("Orchestra");
70-
var expected = new[] { "Carthorse" };
70+
string[] expected = ["Carthorse"];
7171
Assert.Equal(expected, sut.FindAnagrams(candidates));
7272
}
7373

7474
[Fact(Skip = "Remove this Skip property to run this test")]
7575
public void Detects_anagrams_using_case_insensitive_subject()
7676
{
77-
var candidates = new[] { "cashregister", "carthorse", "radishes" };
77+
string[] candidates = ["cashregister", "carthorse", "radishes"];
7878
var sut = new Anagram("Orchestra");
79-
var expected = new[] { "carthorse" };
79+
string[] expected = ["carthorse"];
8080
Assert.Equal(expected, sut.FindAnagrams(candidates));
8181
}
8282

8383
[Fact(Skip = "Remove this Skip property to run this test")]
8484
public void Detects_anagrams_using_case_insensitive_possible_matches()
8585
{
86-
var candidates = new[] { "cashregister", "Carthorse", "radishes" };
86+
string[] candidates = ["cashregister", "Carthorse", "radishes"];
8787
var sut = new Anagram("orchestra");
88-
var expected = new[] { "Carthorse" };
88+
string[] expected = ["Carthorse"];
8989
Assert.Equal(expected, sut.FindAnagrams(candidates));
9090
}
9191

9292
[Fact(Skip = "Remove this Skip property to run this test")]
9393
public void Does_not_detect_an_anagram_if_the_original_word_is_repeated()
9494
{
95-
var candidates = new[] { "go Go GO" };
95+
string[] candidates = ["goGoGO"];
9696
var sut = new Anagram("go");
9797
Assert.Empty(sut.FindAnagrams(candidates));
9898
}
9999

100100
[Fact(Skip = "Remove this Skip property to run this test")]
101101
public void Anagrams_must_use_all_letters_exactly_once()
102102
{
103-
var candidates = new[] { "patter" };
103+
string[] candidates = ["patter"];
104104
var sut = new Anagram("tapper");
105105
Assert.Empty(sut.FindAnagrams(candidates));
106106
}
107107

108108
[Fact(Skip = "Remove this Skip property to run this test")]
109109
public void Words_are_not_anagrams_of_themselves()
110110
{
111-
var candidates = new[] { "BANANA" };
111+
string[] candidates = ["BANANA"];
112112
var sut = new Anagram("BANANA");
113113
Assert.Empty(sut.FindAnagrams(candidates));
114114
}
115115

116116
[Fact(Skip = "Remove this Skip property to run this test")]
117117
public void Words_are_not_anagrams_of_themselves_even_if_letter_case_is_partially_different()
118118
{
119-
var candidates = new[] { "Banana" };
119+
string[] candidates = ["Banana"];
120120
var sut = new Anagram("BANANA");
121121
Assert.Empty(sut.FindAnagrams(candidates));
122122
}
123123

124124
[Fact(Skip = "Remove this Skip property to run this test")]
125125
public void Words_are_not_anagrams_of_themselves_even_if_letter_case_is_completely_different()
126126
{
127-
var candidates = new[] { "banana" };
127+
string[] candidates = ["banana"];
128128
var sut = new Anagram("BANANA");
129129
Assert.Empty(sut.FindAnagrams(candidates));
130130
}
131131

132132
[Fact(Skip = "Remove this Skip property to run this test")]
133133
public void Words_other_than_themselves_can_be_anagrams()
134134
{
135-
var candidates = new[] { "LISTEN", "Silent" };
135+
string[] candidates = ["LISTEN", "Silent"];
136136
var sut = new Anagram("LISTEN");
137-
var expected = new[] { "Silent" };
137+
string[] expected = ["Silent"];
138138
Assert.Equal(expected, sut.FindAnagrams(candidates));
139139
}
140+
141+
[Fact(Skip = "Remove this Skip property to run this test")]
142+
public void Handles_case_of_greek_letters()
143+
{
144+
string[] candidates = ["ΒΓΑ", "ΒΓΔ", "γβα", "αβγ"];
145+
var sut = new Anagram("ΑΒΓ");
146+
string[] expected = ["ΒΓΑ", "γβα"];
147+
Assert.Equal(expected, sut.FindAnagrams(candidates));
148+
}
149+
150+
[Fact(Skip = "Remove this Skip property to run this test")]
151+
public void Different_characters_may_have_the_same_bytes()
152+
{
153+
string[] candidates = ["€a"];
154+
var sut = new Anagram("a⬂");
155+
Assert.Empty(sut.FindAnagrams(candidates));
156+
}
140157
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using Xunit;
2+
3+
public class ArmstrongNumbersTests
4+
{
5+
{{for test in tests}}
6+
[Fact{{if !for.first}}(Skip = "Remove this Skip property to run this test"){{end}}]
7+
public void {{test.methodName}}()
8+
{
9+
Assert.{{test.expected ? "True" : "False"}}(ArmstrongNumbers.IsArmstrongNumber({{test.input.number}}));
10+
}
11+
{{end}}
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using Xunit;
2+
3+
public class AtbashCipherTests
4+
{
5+
{{for test in tests}}
6+
[Fact{{if !for.first}}(Skip = "Remove this Skip property to run this test"){{end}}]
7+
public void {{test.shortMethodName}}()
8+
{
9+
Assert.Equal({{test.expected | string.literal}}, AtbashCipher.{{test.property | string.capitalize}}({{test.input.phrase | string.literal}}));
10+
}
11+
{{end}}
12+
}

generators.deprecated/Exercises/Generators/AllYourBase.cs

Lines changed: 0 additions & 23 deletions
This file was deleted.

generators.deprecated/Exercises/Generators/Alphametics.cs

Lines changed: 0 additions & 28 deletions
This file was deleted.

generators.deprecated/Exercises/Generators/Anagram.cs

Lines changed: 0 additions & 14 deletions
This file was deleted.

generators.deprecated/Exercises/Generators/ArmstrongNumbers.cs

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)