Skip to content

Commit 71eb10b

Browse files
transpose: add generator
1 parent 6b5fbd3 commit 71eb10b

File tree

2 files changed

+54
-22
lines changed

2 files changed

+54
-22
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{{ func lines(lines, variable) }}
2+
{{- if test.input.lines.empty? }}
3+
var {{variable}} = "";
4+
{{- else }}
5+
var {{variable}} =
6+
{{- for line in lines }}
7+
{{ if for.last -}}
8+
{{ line | string.literal -}};
9+
{{- else -}}
10+
{{ line | string.append "\n" | string.literal }} +
11+
{{- end -}}
12+
{{- end }}
13+
{{- end -}}
14+
{{ end }}
15+
16+
using Xunit;
17+
18+
public class {{ testClass }}
19+
{
20+
{{- for test in tests }}
21+
[Fact{{ if !for.first }}(Skip = "Remove this Skip property to run this test"){{ end }}]
22+
public void {{ test.testMethod }}()
23+
{
24+
{{- test.input.lines | lines "lines" }}
25+
{{- test.expected | lines "expected" }}
26+
Assert.Equal(expected, {{ testedClass }}.String(lines));
27+
}
28+
{{ end -}}
29+
}

exercises/practice/transpose/TransposeTests.cs

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ public void Empty_string()
1313
[Fact(Skip = "Remove this Skip property to run this test")]
1414
public void Two_characters_in_a_row()
1515
{
16-
var lines = "A1";
17-
var expected =
16+
var lines =
17+
"A1";
18+
var expected =
1819
"A\n" +
1920
"1";
2021
Assert.Equal(expected, Transpose.String(lines));
@@ -23,20 +24,21 @@ public void Two_characters_in_a_row()
2324
[Fact(Skip = "Remove this Skip property to run this test")]
2425
public void Two_characters_in_a_column()
2526
{
26-
var lines =
27+
var lines =
2728
"A\n" +
2829
"1";
29-
var expected = "A1";
30+
var expected =
31+
"A1";
3032
Assert.Equal(expected, Transpose.String(lines));
3133
}
3234

3335
[Fact(Skip = "Remove this Skip property to run this test")]
3436
public void Simple()
3537
{
36-
var lines =
38+
var lines =
3739
"ABC\n" +
3840
"123";
39-
var expected =
41+
var expected =
4042
"A1\n" +
4143
"B2\n" +
4244
"C3";
@@ -46,8 +48,9 @@ public void Simple()
4648
[Fact(Skip = "Remove this Skip property to run this test")]
4749
public void Single_line()
4850
{
49-
var lines = "Single line.";
50-
var expected =
51+
var lines =
52+
"Single line.";
53+
var expected =
5154
"S\n" +
5255
"i\n" +
5356
"n\n" +
@@ -66,10 +69,10 @@ public void Single_line()
6669
[Fact(Skip = "Remove this Skip property to run this test")]
6770
public void First_line_longer_than_second_line()
6871
{
69-
var lines =
72+
var lines =
7073
"The fourth line.\n" +
7174
"The fifth line.";
72-
var expected =
75+
var expected =
7376
"TT\n" +
7477
"hh\n" +
7578
"ee\n" +
@@ -92,10 +95,10 @@ public void First_line_longer_than_second_line()
9295
[Fact(Skip = "Remove this Skip property to run this test")]
9396
public void Second_line_longer_than_first_line()
9497
{
95-
var lines =
98+
var lines =
9699
"The first line.\n" +
97100
"The second line.";
98-
var expected =
101+
var expected =
99102
"TT\n" +
100103
"hh\n" +
101104
"ee\n" +
@@ -118,12 +121,12 @@ public void Second_line_longer_than_first_line()
118121
[Fact(Skip = "Remove this Skip property to run this test")]
119122
public void Mixed_line_length()
120123
{
121-
var lines =
124+
var lines =
122125
"The longest line.\n" +
123126
"A long line.\n" +
124127
"A longer line.\n" +
125128
"A line.";
126-
var expected =
129+
var expected =
127130
"TAAA\n" +
128131
"h \n" +
129132
"elll\n" +
@@ -147,13 +150,13 @@ public void Mixed_line_length()
147150
[Fact(Skip = "Remove this Skip property to run this test")]
148151
public void Square()
149152
{
150-
var lines =
153+
var lines =
151154
"HEART\n" +
152155
"EMBER\n" +
153156
"ABUSE\n" +
154157
"RESIN\n" +
155158
"TREND";
156-
var expected =
159+
var expected =
157160
"HEART\n" +
158161
"EMBER\n" +
159162
"ABUSE\n" +
@@ -165,12 +168,12 @@ public void Square()
165168
[Fact(Skip = "Remove this Skip property to run this test")]
166169
public void Rectangle()
167170
{
168-
var lines =
171+
var lines =
169172
"FRACTURE\n" +
170173
"OUTLINED\n" +
171174
"BLOOMING\n" +
172175
"SEPTETTE";
173-
var expected =
176+
var expected =
174177
"FOBS\n" +
175178
"RULE\n" +
176179
"ATOP\n" +
@@ -185,14 +188,14 @@ public void Rectangle()
185188
[Fact(Skip = "Remove this Skip property to run this test")]
186189
public void Triangle()
187190
{
188-
var lines =
191+
var lines =
189192
"T\n" +
190193
"EE\n" +
191194
"AAA\n" +
192195
"SSSS\n" +
193196
"EEEEE\n" +
194197
"RRRRRR";
195-
var expected =
198+
var expected =
196199
"TEASER\n" +
197200
" EASER\n" +
198201
" ASER\n" +
@@ -205,14 +208,14 @@ public void Triangle()
205208
[Fact(Skip = "Remove this Skip property to run this test")]
206209
public void Jagged_triangle()
207210
{
208-
var lines =
211+
var lines =
209212
"11\n" +
210213
"2\n" +
211214
"3333\n" +
212215
"444\n" +
213216
"555555\n" +
214217
"66666";
215-
var expected =
218+
var expected =
216219
"123456\n" +
217220
"1 3456\n" +
218221
" 3456\n" +

0 commit comments

Comments
 (0)