Test Unicode Scalar Counting
Medium About 25 min Free, no account needed
Distinguish UTF-16 code units from Unicode scalars and reject unpaired surrogates at every position.
The brief
ScalarCounter.Count(string text) counts Unicode scalar values in a .NET UTF-16 string. A valid high-surrogate/low-surrogate pair counts as one. Every nonsurrogate code unit counts as one, including NUL and combining marks. This method does not count user-perceived characters or perform normalization.
An unpaired high or low surrogate anywhere throws ArgumentException. A null string throws ArgumentNullException. Empty input returns zero.
Use C# escapes such as "\uD83D\uDE00" for a valid pair and "\uD800x" for an invalid pair. Check pairs at boundaries and beside ordinary characters, as well as malformed sequences.
Write a Tests class. Every public, parameterless method is a test; a test passes if it does not throw. Use Assert.Equal, True, False, and Throws<TException> as needed. Your suite must pass on the correct subject and catch every hidden mutant. Construct fresh state in each test.
Starter code
public class Tests
{
public void ASCII_text()
{
Assert.Equal(3, new ScalarCounter().Count("cat"));
}
}How it is graded
You write the tests. A suite passes only when it stays green on correct code and turns enough faulty implementations red.
What it practices
- Equivalence partitioning
- Cover each class of input and every branch with one deliberate case.
- Error path testing
- Prove exceptions, retries and rejected inputs behave as specified.
Related katas
- Test the CSV Record Parser Hard Free You're given a correct CSV record parser. Write tests that pin quoting, empty fields, whitespace, and malformed input.
- Test the Bracket Matcher Medium Free You're given a correct bracket matcher for (), [], and {}. Write the tests that pin type, order, and the unbalanced cases.
- Test the Caesar Cipher Medium Free You're given a correct Caesar cipher. Write the tests that pin wraparound, case, non-letters, and shift normalization.
- Test the Checkout Service Medium Free You're given a correct checkout service with three collaborators. Write recording fakes that prove what it does to each one, and in what order.