Skip to content

Commit 8f5baa0

Browse files
rectangles: add generator
1 parent 5a88a0f commit 8f5baa0

File tree

11 files changed

+64
-236
lines changed

11 files changed

+64
-236
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System;
2+
using Xunit;
3+
4+
public class {{ testClass }}
5+
{
6+
{{- for test in tests }}
7+
[Fact{{ if !for.first }}(Skip = "Remove this Skip property to run this test"){{ end }}]
8+
public void {{ test.testMethod | string.replace "1x1" "One_by_one" }}()
9+
{
10+
{{- if test.input.strings.empty? }}
11+
string[] rows = Array.Empty<string>();
12+
{{ else }}
13+
string[] rows = [
14+
{{- for row in test.input.strings }}
15+
{{ row | string.literal }}{{- if !for.last }},{{ end -}}
16+
{{ end }}
17+
];
18+
{{ end -}}
19+
Assert.Equal({{ test.expected }}, {{ testedClass }}.Count(rows));
20+
}
21+
{{ end -}}
22+
}

exercises/practice/rectangles/RectanglesTests.cs

Lines changed: 42 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -6,151 +6,139 @@ public class RectanglesTests
66
[Fact]
77
public void No_rows()
88
{
9-
var strings = Array.Empty<string>();
10-
Assert.Equal(0, Rectangles.Count(strings));
9+
string[] rows = Array.Empty<string>();
10+
Assert.Equal(0, Rectangles.Count(rows));
1111
}
1212

1313
[Fact(Skip = "Remove this Skip property to run this test")]
1414
public void No_columns()
1515
{
16-
var strings = new[]
17-
{
16+
string[] rows = [
1817
""
19-
};
20-
Assert.Equal(0, Rectangles.Count(strings));
18+
];
19+
Assert.Equal(0, Rectangles.Count(rows));
2120
}
2221

2322
[Fact(Skip = "Remove this Skip property to run this test")]
2423
public void No_rectangles()
2524
{
26-
var strings = new[]
27-
{
25+
string[] rows = [
2826
" "
29-
};
30-
Assert.Equal(0, Rectangles.Count(strings));
27+
];
28+
Assert.Equal(0, Rectangles.Count(rows));
3129
}
3230

3331
[Fact(Skip = "Remove this Skip property to run this test")]
3432
public void One_rectangle()
3533
{
36-
var strings = new[]
37-
{
34+
string[] rows = [
3835
"+-+",
3936
"| |",
4037
"+-+"
41-
};
42-
Assert.Equal(1, Rectangles.Count(strings));
38+
];
39+
Assert.Equal(1, Rectangles.Count(rows));
4340
}
4441

4542
[Fact(Skip = "Remove this Skip property to run this test")]
4643
public void Two_rectangles_without_shared_parts()
4744
{
48-
var strings = new[]
49-
{
45+
string[] rows = [
5046
" +-+",
5147
" | |",
5248
"+-+-+",
5349
"| | ",
5450
"+-+ "
55-
};
56-
Assert.Equal(2, Rectangles.Count(strings));
51+
];
52+
Assert.Equal(2, Rectangles.Count(rows));
5753
}
5854

5955
[Fact(Skip = "Remove this Skip property to run this test")]
6056
public void Five_rectangles_with_shared_parts()
6157
{
62-
var strings = new[]
63-
{
58+
string[] rows = [
6459
" +-+",
6560
" | |",
6661
"+-+-+",
6762
"| | |",
6863
"+-+-+"
69-
};
70-
Assert.Equal(5, Rectangles.Count(strings));
64+
];
65+
Assert.Equal(5, Rectangles.Count(rows));
7166
}
7267

7368
[Fact(Skip = "Remove this Skip property to run this test")]
7469
public void Rectangle_of_height_1_is_counted()
7570
{
76-
var strings = new[]
77-
{
71+
string[] rows = [
7872
"+--+",
7973
"+--+"
80-
};
81-
Assert.Equal(1, Rectangles.Count(strings));
74+
];
75+
Assert.Equal(1, Rectangles.Count(rows));
8276
}
8377

