Skip to content

Commit 45b11a7

Browse files
prime-factors: add generator
1 parent 6abdfe5 commit 45b11a7

File tree

2 files changed

+40
-12
lines changed

2 files changed

+40
-12
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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+
{{- if test.expected.empty? }}
10+
Assert.Empty({{ testedClass }}.{{ test.testedMethod }}({{ test.input.value }}));
11+
{{- else }}
12+
long[] expected = {{ test.expected }};
13+
Assert.Equal(expected, {{ testedClass }}.{{ test.testedMethod }}({{ test.input.value }}));
14+
{{ end -}}
15+
}
16+
{{ end -}}
17+
}

exercises/practice/prime-factors/PrimeFactorsTests.cs

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,72 +5,83 @@ public class PrimeFactorsTests
55
[Fact]
66
public void No_factors()
77
{
8-
Assert.Empty(PrimeFactors.Factors(1L));
8+
Assert.Empty(PrimeFactors.Factors(1));
99
}
1010

1111
[Fact(Skip = "Remove this Skip property to run this test")]
1212
public void Prime_number()
1313
{
14-
Assert.Equal(new[] { 2L }, PrimeFactors.Factors(2L));
14+
long[] expected = [2];
15+
Assert.Equal(expected, PrimeFactors.Factors(2));
1516
}
1617

1718
[Fact(Skip = "Remove this Skip property to run this test")]
1819
public void Another_prime_number()
1920
{
20-
Assert.Equal(new[] { 3L }, PrimeFactors.Factors(3L));
21+
long[] expected = [3];
22+
Assert.Equal(expected, PrimeFactors.Factors(3));
2123
}
2224

2325
[Fact(Skip = "Remove this Skip property to run this test")]
2426
public void Square_of_a_prime()
2527
{
26-
Assert.Equal(new[] { 3L, 3L }, PrimeFactors.Factors(9L));
28+
long[] expected = [3, 3];
29+
Assert.Equal(expected, PrimeFactors.Factors(9));
2730
}
2831

2932
[Fact(Skip = "Remove this Skip property to run this test")]
3033
public void Product_of_first_prime()
3134
{
32-
Assert.Equal(new[] { 2L, 2L }, PrimeFactors.Factors(4L));
35+
long[] expected = [2, 2];
36+
Assert.Equal(expected, PrimeFactors.Factors(4));
3337
}
3438

3539
[Fact(Skip = "Remove this Skip property to run this test")]
3640
public void Cube_of_a_prime()
3741
{
38-
Assert.Equal(new[] { 2L, 2L, 2L }, PrimeFactors.Factors(8L));
42+
long[] expected = [2, 2, 2];
43+
Assert.Equal(expected, PrimeFactors.Factors(8));
3944
}
4045

4146
[Fact(Skip = "Remove this Skip property to run this test")]
4247
public void Product_of_second_prime()
4348
{
44-
Assert.Equal(new[] { 3L, 3L, 3L }, PrimeFactors.Factors(27L));
49+
long[] expected = [3, 3, 3];
50+
Assert.Equal(expected, PrimeFactors.Factors(27));
4551
}
4652

4753
[Fact(Skip = "Remove this Skip property to run this test")]
4854
public void Product_of_third_prime()
4955
{
50-
Assert.Equal(new[] { 5L, 5L, 5L, 5L }, PrimeFactors.Factors(625L));
56+
long[] expected = [5, 5, 5, 5];
57+
Assert.Equal(expected, PrimeFactors.Factors(625));
5158
}
5259

5360
[Fact(Skip = "Remove this Skip property to run this test")]
5461
public void Product_of_first_and_second_prime()
5562
{
56-
Assert.Equal(new[] { 2L, 3L }, PrimeFactors.Factors(6L));
63+
long[] expected = [2, 3];
64+
Assert.Equal(expected, PrimeFactors.Factors(6));
5765
}
5866

5967
[Fact(Skip = "Remove this Skip property to run this test")]
6068
public void Product_of_primes_and_non_primes()
6169
{
62-
Assert.Equal(new[] { 2L, 2L, 3L }, PrimeFactors.Factors(12L));
70+
long[] expected = [2, 2, 3];
71+
Assert.Equal(expected, PrimeFactors.Factors(12));
6372
}
6473

6574
[Fact(Skip = "Remove this Skip property to run this test")]
6675
public void Product_of_primes()
6776
{
68-
Assert.Equal(new[] { 5L, 17L, 23L, 461L }, PrimeFactors.Factors(901255L));
77+
long[] expected = [5, 17, 23, 461];
78+
Assert.Equal(expected, PrimeFactors.Factors(901255));
6979
}
7080

7181
[Fact(Skip = "Remove this Skip property to run this test")]
7282
public void Factors_include_a_large_prime()
7383
{
74-
Assert.Equal(new[] { 11L, 9539L, 894119L }, PrimeFactors.Factors(93819012551L));
84+
long[] expected = [11, 9539, 894119];
85+
Assert.Equal(expected, PrimeFactors.Factors(93819012551));
7586
}
7687
}

0 commit comments

Comments
 (0)