6 kyu

CamelCase to underscore

424 of 1,119Blune

Description:

You wrote all your unit test names in camelCase. But some of your colleagues have troubles reading these long test names. So you make a compromise to switch to underscore separation.

To make these changes fast you wrote a class to translate a camelCase name into an underscore separated name.

Implement the ToUnderscore() method.

Example:

"ThisIsAUnitTest" => "This_Is_A_Unit_Test"

But of course there are always special cases...

You also have some calculation tests. Make sure the results don't get split by underscores. So only add an underscore in front of the first number.

Also Some people already used underscore names in their tests. You don't want to change them. But if they are not split correct you should adjust them.

Some of your colleagues mark their tests with a leading and trailing underscore. Don't remove this.

And of course you should handle empty strings to avoid unnecessary errors. Just return an empty string then.

Example:

"Calculate15Plus5Equals20" => "Calculate_15_Plus_5_Equals_20"

"This_Is_Already_Split_Correct" => "This_Is_Already_Split_Correct"

"ThisIs_Not_SplitCorrect" => "This_Is_Not_Split_Correct"

"_UnderscoreMarked_Test_Name_" => _Underscore_Marked_Test_Name_"

Fundamentals
Regular Expressions
Algorithms

More By Author:

Check out these other kata created by Blune

Stats:

CreatedJun 7, 2018
PublishedJun 7, 2018
Warriors Trained2609
Total Skips51
Total Code Submissions10487
Total Times Completed1119
C# Completions134
Java Completions172
Python Completions355
JavaScript Completions424
C++ Completions71
Total Stars74
% of votes with a positive feedback rating91% of 291
Total "Very Satisfied" Votes244
Total "Somewhat Satisfied" Votes40
Total "Not Satisfied" Votes7
Total Rank Assessments12
Average Assessed Rank
6 kyu
Highest Assessed Rank
6 kyu
Lowest Assessed Rank
8 kyu
Ad
Contributors
  • Blune Avatar
  • Blind4Basics Avatar
  • Kartoffelsalat Avatar
  • FArekkusu Avatar
  • KDaryl Avatar
  • hobovsky Avatar
  • farhanaditya Avatar
  • saudiGuy Avatar
Ad