Skip to content

Commit f2c700c

Browse files
More templates (#2355)
* affine-cipher: add template * allergies: add template * strain: add template * sublist: add template [no important files changed] * darts: add template * triangle: add template * Remove deprecated
1 parent d504da2 commit f2c700c

File tree

14 files changed

+250
-175
lines changed

14 files changed

+250
-175
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System;
2+
using Xunit;
3+
4+
public class AffineCipherTests
5+
{
6+
{{#test_cases_by_property.encode}}
7+
[Fact{{#unless @first}}(Skip = "Remove this Skip property to run this test"){{/unless}}]
8+
public void {{short_test_method_name}}()
9+
{
10+
{{#if expected.error}}
11+
Assert.Throws<ArgumentException>(() => AffineCipher.Encode({{lit input.phrase}}, {{input.key.a}}, {{input.key.b}}));
12+
{{else}}
13+
Assert.Equal({{lit expected}}, AffineCipher.Encode({{lit input.phrase}}, {{input.key.a}}, {{input.key.b}}));
14+
{{/if}}
15+
}
16+
{{/test_cases_by_property.encode}}
17+
18+
{{#test_cases_by_property.decode}}
19+
[Fact(Skip = "Remove this Skip property to run this test")]
20+
public void {{short_test_method_name}}()
21+
{
22+
{{#if expected.error}}
23+
Assert.Throws<ArgumentException>(() => AffineCipher.Decode({{lit input.phrase}}, {{input.key.a}}, {{input.key.b}}));
24+
{{else}}
25+
Assert.Equal({{lit expected}}, AffineCipher.Decode({{lit input.phrase}}, {{input.key.a}}, {{input.key.b}}));
26+
{{/if}}
27+
}
28+
{{/test_cases_by_property.decode}}
29+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using Xunit;
2+
3+
public class AllergiesTests
4+
{
5+
{{#test_cases_by_property.allergicTo}}
6+
[Fact{{#unless @first}}(Skip = "Remove this Skip property to run this test"){{/unless}}]
7+
public void {{test_method_name}}()
8+
{
9+
var sut = new Allergies({{input.score}});
10+
Assert.{{expected}}(sut.IsAllergicTo(Allergen.{{Capitalize input.item}}));
11+
}
12+
{{/test_cases_by_property.allergicTo}}
13+
14+
{{#test_cases_by_property.list}}
15+
[Fact(Skip = "Remove this Skip property to run this test")]
16+
public void {{test_method_name}}()
17+
{
18+
var sut = new Allergies({{input.score}});
19+
{{#isempty expected}}
20+
Assert.Empty(sut.List());
21+
{{else}}
22+
Allergen[] expected = [{{#each ../expected}}Allergen.{{Capitalize .}}{{#unless @last}},{{/unless}}{{/each}}];
23+
Assert.Equal(expected, sut.List());
24+
{{/isempty}}
25+
}
26+
{{/test_cases_by_property.list}}
27+
}

exercises/practice/allergies/AllergiesTests.cs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -283,81 +283,81 @@ public void Testing_for_cats_allergy_allergic_to_everything()
283283
}
284284

285285
[Fact(Skip = "Remove this Skip property to run this test")]
286-
public void No_allergies()
286+
public void List_when_no_allergies()
287287
{
288288
var sut = new Allergies(0);
289289
Assert.Empty(sut.List());
290290
}
291291

292292
[Fact(Skip = "Remove this Skip property to run this test")]
293-
public void Just_eggs()
293+
public void List_when_just_eggs()
294294
{
295295
var sut = new Allergies(1);
296-
var expected = new[] { Allergen.Eggs };
296+
Allergen[] expected = [Allergen.Eggs];
297297
Assert.Equal(expected, sut.List());
298298
}
299299

300300
[Fact(Skip = "Remove this Skip property to run this test")]
301-
public void Just_peanuts()
301+
public void List_when_just_peanuts()
302302
{
303303
var sut = new Allergies(2);
304-
var expected = new[] { Allergen.Peanuts };
304+
Allergen[] expected = [Allergen.Peanuts];
305305
Assert.Equal(expected, sut.List());
306306
}
307307

308308
[Fact(Skip = "Remove this Skip property to run this test")]
309-
public void Just_strawberries()
309+
public void List_when_just_strawberries()
310310
{
311311
var sut = new Allergies(8);
312-
var expected = new[] { Allergen.Strawberries };
312+
Allergen[] expected = [Allergen.Strawberries];
313313
Assert.Equal(expected, sut.List());
314314
}
315315

316316
[Fact(Skip = "Remove this Skip property to run this test")]
317-
public void Eggs_and_peanuts()
317+
public void List_when_eggs_and_peanuts()
318318
{
319319
var sut = new Allergies(3);
320-
var expected = new[] { Allergen.Eggs, Allergen.Peanuts };
320+
Allergen[] expected = [Allergen.Eggs, Allergen.Peanuts];
321321
Assert.Equal(expected, sut.List());
322322
}
323323

324324
[Fact(Skip = "Remove this Skip property to run this test")]
325-
public void More_than_eggs_but_not_peanuts()
325+
public void List_when_more_than_eggs_but_not_peanuts()
326326
{
327327
var sut = new Allergies(5);
328-
var expected = new[] { Allergen.Eggs, Allergen.Shellfish };
328+
Allergen[] expected = [Allergen.Eggs, Allergen.Shellfish];
329329
Assert.Equal(expected, sut.List());
330330
}
331331

332332
[Fact(Skip = "Remove this Skip property to run this test")]
333-
public void Lots_of_stuff()
333+
public void List_when_lots_of_stuff()
334334
{
335335
var sut = new Allergies(248);
336-
var expected = new[] { Allergen.Strawberries, Allergen.Tomatoes, Allergen.Chocolate, Allergen.Pollen, Allergen.Cats };
336+
Allergen[] expected = [Allergen.Strawberries, Allergen.Tomatoes, Allergen.Chocolate, Allergen.Pollen, Allergen.Cats];
337337
Assert.Equal(expected, sut.List());
338338
}
339339

340340
[Fact(Skip = "Remove this Skip property to run this test")]
341-
public void Everything()
341+
public void List_when_everything()
342342
{
343343
var sut = new Allergies(255);
344-
var expected = new[] { Allergen.Eggs, Allergen.Peanuts, Allergen.Shellfish, Allergen.Strawberries, Allergen.Tomatoes, Allergen.Chocolate, Allergen.Pollen, Allergen.Cats };
344+
Allergen[] expected = [Allergen.Eggs, Allergen.Peanuts, Allergen.Shellfish, Allergen.Strawberries, Allergen.Tomatoes, Allergen.Chocolate, Allergen.Pollen, Allergen.Cats];
345345
Assert.Equal(expected, sut.List());
346346
}
347347

348348
[Fact(Skip = "Remove this Skip property to run this test")]
349-
public void No_allergen_score_parts()
349+
public void List_when_no_allergen_score_parts()
350350
{
351351
var sut = new Allergies(509);
352-
var expected = new[] { Allergen.Eggs, Allergen.Shellfish, Allergen.Strawberries, Allergen.Tomatoes, Allergen.Chocolate, Allergen.Pollen, Allergen.Cats };
352+
Allergen[] expected = [Allergen.Eggs, Allergen.Shellfish, Allergen.Strawberries, Allergen.Tomatoes, Allergen.Chocolate, Allergen.Pollen, Allergen.Cats];
353353
Assert.Equal(expected, sut.List());
354354
}
355355

356356
[Fact(Skip = "Remove this Skip property to run this test")]
357-
public void No_allergen_score_parts_without_highest_valid_score()
357+
public void List_when_no_allergen_score_parts_without_highest_valid_score()
358358
{
359359
var sut = new Allergies(257);
360-
var expected = new[] { Allergen.Eggs };
360+
Allergen[] expected = [Allergen.Eggs];
361361
Assert.Equal(expected, sut.List());
362362
}
363363
}
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 DartsTests
4+
{
5+
{{#test_cases}}
6+
[Fact{{#unless @first}}(Skip = "Remove this Skip property to run this test"){{/unless}}]
7+
public void {{test_method_name}}()
8+
{
9+
Assert.Equal({{expected}}, Darts.Score({{input.x}}, {{input.y}}));
10+
}
11+
{{/test_cases}}
12+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
using System.Collections.Generic;
2+
using System.Linq;
3+
using Xunit;
4+
5+
public class StrainTests
6+
{
7+
{{#test_cases_by_property.keep}}
8+
[Fact{{#unless @first}}(Skip = "Remove this Skip property to run this test"){{/unless}}]
9+
public void {{test_method_name}}()
10+
{
11+
{{#equals description "keeps lists"}}
12+
int[][] expected = [{{../expected}}];
13+
int[][] input = [{{#../input.list}}[{{.}}]{{#unless @last}}, {{/unless}}{{/../input.list}}];
14+
Assert.Equal(expected, input.Keep(x => x.Contains(5)).ToArray());
15+
{{else}}
16+
{{#equals ../description "keeps strings"}}
17+
string[] expected = [{{#../../expected}}{{lit .}}{{#unless @last}}, {{/unless}}{{/../../expected}}];
18+
string[] input = [{{#../../input.list}}{{lit .}}{{#unless @last}}, {{/unless}}{{/../../input.list}}];
19+
Assert.Equal(expected, input.Keep(x => x.StartsWith('z')).ToArray());
20+
{{else}}
21+
int[] expected = [{{../../expected}}];
22+
int[] input = [{{../../input.list}}];
23+
Assert.Equal(expected, input.Keep(x => {{replace ../../input.predicate "fn(x) -> " ""}}).ToArray());
24+
{{/equals}}
25+
{{/equals}}
26+
}
27+
{{/test_cases_by_property.keep}}
28+
29+
{{#test_cases_by_property.discard}}
30+
[Fact(Skip = "Remove this Skip property to run this test")]
31+
public void {{test_method_name}}()
32+
{
33+
{{#equals description "discards lists"}}
34+
int[][] expected = [{{../expected}}];
35+
int[][] input = [{{#../input.list}}[{{.}}]{{#unless @last}}, {{/unless}}{{/../input.list}}];
36+
Assert.Equal(expected, input.Discard(x => x.Contains(5)).ToArray());
37+
{{else}}
38+
{{#equals ../description "discards strings"}}
39+
string[] expected = [{{#../../expected}}{{lit .}}{{#unless @last}}, {{/unless}}{{/../../expected}}];
40+
string[] input = [{{#../../input.list}}{{lit .}}{{#unless @last}}, {{/unless}}{{/../../input.list}}];
41+
Assert.Equal(expected, input.Discard(x => x.StartsWith('z')).ToArray());
42+
{{else}}
43+
int[] expected = [{{../../expected}}];
44+
int[] input = [{{../../input.list}}];
45+
Assert.Equal(expected, input.Discard(x => {{replace ../../input.predicate "fn(x) -> " ""}}).ToArray());
46+
{{/equals}}
47+
{{/equals}}
48+
}
49+
{{/test_cases_by_property.discard}}
50+
}

exercises/practice/strain/StrainTests.cs

Lines changed: 57 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -5,110 +5,114 @@
55
public class StrainTests
66
{
77
[Fact]
8-
public void Empty_keep()
8+
public void Keep_on_empty_list_returns_empty_list()
99
{
10-
Assert.Equal(new LinkedList<int>(), new LinkedList<int>().Keep(x => x < 10));
10+
int[] expected = [];
11+
int[] input = [];
12+
Assert.Equal(expected, input.Keep(x => true).ToArray());
1113
}
1214

1315
[Fact(Skip = "Remove this Skip property to run this test")]
14-
public void Keep_everything()
16+
public void Keeps_everything()
1517
{
16-
Assert.Equal(new HashSet<int> { 1, 2, 3 }, new HashSet<int> { 1, 2, 3 }.Keep(x => x < 10));
18+
int[] expected = [1, 3, 5];
19+
int[] input = [1, 3, 5];
20+
Assert.Equal(expected, input.Keep(x => true).ToArray());
1721
}
1822

1923
[Fact(Skip = "Remove this Skip property to run this test")]
20-
public void Keep_nothing()
24+
public void Keeps_nothing()
2125
{
22-
Assert.Equal(new HashSet<int>(), new HashSet<int> { 1, 2, 3 }.Keep(x => x > 10));
26+
int[] expected = [];
27+
int[] input = [1, 3, 5];
28+
Assert.Equal(expected, input.Keep(x => false).ToArray());
2329
}
2430

2531
[Fact(Skip = "Remove this Skip property to run this test")]
26-
public void Keep_first_and_last()
32+
public void Keeps_first_and_last()
2733
{
28-
Assert.Equal(new[] { 1, 3 }, new[] { 1, 2, 3 }.Keep(x => x % 2 != 0));
34+
int[] expected = [1, 3];
35+
int[] input = [1, 2, 3];
36+
Assert.Equal(expected, input.Keep(x => x % 2 == 1).ToArray());
2937
}
3038

3139
[Fact(Skip = "Remove this Skip property to run this test")]
32-
public void Keep_neither_first_nor_last()
40+
public void Keeps_neither_first_nor_last()
3341
{
34-
Assert.Equal(new List<int> { 2, 4 }, new List<int> { 1, 2, 3, 4, 5 }.Keep(x => x % 2 == 0));
42+
int[] expected = [2];
43+
int[] input = [1, 2, 3];
44+
Assert.Equal(expected, input.Keep(x => x % 2 == 0).ToArray());
3545
}
3646

3747
[Fact(Skip = "Remove this Skip property to run this test")]
38-
public void Keep_strings()
48+
public void Keeps_strings()
3949
{
40-
var words = "apple zebra banana zombies cherimoya zelot".Split(' ');
41-
Assert.Equal("zebra zombies zelot".Split(' '), words.Keep(x => x.StartsWith("z")));
50+
string[] expected = ["zebra", "zombies", "zealot"];
51+
string[] input = ["apple", "zebra", "banana", "zombies", "cherimoya", "zealot"];
52+
Assert.Equal(expected, input.Keep(x => x.StartsWith('z')).ToArray());
4253
}
4354

4455
[Fact(Skip = "Remove this Skip property to run this test")]
45-
public void Keep_arrays()
56+
public void Keeps_lists()
4657
{
47-
var actual = new[]
48-
{
49-
new[] { 1, 2, 3 },
50-
new[] { 5, 5, 5 },
51-
new[] { 5, 1, 2 },
52-
new[] { 2, 1, 2 },
53-
new[] { 1, 5, 2 },
54-
new[] { 2, 2, 1 },
55-
new[] { 1, 2, 5 }
56-
};
57-
var expected = new[] { new[] { 5, 5, 5 }, new[] { 5, 1, 2 }, new[] { 1, 5, 2 }, new[] { 1, 2, 5 } };
58-
Assert.Equal(expected, actual.Keep(x => x.Contains(5)));
58+
int[][] expected = [[5, 5, 5], [5, 1, 2], [1, 5, 2], [1, 2, 5]];
59+
int[][] input = [[1, 2, 3], [5, 5, 5], [5, 1, 2], [2, 1, 2], [1, 5, 2], [2, 2, 1], [1, 2, 5]];
60+
Assert.Equal(expected, input.Keep(x => x.Contains(5)).ToArray());
5961
}
6062

6163
[Fact(Skip = "Remove this Skip property to run this test")]
62-
public void Empty_discard()
64+
public void Discard_on_empty_list_returns_empty_list()
6365
{
64-
Assert.Equal(new LinkedList<int>(), new LinkedList<int>().Discard(x => x < 10));
66+
int[] expected = [];
67+
int[] input = [];
68+
Assert.Equal(expected, input.Discard(x => true).ToArray());
6569
}
6670

6771
[Fact(Skip = "Remove this Skip property to run this test")]
68-
public void Discard_everything()
72+
public void Discards_everything()
6973
{
70-
Assert.Equal(new HashSet<int>(), new HashSet<int> { 1, 2, 3 }.Discard(x => x < 10));
74+
int[] expected = [];
75+
int[] input = [1, 3, 5];
76+
Assert.Equal(expected, input.Discard(x => true).ToArray());
7177
}
7278

7379
[Fact(Skip = "Remove this Skip property to run this test")]
74-
public void Discard_nothing()
80+
public void Discards_nothing()
7581
{
76-
Assert.Equal(new HashSet<int> { 1, 2, 3 }, new HashSet<int> { 1, 2, 3 }.Discard(x => x > 10));
82+
int[] expected = [1, 3, 5];
83+
int[] input = [1, 3, 5];
84+
Assert.Equal(expected, input.Discard(x => false).ToArray());
7785
}
7886

7987
[Fact(Skip = "Remove this Skip property to run this test")]
80-
public void Discard_first_and_last()
88+
public void Discards_first_and_last()
8189
{
82-
Assert.Equal(new[] { 2 }, new[] { 1, 2, 3 }.Discard(x => x % 2 != 0));
90+
int[] expected = [2];
91+
int[] input = [1, 2, 3];
92+
Assert.Equal(expected, input.Discard(x => x % 2 == 1).ToArray());
8393
}
8494

8595
[Fact(Skip = "Remove this Skip property to run this test")]
86-
public void Discard_neither_first_nor_last()
96+
public void Discards_neither_first_nor_last()
8797
{
88-
Assert.Equal(new List<int> { 1, 3, 5 }, new List<int> { 1, 2, 3, 4, 5 }.Discard(x => x % 2 == 0));
98+
int[] expected = [1, 3];
99+
int[] input = [1, 2, 3];
100+
Assert.Equal(expected, input.Discard(x => x % 2 == 0).ToArray());
89101
}
90102

91103
[Fact(Skip = "Remove this Skip property to run this test")]
92-
public void Discard_strings()
104+
public void Discards_strings()
93105
{
94-
var words = "apple zebra banana zombies cherimoya zelot".Split(' ');
95-
Assert.Equal("apple banana cherimoya".Split(' '), words.Discard(x => x.StartsWith("z")));
106+
string[] expected = ["apple", "banana", "cherimoya"];
107+
string[] input = ["apple", "zebra", "banana", "zombies", "cherimoya", "zealot"];
108+
Assert.Equal(expected, input.Discard(x => x.StartsWith('z')).ToArray());
96109
}
97110

98111
[Fact(Skip = "Remove this Skip property to run this test")]
99-
public void Discard_arrays()
112+
public void Discards_lists()
100113
{
101-
var actual = new[]
102-
{
103-
new[] { 1, 2, 3 },
104-
new[] { 5, 5, 5 },
105-
new[] { 5, 1, 2 },
106-
new[] { 2, 1, 2 },
107-
new[] { 1, 5, 2 },
108-
new[] { 2, 2, 1 },
109-
new[] { 1, 2, 5 }
110-
};
111-
var expected = new[] { new[] { 1, 2, 3 }, new[] { 2, 1, 2 }, new[] { 2, 2, 1 } };
112-
Assert.Equal(expected, actual.Discard(x => x.Contains(5)));
114+
int[][] expected = [[1, 2, 3], [2, 1, 2], [2, 2, 1]];
115+
int[][] input = [[1, 2, 3], [5, 5, 5], [5, 1, 2], [2, 1, 2], [1, 5, 2], [2, 2, 1], [1, 2, 5]];
116+
Assert.Equal(expected, input.Discard(x => x.Contains(5)).ToArray());
113117
}
114-
}
118+
}

0 commit comments

Comments
 (0)