Skip to content

Commit 85c19dd

Browse files
rectangles: add generator (#2373)
* reverse-string: add generator * spiral-matrix: add generator * scale-generator: add generator * minesweeper: add generator * tournament: add generator * transpose: fix * saddle-points: add generator * ocr-numbers: add generator * book-store: add generator * spiral-matrix: fix * game-of-life: add generator * rectangles: add generator [no important files changed]
1 parent 7432aec commit 85c19dd

File tree

29 files changed

+566
-591
lines changed

29 files changed

+566
-591
lines changed
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 {{ testClass }}
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.testMethod }}()
8+
{
9+
Assert.Equal({{ test.expected / 100.0 }}m, {{ testedClass }}.{{ test.testedMethod }}({{ test.input.basket }}));
10+
}
11+
{{ end -}}
12+
}
Lines changed: 18 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,131 +1,112 @@
1-
using System;
21
using Xunit;
32

43
public class BookStoreTests
54
{
65
[Fact]
76
public void Only_a_single_book()
87
{
9-
var basket = new[] { 1 };
10-
Assert.Equal(8m, BookStore.Total(basket));
8+
Assert.Equal(8m, BookStore.Total([1]));
119
}
1210

1311
[Fact(Skip = "Remove this Skip property to run this test")]
1412
public void Two_of_the_same_book()
1513
{
16-
var basket = new[] { 2, 2 };
17-
Assert.Equal(16m, BookStore.Total(basket));
14+
Assert.Equal(16m, BookStore.Total([2, 2]));
1815
}
1916

2017
[Fact(Skip = "Remove this Skip property to run this test")]
2118
public void Empty_basket()
2219
{
23-
var basket = Array.Empty<int>();
24-
Assert.Equal(0m, BookStore.Total(basket));
20+
Assert.Equal(0m, BookStore.Total([]));
2521
}
2622

2723
[Fact(Skip = "Remove this Skip property to run this test")]
2824
public void Two_different_books()
2925
{
30-
var basket = new[] { 1, 2 };
31-
Assert.Equal(15.2m, BookStore.Total(basket));
26+
Assert.Equal(15.2m, BookStore.Total([1, 2]));
3227
}
3328

3429
[Fact(Skip = "Remove this Skip property to run this test")]
3530
public void Three_different_books()
3631
{
37-
var basket = new[] { 1, 2, 3 };
38-
Assert.Equal(21.6m, BookStore.Total(basket));
32+
Assert.Equal(21.6m, BookStore.Total([1, 2, 3]));
3933
}
4034

4135
[Fact(Skip = "Remove this Skip property to run this test")]
4236
public void Four_different_books()
4337
{
44-
var basket = new[] { 1, 2, 3, 4 };
45-
Assert.Equal(25.6m, BookStore.Total(basket));
38+
Assert.Equal(25.6m, BookStore.Total([1, 2, 3, 4]));
4639
}
4740

4841
[Fact(Skip = "Remove this Skip property to run this test")]
4942
public void Five_different_books()
5043
{
51-
var basket = new[] { 1, 2, 3, 4, 5 };
52-
Assert.Equal(30m, BookStore.Total(basket));
44+
Assert.Equal(30m, BookStore.Total([1, 2, 3, 4, 5]));
5345
}
5446

5547
[Fact(Skip = "Remove this Skip property to run this test")]
5648
public void Two_groups_of_four_is_cheaper_than_group_of_five_plus_group_of_three()
5749
{
58-
var basket = new[] { 1, 1, 2, 2, 3, 3, 4, 5 };
59-
Assert.Equal(51.2m, BookStore.Total(basket));
50+
Assert.Equal(51.2m, BookStore.Total([1, 1, 2, 2, 3, 3, 4, 5]));
6051
}
6152

6253
[Fact(Skip = "Remove this Skip property to run this test")]
6354
public void Two_groups_of_four_is_cheaper_than_groups_of_five_and_three()
6455
{
65-
var basket = new[] { 1, 1, 2, 3, 4, 4, 5, 5 };
66-
Assert.Equal(51.2m, BookStore.Total(basket));
56+
Assert.Equal(51.2m, BookStore.Total([1, 1, 2, 3, 4, 4, 5, 5]));
6757
}
6858

6959
[Fact(Skip = "Remove this Skip property to run this test")]
7060
public void Group_of_four_plus_group_of_two_is_cheaper_than_two_groups_of_three()
7161
{
72-
var basket = new[] { 1, 1, 2, 2, 3, 4 };
73-
Assert.Equal(40.8m, BookStore.Total(basket));
62+
Assert.Equal(40.8m, BookStore.Total([1, 1, 2, 2, 3, 4]));
7463
}
7564

7665
[Fact(Skip = "Remove this Skip property to run this test")]
7766
public void Two_each_of_first_four_books_and_one_copy_each_of_rest()
7867
{
79-
var basket = new[] { 1, 1, 2, 2, 3, 3, 4, 4, 5 };
80-
Assert.Equal(55.6m, BookStore.Total(basket));
68+
Assert.Equal(55.6m, BookStore.Total([1, 1, 2, 2, 3, 3, 4, 4, 5]));
8169
}
8270

8371
[Fact(Skip = "Remove this Skip property to run this test")]
8472
public void Two_copies_of_each_book()
8573
{
86-
var basket = new[] { 1, 1, 2, 2, 3, 3, 4, 4, 5, 5 };
87-
Assert.Equal(60m, BookStore.Total(basket));
74+
Assert.Equal(60m, BookStore.Total([1, 1, 2, 2, 3, 3, 4, 4, 5, 5]));
8875
}
8976

9077
[Fact(Skip = "Remove this Skip property to run this test")]
9178
public void Three_copies_of_first_book_and_two_each_of_remaining()
9279
{
93-
var basket = new[] { 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 1 };
94-
Assert.Equal(68m, BookStore.Total(basket));
80+
Assert.Equal(68m, BookStore.Total([1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 1]));
9581
}
9682

9783
[Fact(Skip = "Remove this Skip property to run this test")]
9884
public void Three_each_of_first_two_books_and_two_each_of_remaining_books()
9985
{
100-
var basket = new[] { 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 1, 2 };
101-
Assert.Equal(75.2m, BookStore.Total(basket));
86+
Assert.Equal(75.2m, BookStore.Total([1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 1, 2]));
10287
}
10388

10489
[Fact(Skip = "Remove this Skip property to run this test")]
10590
public void Four_groups_of_four_are_cheaper_than_two_groups_each_of_five_and_three()
10691
{
107-
var basket = new[] { 1, 1, 2, 2, 3, 3, 4, 5, 1, 1, 2, 2, 3, 3, 4, 5 };
108-
Assert.Equal(102.4m, BookStore.Total(basket));
92+
Assert.Equal(102.4m, BookStore.Total([1, 1, 2, 2, 3, 3, 4, 5, 1, 1, 2, 2, 3, 3, 4, 5]));
10993
}
11094

11195
[Fact(Skip = "Remove this Skip property to run this test")]
11296
public void Check_that_groups_of_four_are_created_properly_even_when_there_are_more_groups_of_three_than_groups_of_five()
11397
{
114-
var basket = new[] { 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 5, 5 };
115-
Assert.Equal(145.6m, BookStore.Total(basket));
98+
Assert.Equal(145.6m, BookStore.Total([1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 5, 5]));
11699
}
117100

118101
[Fact(Skip = "Remove this Skip property to run this test")]
119102
public void One_group_of_one_and_four_is_cheaper_than_one_group_of_two_and_three()
120103
{
121-
var basket = new[] { 1, 1, 2, 3, 4 };
122-
Assert.Equal(33.6m, BookStore.Total(basket));
104+
Assert.Equal(33.6m, BookStore.Total([1, 1, 2, 3, 4]));
123105
}
124106

125107
[Fact(Skip = "Remove this Skip property to run this test")]
126108
public void One_group_of_one_and_two_plus_three_groups_of_four_is_cheaper_than_one_group_of_each_size()
127109
{
128-
var basket = new[] { 1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5 };
129-
Assert.Equal(100m, BookStore.Total(basket));
110+
Assert.Equal(100m, BookStore.Total([1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5]));
130111
}
131112
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using Xunit;
2+
3+
public class {{ testClass }}
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.testMethod }}()
8+
{
9+
int[,] matrix =
10+
{
11+
{{- for row in test.input.matrix }}
12+
{ {{ row | array.join ", " }} }{{- if !for.last }},{{ end -}}
13+
{{ end }}
14+
};
15+
{{- if test.expected.empty? }}
16+
Assert.Empty({{ testedClass }}.{{ test.testedMethod }}(matrix));
17+
{{ else }}
18+
int[,] expected =
19+
{
20+
{{- for row in test.expected }}
21+
{ {{ row | array.join ", " }} }{{- if !for.last }},{{ end -}}
22+
{{ end }}
23+
};
24+
Assert.Equal(expected, {{ testedClass }}.{{ test.testedMethod }}(matrix));
25+
{{ end -}}
26+
}
27+
{{ end -}}
28+
}

0 commit comments

Comments
 (0)