Skip to content

Commit 23bedb9

Browse files
series: add generator
1 parent 2fa556e commit 23bedb9

File tree

3 files changed

+35
-41
lines changed

3 files changed

+35
-41
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System;
2+
using Xunit;
3+
4+
public class SeriesTests
5+
{
6+
{{for testCase in testCases}}
7+
[Fact{{if !for.first}}(Skip = "Remove this Skip property to run this test"){{end}}]
8+
public void {{testCase.testMethodName}}()
9+
{
10+
{{if testCase.expected.error}}
11+
Assert.Throws<ArgumentException>(() => Series.Slices({{testCase.input.series | string.literal}}, {{testCase.input.sliceLength}}));
12+
{{else}}
13+
string[] expected = {{testCase.expected}};
14+
Assert.Equal(expected, Series.Slices({{testCase.input.series | string.literal}}, {{testCase.input.sliceLength}}));
15+
{{end}}
16+
}
17+
{{end}}
18+
}
Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,77 @@
11
using System;
2-
using System.Linq;
32
using Xunit;
43

54
public class SeriesTests
65
{
76
[Fact]
87
public void Slices_of_one_from_one()
98
{
10-
var expected = new[] { "1" };
11-
Assert.Equal(expected, Series.Slices("1", 1).ToArray());
9+
string[] expected = ["1"];
10+
Assert.Equal(expected, Series.Slices("1", 1));
1211
}
1312

1413
[Fact(Skip = "Remove this Skip property to run this test")]
1514
public void Slices_of_one_from_two()
1615
{
17-
var expected = new[] { "1", "2" };
18-
Assert.Equal(expected, Series.Slices("12", 1).ToArray());
16+
string[] expected = ["1", "2"];
17+
Assert.Equal(expected, Series.Slices("12", 1));
1918
}
2019

2120
[Fact(Skip = "Remove this Skip property to run this test")]
2221
public void Slices_of_two()
2322
{
24-
var expected = new[] { "35" };
25-
Assert.Equal(expected, Series.Slices("35", 2).ToArray());
23+
string[] expected = ["35"];
24+
Assert.Equal(expected, Series.Slices("35", 2));
2625
}
2726

2827
[Fact(Skip = "Remove this Skip property to run this test")]
2928
public void Slices_of_two_overlap()
3029
{
31-
var expected = new[] { "91", "14", "42" };
32-
Assert.Equal(expected, Series.Slices("9142", 2).ToArray());
30+
string[] expected = ["91", "14", "42"];
31+
Assert.Equal(expected, Series.Slices("9142", 2));
3332
}
3433

3534
[Fact(Skip = "Remove this Skip property to run this test")]
3635
public void Slices_can_include_duplicates()
3736
{
38-
var expected = new[] { "777", "777", "777", "777" };
39-
Assert.Equal(expected, Series.Slices("777777", 3).ToArray());
37+
string[] expected = ["777", "777", "777", "777"];
38+
Assert.Equal(expected, Series.Slices("777777", 3));
4039
}
4140

4241
[Fact(Skip = "Remove this Skip property to run this test")]
4342
public void Slices_of_a_long_series()
4443
{
45-
var expected = new[] { "91849", "18493", "84939", "49390", "93904", "39042", "90424", "04243" };
46-
Assert.Equal(expected, Series.Slices("918493904243", 5).ToArray());
44+
string[] expected = ["91849", "18493", "84939", "49390", "93904", "39042", "90424", "04243"];
45+
Assert.Equal(expected, Series.Slices("918493904243", 5));
4746
}
4847

4948
[Fact(Skip = "Remove this Skip property to run this test")]
5049
public void Slice_length_is_too_large()
5150
{
52-
Assert.Throws<ArgumentException>(() => Series.Slices("12345", 6).ToArray());
51+
Assert.Throws<ArgumentException>(() => Series.Slices("12345", 6));
5352
}
5453

5554
[Fact(Skip = "Remove this Skip property to run this test")]
5655
public void Slice_length_is_way_too_large()
5756
{
58-
Assert.Throws<ArgumentException>(() => Series.Slices("12345", 42).ToArray());
57+
Assert.Throws<ArgumentException>(() => Series.Slices("12345", 42));
5958
}
6059

6160
[Fact(Skip = "Remove this Skip property to run this test")]
6261
public void Slice_length_cannot_be_zero()
6362
{
64-
Assert.Throws<ArgumentException>(() => Series.Slices("12345", 0).ToArray());
63+
Assert.Throws<ArgumentException>(() => Series.Slices("12345", 0));
6564
}
6665

6766
[Fact(Skip = "Remove this Skip property to run this test")]
6867
public void Slice_length_cannot_be_negative()
6968
{
70-
Assert.Throws<ArgumentException>(() => Series.Slices("123", -1).ToArray());
69+
Assert.Throws<ArgumentException>(() => Series.Slices("123", -1));
7170
}
7271

7372
[Fact(Skip = "Remove this Skip property to run this test")]
7473
public void Empty_series_is_invalid()
7574
{
76-
Assert.Throws<ArgumentException>(() => Series.Slices("", 1).ToArray());
75+
Assert.Throws<ArgumentException>(() => Series.Slices("", 1));
7776
}
7877
}

generators.deprecated/Exercises/Generators/Series.cs

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

0 commit comments

Comments
 (0)