8478
[Fact(Skip = "Remove this Skip property to run this test")]
8579
public void Rectangle_of_width_1_is_counted()
8680
{
87-
var strings = new[]
88-
{
81+
string[] rows = [
8982
"++",
9083
"||",
9184
"++"
92-
};
93-
Assert.Equal(1, Rectangles.Count(strings));
85+
];
86+
Assert.Equal(1, Rectangles.Count(rows));
9487
}
9588

9689
[Fact(Skip = "Remove this Skip property to run this test")]
97-
public void Number_1x1_square_is_counted()
90+
public void One_by_one_square_is_counted()
9891
{
99-
var strings = new[]
100-
{
92+
string[] rows = [
10193
"++",
10294
"++"
103-
};
104-
Assert.Equal(1, Rectangles.Count(strings));
95+
];
96+
Assert.Equal(1, Rectangles.Count(rows));
10597
}
10698

10799
[Fact(Skip = "Remove this Skip property to run this test")]
108100
public void Only_complete_rectangles_are_counted()
109101
{
110-
var strings = new[]
111-
{
102+
string[] rows = [
112103
" +-+",
113104
" |",
114105
"+-+-+",
115106
"| | -",
116107
"+-+-+"
117-
};
118-
Assert.Equal(1, Rectangles.Count(strings));
108+
];
109+
Assert.Equal(1, Rectangles.Count(rows));
119110
}
120111

121112
[Fact(Skip = "Remove this Skip property to run this test")]
122113
public void Rectangles_can_be_of_different_sizes()
123114
{
124-
var strings = new[]
125-
{
115+
string[] rows = [
126116
"+------+----+",
127117
"| | |",
128118
"+---+--+ |",
129119
"| | |",
130120
"+---+-------+"
131-
};
132-
Assert.Equal(3, Rectangles.Count(strings));
121+
];
122+
Assert.Equal(3, Rectangles.Count(rows));
133123
}
134124

135125
[Fact(Skip = "Remove this Skip property to run this test")]
136126
public void Corner_is_required_for_a_rectangle_to_be_complete()
137127
{
138-
var strings = new[]
139-
{
128+
string[] rows = [
140129
"+------+----+",
141130
"| | |",
142131
"+------+ |",
143132
"| | |",
144133
"+---+-------+"
145-
};
146-
Assert.Equal(2, Rectangles.Count(strings));
134+
];
135+
Assert.Equal(2, Rectangles.Count(rows));
147136
}
148137

149138
[Fact(Skip = "Remove this Skip property to run this test")]
150139
public void Large_input_with_many_rectangles()
151140
{
152-
var strings = new[]
153-
{
141+
string[] rows = [
154142
"+---+--+----+",
155143
"| +--+----+",
156144
"+---+--+ |",
@@ -159,23 +147,22 @@ public void Large_input_with_many_rectangles()
159147
"+---+--+--+-+",
160148
"+------+ | |",
161149
" +-+"
162-
};
163-
Assert.Equal(60, Rectangles.Count(strings));
150+
];
151+
Assert.Equal(60, Rectangles.Count(rows));
164152
}
165153

166154
[Fact(Skip = "Remove this Skip property to run this test")]
167155
public void Rectangles_must_have_four_sides()
168156
{
169-
var strings = new[]
170-
{
157+
string[] rows = [
171158
"+-+ +-+",
172159
"| | | |",
173160
"+-+-+-+",
174161
" | | ",
175162
"+-+-+-+",
176163
"| | | |",
177164
"+-+ +-+"
178-
};
179-
Assert.Equal(5, Rectangles.Count(strings));
165+
];
166+
Assert.Equal(5, Rectangles.Count(rows));
180167
}
181168
}

generators.deprecated/Exercises/Generators/GameOfLife.cs

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

generators.deprecated/Exercises/Generators/Minesweeper.cs

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

generators.deprecated/Exercises/Generators/Rectangles.cs

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

generators.deprecated/Exercises/Generators/ReverseString.cs

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

generators.deprecated/Exercises/Generators/ScaleGenerator.cs

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

generators.deprecated/Exercises/Generators/SpiralMatrix.cs

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

0 commit comments

Comments
 (0)