Skip to content

Commit f23f608

Browse files
Update method names
1 parent b8b62c5 commit f23f608

File tree

8 files changed

+51
-52
lines changed

8 files changed

+51
-52
lines changed

exercises/practice/difference-of-squares/DifferenceOfSquaresTests.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,55 +3,55 @@
33
public class DifferenceOfSquaresTests
44
{
55
[Fact]
6-
public void Square_of_sum1()
6+
public void Square_of_sum_1()
77
{
88
Assert.Equal(1, DifferenceOfSquares.CalculateSquareOfSum(1));
99
}
1010

1111
[Fact(Skip = "Remove this Skip property to run this test")]
12-
public void Square_of_sum5()
12+
public void Square_of_sum_5()
1313
{
1414
Assert.Equal(225, DifferenceOfSquares.CalculateSquareOfSum(5));
1515
}
1616

1717
[Fact(Skip = "Remove this Skip property to run this test")]
18-
public void Square_of_sum100()
18+
public void Square_of_sum_100()
1919
{
2020
Assert.Equal(25502500, DifferenceOfSquares.CalculateSquareOfSum(100));
2121
}
2222

2323
[Fact]
24-
public void Sum_of_squares1()
24+
public void Sum_of_squares_1()
2525
{
2626
Assert.Equal(1, DifferenceOfSquares.CalculateSumOfSquares(1));
2727
}
2828

2929
[Fact(Skip = "Remove this Skip property to run this test")]
30-
public void Sum_of_squares5()
30+
public void Sum_of_squares_5()
3131
{
3232
Assert.Equal(55, DifferenceOfSquares.CalculateSumOfSquares(5));
3333
}
3434

3535
[Fact(Skip = "Remove this Skip property to run this test")]
36-
public void Sum_of_squares100()
36+
public void Sum_of_squares_100()
3737
{
3838
Assert.Equal(338350, DifferenceOfSquares.CalculateSumOfSquares(100));
3939
}
4040

4141
[Fact]
42-
public void Difference_of_squares1()
42+
public void Difference_of_squares_1()
4343
{
4444
Assert.Equal(0, DifferenceOfSquares.CalculateDifferenceOfSquares(1));
4545
}
4646

4747
[Fact(Skip = "Remove this Skip property to run this test")]
48-
public void Difference_of_squares5()
48+
public void Difference_of_squares_5()
4949
{
5050
Assert.Equal(170, DifferenceOfSquares.CalculateDifferenceOfSquares(5));
5151
}
5252

5353
[Fact(Skip = "Remove this Skip property to run this test")]
54-
public void Difference_of_squares100()
54+
public void Difference_of_squares_100()
5555
{
5656
Assert.Equal(25164150, DifferenceOfSquares.CalculateDifferenceOfSquares(100));
5757
}

exercises/practice/leap/LeapTests.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,55 +3,55 @@
33
public class LeapTests
44
{
55
[Fact]
6-
public void Year_not_divisible_by4_in_common_year()
6+
public void Year_not_divisible_by_4_in_common_year()
77
{
88
Assert.False(Leap.IsLeapYear(2015));
99
}
1010

1111
[Fact(Skip = "Remove this Skip property to run this test")]
12-
public void Year_divisible_by2_not_divisible_by4_in_common_year()
12+
public void Year_divisible_by_2_not_divisible_by_4_in_common_year()
1313
{
1414
Assert.False(Leap.IsLeapYear(1970));
1515
}
1616

1717
[Fact(Skip = "Remove this Skip property to run this test")]
18-
public void Year_divisible_by4_not_divisible_by100_in_leap_year()
18+
public void Year_divisible_by_4_not_divisible_by_100_in_leap_year()
1919
{
2020
Assert.True(Leap.IsLeapYear(1996));
2121
}
2222

2323
[Fact(Skip = "Remove this Skip property to run this test")]
24-
public void Year_divisible_by4_and5_is_still_a_leap_year()
24+
public void Year_divisible_by_4_and_5_is_still_a_leap_year()
2525
{
2626
Assert.True(Leap.IsLeapYear(1960));
2727
}
2828

2929
[Fact(Skip = "Remove this Skip property to run this test")]
30-
public void Year_divisible_by100_not_divisible_by400_in_common_year()
30+
public void Year_divisible_by_100_not_divisible_by_400_in_common_year()
3131
{
3232
Assert.False(Leap.IsLeapYear(2100));
3333
}
3434

3535
[Fact(Skip = "Remove this Skip property to run this test")]
36-
public void Year_divisible_by100_but_not_by3_is_still_not_a_leap_year()
36+
public void Year_divisible_by_100_but_not_by_3_is_still_not_a_leap_year()
3737
{
3838
Assert.False(Leap.IsLeapYear(1900));
3939
}
4040

4141
[Fact(Skip = "Remove this Skip property to run this test")]
42-
public void Year_divisible_by400_is_leap_year()
42+
public void Year_divisible_by_400_is_leap_year()
4343
{
4444
Assert.True(Leap.IsLeapYear(2000));
4545
}
4646

4747
[Fact(Skip = "Remove this Skip property to run this test")]
48-
public void Year_divisible_by400_but_not_by125_is_still_a_leap_year()
48+
public void Year_divisible_by_400_but_not_by_125_is_still_a_leap_year()
4949
{
5050
Assert.True(Leap.IsLeapYear(2400));
5151
}
5252

5353
[Fact(Skip = "Remove this Skip property to run this test")]
54-
public void Year_divisible_by200_not_divisible_by400_in_common_year()
54+
public void Year_divisible_by_200_not_divisible_by_400_in_common_year()
5555
{
5656
Assert.False(Leap.IsLeapYear(1800));
5757
}

exercises/practice/pangram/PangramTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public void Mixed_case_and_punctuation()
5757
}
5858

5959
[Fact(Skip = "Remove this Skip property to run this test")]
60-
public void Am_and_am_are26_different_characters_but_not_a_pangram()
60+
public void Am_and_am_are_26_different_characters_but_not_a_pangram()
6161
{
6262
Assert.False(Pangram.IsPangram("abcdefghijklm ABCDEFGHIJKLM"));
6363
}

exercises/practice/rotational-cipher/RotationalCipherTests.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,31 @@
33
public class RotationalCipherTests
44
{
55
[Fact]
6-
public void Rotate_a_by0_same_output_as_input()
6+
public void Rotate_a_by_0_same_output_as_input()
77
{
88
Assert.Equal(a, RotationalCipher.Rotate("a", 0));
99
}
1010

1111
[Fact(Skip = "Remove this Skip property to run this test")]
12-
public void Rotate_a_by1()
12+
public void Rotate_a_by_1()
1313
{
1414
Assert.Equal(b, RotationalCipher.Rotate("a", 1));
1515
}
1616

1717
[Fact(Skip = "Remove this Skip property to run this test")]
18-
public void Rotate_a_by26_same_output_as_input()
18+
public void Rotate_a_by_26_same_output_as_input()
1919
{
2020
Assert.Equal(a, RotationalCipher.Rotate("a", 26));
2121
}
2222

2323
[Fact(Skip = "Remove this Skip property to run this test")]
24-
public void Rotate_m_by13()
24+
public void Rotate_m_by_13()
2525
{
2626
Assert.Equal(z, RotationalCipher.Rotate("m", 13));
2727
}
2828

2929
[Fact(Skip = "Remove this Skip property to run this test")]
30-
public void Rotate_n_by13_with_wrap_around_alphabet()
30+
public void Rotate_n_by_13_with_wrap_around_alphabet()
3131
{
3232
Assert.Equal(a, RotationalCipher.Rotate("n", 13));
3333
}

exercises/practice/sieve/SieveTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public void Find_first_prime()
1515
}
1616

1717
[Fact(Skip = "Remove this Skip property to run this test")]
18-
public void Find_primes_up_to10()
18+
public void Find_primes_up_to_10()
1919
{
2020
Assert.Equal([2, 3, 5, 7], Sieve.Primes(10));
2121
}
@@ -27,7 +27,7 @@ public void Limit_is_prime()
2727
}
2828

