Skip to content

Commit

Permalink
Update method names
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikSchierboom committed Jan 29, 2025
1 parent b8b62c5 commit f23f608
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,55 +3,55 @@
public class DifferenceOfSquaresTests
{
[Fact]
public void Square_of_sum1()
public void Square_of_sum_1()
{
Assert.Equal(1, DifferenceOfSquares.CalculateSquareOfSum(1));
}

[Fact(Skip = "Remove this Skip property to run this test")]
public void Square_of_sum5()
public void Square_of_sum_5()
{
Assert.Equal(225, DifferenceOfSquares.CalculateSquareOfSum(5));
}

[Fact(Skip = "Remove this Skip property to run this test")]
public void Square_of_sum100()
public void Square_of_sum_100()
{
Assert.Equal(25502500, DifferenceOfSquares.CalculateSquareOfSum(100));
}

[Fact]
public void Sum_of_squares1()
public void Sum_of_squares_1()
{
Assert.Equal(1, DifferenceOfSquares.CalculateSumOfSquares(1));
}

[Fact(Skip = "Remove this Skip property to run this test")]
public void Sum_of_squares5()
public void Sum_of_squares_5()
{
Assert.Equal(55, DifferenceOfSquares.CalculateSumOfSquares(5));
}

[Fact(Skip = "Remove this Skip property to run this test")]
public void Sum_of_squares100()
public void Sum_of_squares_100()
{
Assert.Equal(338350, DifferenceOfSquares.CalculateSumOfSquares(100));
}

[Fact]
public void Difference_of_squares1()
public void Difference_of_squares_1()
{
Assert.Equal(0, DifferenceOfSquares.CalculateDifferenceOfSquares(1));
}

[Fact(Skip = "Remove this Skip property to run this test")]
public void Difference_of_squares5()
public void Difference_of_squares_5()
{
Assert.Equal(170, DifferenceOfSquares.CalculateDifferenceOfSquares(5));
}

[Fact(Skip = "Remove this Skip property to run this test")]
public void Difference_of_squares100()
public void Difference_of_squares_100()
{
Assert.Equal(25164150, DifferenceOfSquares.CalculateDifferenceOfSquares(100));
}
Expand Down
18 changes: 9 additions & 9 deletions exercises/practice/leap/LeapTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,55 +3,55 @@
public class LeapTests
{
[Fact]
public void Year_not_divisible_by4_in_common_year()
public void Year_not_divisible_by_4_in_common_year()
{
Assert.False(Leap.IsLeapYear(2015));
}

[Fact(Skip = "Remove this Skip property to run this test")]
public void Year_divisible_by2_not_divisible_by4_in_common_year()
public void Year_divisible_by_2_not_divisible_by_4_in_common_year()
{
Assert.False(Leap.IsLeapYear(1970));
}

[Fact(Skip = "Remove this Skip property to run this test")]
public void Year_divisible_by4_not_divisible_by100_in_leap_year()
public void Year_divisible_by_4_not_divisible_by_100_in_leap_year()
{
Assert.True(Leap.IsLeapYear(1996));
}

[Fact(Skip = "Remove this Skip property to run this test")]
public void Year_divisible_by4_and5_is_still_a_leap_year()
public void Year_divisible_by_4_and_5_is_still_a_leap_year()
{
Assert.True(Leap.IsLeapYear(1960));
}

[Fact(Skip = "Remove this Skip property to run this test")]
public void Year_divisible_by100_not_divisible_by400_in_common_year()
public void Year_divisible_by_100_not_divisible_by_400_in_common_year()
{
Assert.False(Leap.IsLeapYear(2100));
}

[Fact(Skip = "Remove this Skip property to run this test")]
public void Year_divisible_by100_but_not_by3_is_still_not_a_leap_year()
public void Year_divisible_by_100_but_not_by_3_is_still_not_a_leap_year()
{
Assert.False(Leap.IsLeapYear(1900));
}

[Fact(Skip = "Remove this Skip property to run this test")]
public void Year_divisible_by400_is_leap_year()
public void Year_divisible_by_400_is_leap_year()
{
Assert.True(Leap.IsLeapYear(2000));
}

[Fact(Skip = "Remove this Skip property to run this test")]
public void Year_divisible_by400_but_not_by125_is_still_a_leap_year()
public void Year_divisible_by_400_but_not_by_125_is_still_a_leap_year()
{
Assert.True(Leap.IsLeapYear(2400));
}

[Fact(Skip = "Remove this Skip property to run this test")]
public void Year_divisible_by200_not_divisible_by400_in_common_year()
public void Year_divisible_by_200_not_divisible_by_400_in_common_year()
{
Assert.False(Leap.IsLeapYear(1800));
}
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/pangram/PangramTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void Mixed_case_and_punctuation()
}

[Fact(Skip = "Remove this Skip property to run this test")]
public void Am_and_am_are26_different_characters_but_not_a_pangram()
public void Am_and_am_are_26_different_characters_but_not_a_pangram()
{
Assert.False(Pangram.IsPangram("abcdefghijklm ABCDEFGHIJKLM"));
}
Expand Down
10 changes: 5 additions & 5 deletions exercises/practice/rotational-cipher/RotationalCipherTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,31 @@
public class RotationalCipherTests
{
[Fact]
public void Rotate_a_by0_same_output_as_input()
public void Rotate_a_by_0_same_output_as_input()
{
Assert.Equal(a, RotationalCipher.Rotate("a", 0));
}

[Fact(Skip = "Remove this Skip property to run this test")]
public void Rotate_a_by1()
public void Rotate_a_by_1()
{
Assert.Equal(b, RotationalCipher.Rotate("a", 1));
}

[Fact(Skip = "Remove this Skip property to run this test")]
public void Rotate_a_by26_same_output_as_input()
public void Rotate_a_by_26_same_output_as_input()
{
Assert.Equal(a, RotationalCipher.Rotate("a", 26));
}

[Fact(Skip = "Remove this Skip property to run this test")]
public void Rotate_m_by13()
public void Rotate_m_by_13()
{
Assert.Equal(z, RotationalCipher.Rotate("m", 13));
}

[Fact(Skip = "Remove this Skip property to run this test")]
public void Rotate_n_by13_with_wrap_around_alphabet()
public void Rotate_n_by_13_with_wrap_around_alphabet()
{
Assert.Equal(a, RotationalCipher.Rotate("n", 13));
}
Expand Down
4 changes: 2 additions & 2 deletions exercises/practice/sieve/SieveTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public void Find_first_prime()
}

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

[Fact(Skip = "Remove this Skip property to run this test")]
public void Find_primes_up_to1000()
public void Find_primes_up_to_1000()
{
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));
}
Expand Down
12 changes: 6 additions & 6 deletions exercises/practice/square-root/SquareRootTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,37 @@
public class SquareRootTests
{
[Fact]
public void Root_of1()
public void Root_of_1()
{
Assert.Equal(1, SquareRoot.Root(1));
}

[Fact(Skip = "Remove this Skip property to run this test")]
public void Root_of4()
public void Root_of_4()
{
Assert.Equal(2, SquareRoot.Root(4));
}

[Fact(Skip = "Remove this Skip property to run this test")]
public void Root_of25()
public void Root_of_25()
{
Assert.Equal(5, SquareRoot.Root(25));
}

[Fact(Skip = "Remove this Skip property to run this test")]
public void Root_of81()
public void Root_of_81()
{
Assert.Equal(9, SquareRoot.Root(81));
}

[Fact(Skip = "Remove this Skip property to run this test")]
public void Root_of196()
public void Root_of_196()
{
Assert.Equal(14, SquareRoot.Root(196));
}

[Fact(Skip = "Remove this Skip property to run this test")]
public void Root_of65025()
public void Root_of_65025()
{
Assert.Equal(255, SquareRoot.Root(65025));
}
Expand Down
8 changes: 4 additions & 4 deletions exercises/practice/sum-of-multiples/SumOfMultiplesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void Much_larger_factors()
}

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

