End-of-Line Trim
Level: Beginner 15–30 minConcepts: StringsAlgorithms
Solutions: C# | TypeScript | Python
When editing text files often times one ends up putting extra spaces and tabs at the end of each line. Develop a simple algorithm to remove these extra characters. It shall take an input string and produce a right-trimmed output string.
Examples
| Input | Output |
|---|---|
| ”abc" | "abc" |
| "abc " | "abc" |
| "abc\t" | "abc" |
| " abc" | " abc” (does not remove beginning whitespace) |
| “ab\r\n cd \r\n" | "ab\r\ncd\r\n” (removes whitespace at end of second line) |
| “\r\n" | "\r\n” |
Hint
Be sure to handle both Windows \r\n and Unix line endings \n
Reference Walkthrough
Reference implementations in C#, TypeScript, and Python live at tddbuddy-reference-katas/end-of-line-trim. This is an F1 kata — ten scenarios covering CRLF, LF, mixed line endings, whitespace-only lines, leading-whitespace preservation, and empty input — shared across all three languages, each a single pure function trim(input).
- C# (.NET 8, xUnit, FluentAssertions 6.12.0) — walkthrough
- TypeScript (Node 20, Vitest 1.6, TS 5 strict) — walkthrough
- Python (3.11, pytest) — walkthrough
This kata ships in Agent Full-Bake mode at high gear: the rules land as one commit per language, with a brief walkthrough noting there are no builders because the inputs and outputs are the domain. A single left-to-right scan preserves each line’s original terminator (\r\n or \n) byte-for-byte while dropping its trailing space/tab run; a lone \r is treated as content, matching the TDD Buddy spec’s explicit Windows-and-Unix scope. See the repo’s Gears section for when high gear is the right call.
Related reading
- Katas Are Rehearsal, Not Performance
You don't practice TDD on production code. You practice on katas and bring the muscle memory to production. The gap between knowing TDD and doing TDD is reps. - Property-Based Tests Are the Guardrail Agents Need
Example-based tests encode cases an agent can enumerate and hardcode past. Property-based tests quantify over inputs the agent did not see at code-write time, which is the gap that makes the lookup-table attack more expensive than the honest fix. Properties are one layer in the enforcement stack, not the whole stack. - The Contract Test Is the Only Witness the Agent Cannot Author
A test the agent wrote against code the same agent wrote shares the agent's blind spot: a misunderstanding in the implementation becomes a matching misunderstanding in the test, the bar goes green, and the bug ships certified. Consumer-driven contract tests are the only category where a second team publishes the assertion the first team has to satisfy. That separation of authorship is exactly what tamper-resistant test design demanded, applied at the integration seam.