2929
[Fact(Skip = "Remove this Skip property to run this test")]
30-
public void Find_primes_up_to1000()
30+
public void Find_primes_up_to_1000()
3131
{
3232
Assert.Equal([2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997], Sieve.Primes(1000));
3333
}

exercises/practice/square-root/SquareRootTests.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,37 @@
33
public class SquareRootTests
44
{
55
[Fact]
6-
public void Root_of1()
6+
public void Root_of_1()
77
{
88
Assert.Equal(1, SquareRoot.Root(1));
99
}
1010

1111
[Fact(Skip = "Remove this Skip property to run this test")]
12-
public void Root_of4()
12+
public void Root_of_4()
1313
{
1414
Assert.Equal(2, SquareRoot.Root(4));
1515
}
1616

1717
[Fact(Skip = "Remove this Skip property to run this test")]
18-
public void Root_of25()
18+
public void Root_of_25()
1919
{
2020
Assert.Equal(5, SquareRoot.Root(25));
2121
}
2222

2323
[Fact(Skip = "Remove this Skip property to run this test")]
24-
public void Root_of81()
24+
public void Root_of_81()
2525
{
2626
Assert.Equal(9, SquareRoot.Root(81));
2727
}
2828

2929
[Fact(Skip = "Remove this Skip property to run this test")]
30-
public void Root_of196()
30+
public void Root_of_196()
3131
{
3232
Assert.Equal(14, SquareRoot.Root(196));
3333
}
3434

3535
[Fact(Skip = "Remove this Skip property to run this test")]
36-
public void Root_of65025()
36+
public void Root_of_65025()
3737
{
3838
Assert.Equal(255, SquareRoot.Root(65025));
3939
}

exercises/practice/sum-of-multiples/SumOfMultiplesTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public void Much_larger_factors()
6969
}
7070

