Skip to content

Commit 6285e7c

Browse files
Add transformer
1 parent 2a1b6a1 commit 6285e7c

File tree

2 files changed

+46
-14
lines changed

2 files changed

+46
-14
lines changed

exercises/practice/perfect-numbers/PerfectNumbersTests.cs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,81 @@
1-
using System;
21
using Xunit;
32

43
public class PerfectNumbersTests
54
{
65
[Fact]
7-
public void Smallest_perfect_number_is_classified_correctly()
6+
public void PerfectNumbersSmallestPerfectNumberIsClassifiedCorrectly()
87
{
98
Assert.Equal(Classification.Perfect, PerfectNumbers.Classify(6));
109
}
1110

1211
[Fact(Skip = "Remove this Skip property to run this test")]
13-
public void Medium_perfect_number_is_classified_correctly()
12+
public void PerfectNumbersMediumPerfectNumberIsClassifiedCorrectly()
1413
{
1514
Assert.Equal(Classification.Perfect, PerfectNumbers.Classify(28));
1615
}
1716

1817
[Fact(Skip = "Remove this Skip property to run this test")]
19-
public void Large_perfect_number_is_classified_correctly()
18+
public void PerfectNumbersLargePerfectNumberIsClassifiedCorrectly()
2019
{
2120
Assert.Equal(Classification.Perfect, PerfectNumbers.Classify(33550336));
2221
}
2322

2423
[Fact(Skip = "Remove this Skip property to run this test")]
25-
public void Smallest_abundant_number_is_classified_correctly()
24+
public void AbundantNumbersSmallestAbundantNumberIsClassifiedCorrectly()
2625
{
2726
Assert.Equal(Classification.Abundant, PerfectNumbers.Classify(12));
2827
}
2928

3029
[Fact(Skip = "Remove this Skip property to run this test")]
31-
public void Medium_abundant_number_is_classified_correctly()
30+
public void AbundantNumbersMediumAbundantNumberIsClassifiedCorrectly()
3231
{
3332
Assert.Equal(Classification.Abundant, PerfectNumbers.Classify(30));
3433
}
3534

3635
[Fact(Skip = "Remove this Skip property to run this test")]
37-
public void Large_abundant_number_is_classified_correctly()
36+
public void AbundantNumbersLargeAbundantNumberIsClassifiedCorrectly()
3837
{
3938
Assert.Equal(Classification.Abundant, PerfectNumbers.Classify(33550335));
4039
}
4140

4241
[Fact(Skip = "Remove this Skip property to run this test")]
43-
public void Smallest_prime_deficient_number_is_classified_correctly()
42+
public void DeficientNumbersSmallestPrimeDeficientNumberIsClassifiedCorrectly()
4443
{
4544
Assert.Equal(Classification.Deficient, PerfectNumbers.Classify(2));
4645
}
4746

4847
[Fact(Skip = "Remove this Skip property to run this test")]
49-
public void Smallest_non_prime_deficient_number_is_classified_correctly()
48+
public void DeficientNumbersSmallestNonPrimeDeficientNumberIsClassifiedCorrectly()
5049
{
5150
Assert.Equal(Classification.Deficient, PerfectNumbers.Classify(4));
5251
}
5352

5453
[Fact(Skip = "Remove this Skip property to run this test")]
55-
public void Medium_deficient_number_is_classified_correctly()
54+
public void DeficientNumbersMediumDeficientNumberIsClassifiedCorrectly()
5655
{
5756
Assert.Equal(Classification.Deficient, PerfectNumbers.Classify(32));
5857
}
5958

6059
[Fact(Skip = "Remove this Skip property to run this test")]
61-
public void Large_deficient_number_is_classified_correctly()
60+
public void DeficientNumbersLargeDeficientNumberIsClassifiedCorrectly()
6261
{
6362
Assert.Equal(Classification.Deficient, PerfectNumbers.Classify(33550337));
6463
}
6564

6665
[Fact(Skip = "Remove this Skip property to run this test")]
67-
public void Edge_case_no_factors_other_than_itself_is_classified_correctly()
66+
public void DeficientNumbersEdgeCaseNoFactorsOtherThanItselfIsClassifiedCorrectly()
6867
{
6968
Assert.Equal(Classification.Deficient, PerfectNumbers.Classify(1));
7069
}
7170

7271
[Fact(Skip = "Remove this Skip property to run this test")]
73-
public void Zero_is_rejected_as_it_is_not_a_positive_integer_()
72+
public void InvalidInputsZeroIsRejectedAsItIsNotAPositiveInteger()
7473
{
7574
Assert.Throws<ArgumentOutOfRangeException>(() => PerfectNumbers.Classify(0));
7675
}
7776

7877
[Fact(Skip = "Remove this Skip property to run this test")]
79-
public void Negative_integer_is_rejected_as_it_is_not_a_positive_integer_()
78+
public void InvalidInputsNegativeIntegerIsRejectedAsItIsNotAPositiveInteger()
8079
{
8180
Assert.Throws<ArgumentOutOfRangeException>(() => PerfectNumbers.Classify(-1));
8281
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
namespace Generators;
2+
3+
using Humanizer;
4+
5+
internal class PerfectNumbersTestCaseTransformer : TestCaseTransformer
6+
{
7+
protected override TestCase UpdateTestCase(TestCase testCase) =>
8+
testCase.Error is null
9+
? testCase with { Expected = $"Classification.{((string)testCase.Expected.ToString()).Pascalize()}" }
10+
: testCase;
11+
}
12+
13+
internal static class TestCaseTransformerFactory
14+
{
15+
internal static TestCaseTransformer Create(Exercise exercise) =>
16+
exercise.Slug switch
17+
{
18+
"perfect-numbers" => new PerfectNumbersTestCaseTransformer(),
19+
_ => new TestCaseTransformer()
20+
};
21+
}
22+
23+
class TestCaseTransformer
24+
{
25+
protected virtual TestCase UpdateTestCase(TestCase testCase) => testCase;
26+
27+
protected virtual TestCase[] AddOrRemoveTestCases(TestCase[] testCases) => testCases;
28+
29+
public static TestCase[] Transform(Exercise exercise, TestCase[] testCases) =>
30+
TestCaseTransformerFactory.Create(exercise).AddOrRemoveTestCases(testCases)
31+
.Select(TestCaseTransformerFactory.Create(exercise).UpdateTestCase)
32+
.ToArray();
33+
}

0 commit comments

Comments
 (0)