[Fact(Skip = "Remove this Skip property to run this test")]
public void The_only_multiple_of0_is0()
public void The_only_multiple_of_0_is_0()
{
Assert.Equal(0, SumOfMultiples.Sum([0], 1));
}

[Fact(Skip = "Remove this Skip property to run this test")]
public void The_factor0_does_not_affect_the_sum_of_multiples_of_other_factors()
public void The_factor_0_does_not_affect_the_sum_of_multiples_of_other_factors()
{
Assert.Equal(3, SumOfMultiples.Sum([3, 0], 4));
}

[Fact(Skip = "Remove this Skip property to run this test")]
public void Solutions_using_include_exclude_must_extend_to_cardinality_greater_than3()
public void Solutions_using_include_exclude_must_extend_to_cardinality_greater_than_3()
{
Assert.Equal(39614537, SumOfMultiples.Sum([2, 3, 5, 7, 11], 10000));
}
Expand Down
31 changes: 15 additions & 16 deletions generators.new/Naming.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,20 @@ namespace Generators;

internal static class Naming
{
internal static string ToMethodName(params object[] path)
{
var stringPath = path.Select(obj => obj.ToString()!).ToArray();

// Fix method names that start with a number
if (char.IsNumber(stringPath[0][0]))
stringPath[0] = NumberToWord(stringPath[0]);
internal static string ToMethodName(params object[] path) =>
path.Cast<string>()
.Unwords()
.Words()
.Select(Transform)
.Unwords()
.Underscore()
.Transform(To.SentenceCase);

return string.Join("_", stringPath.Select(str => str.Dehumanize())).Underscore().Transform(To.SentenceCase);
}

private static string NumberToWord(string str)
{
var parts = str.Split(' ');
var word = Convert.ToInt32(parts[0]).ToWords();
return string.Join(" ", [word, ..parts[1..]]);
}
private static string Transform(string str, int index) =>
index == 0 && int.TryParse(str, out var i)
? i.ToWords()
: str.Dehumanize();

private static IEnumerable<string> Words(this string str) => str.Split(' ');
private static string Unwords(this IEnumerable<string> strs) => string.Join(' ', strs);
}

0 comments on commit f23f608

Please sign in to comment.