7171
[Fact(Skip = "Remove this Skip property to run this test")]
72-
public void All_numbers_are_multiples_of1()
72+
public void All_numbers_are_multiples_of_1()
7373
{
7474
Assert.Equal(4950, SumOfMultiples.Sum([1], 100));
7575
}
@@ -81,19 +81,19 @@ public void No_factors_means_an_empty_sum()
8181
}
8282

8383
[Fact(Skip = "Remove this Skip property to run this test")]
84-
public void The_only_multiple_of0_is0()
84+
public void The_only_multiple_of_0_is_0()
8585
{
8686
Assert.Equal(0, SumOfMultiples.Sum([0], 1));
8787
}
8888

8989
[Fact(Skip = "Remove this Skip property to run this test")]
90-
public void The_factor0_does_not_affect_the_sum_of_multiples_of_other_factors()
90+
public void The_factor_0_does_not_affect_the_sum_of_multiples_of_other_factors()
9191
{
9292
Assert.Equal(3, SumOfMultiples.Sum([3, 0], 4));
9393
}
9494

9595
[Fact(Skip = "Remove this Skip property to run this test")]
96-
public void Solutions_using_include_exclude_must_extend_to_cardinality_greater_than3()
96+
public void Solutions_using_include_exclude_must_extend_to_cardinality_greater_than_3()
9797
{
9898
Assert.Equal(39614537, SumOfMultiples.Sum([2, 3, 5, 7, 11], 10000));
9999
}

generators.new/Naming.cs

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,20 @@ namespace Generators;
44

55
internal static class Naming
66
{
7-
internal static string ToMethodName(params object[] path)
8-
{
9-
var stringPath = path.Select(obj => obj.ToString()!).ToArray();
10-
11-
// Fix method names that start with a number
12-
if (char.IsNumber(stringPath[0][0]))
13-
stringPath[0] = NumberToWord(stringPath[0]);
7+
internal static string ToMethodName(params object[] path) =>
8+
path.Cast<string>()
9+
.Unwords()
10+
.Words()
11+
.Select(Transform)
12+
.Unwords()
13+
.Underscore()
14+
.Transform(To.SentenceCase);
1415

15-
return string.Join("_", stringPath.Select(str => str.Dehumanize())).Underscore().Transform(To.SentenceCase);
16-
}
17-
18-
private static string NumberToWord(string str)
19-
{
20-
var parts = str.Split(' ');
21-
var word = Convert.ToInt32(parts[0]).ToWords();
22-
return string.Join(" ", [word, ..parts[1..]]);
23-
}
16+
private static string Transform(string str, int index) =>
17+
index == 0 && int.TryParse(str, out var i)
18+
? i.ToWords()
19+
: str.Dehumanize();
20+
21+
private static IEnumerable<string> Words(this string str) => str.Split(' ');
22+
private static string Unwords(this IEnumerable<string> strs) => string.Join(' ', strs);
2423
}

0 commit comments

Comments
 (0)