Score Keeper Kata
The Score Keeper Kata is a beginner-friendly coding exercise designed to help you practice Test-Driven Development (TDD).
Scenario
You're tasked with developing software for a basketball scoreboard. The end-users require a simple interface with six buttons:
- Three buttons for Team A to add 1, 2, or 3 points.
- Three buttons for Team B to add 1, 2, or 3 points.
The scoreboard should display the current score in a fixed format: 000:000, where each team's score is always represented by three digits.
Your Task
You can begin by implementing a class named ScoreKeeper with the following methods:
scoreTeamA1()
scoreTeamA2()
scoreTeamA3()
scoreTeamB1()
scoreTeamB2()
scoreTeamB3()
getScore()
Each scoreTeamXn() method should increment the respective team's score by n points. The getScore() method should return the current score in the 000:000 format.
Constraints
- The score display must always be seven characters long, maintaining leading zeros as needed.
- Focus on writing clean, maintainable code with comprehensive test coverage.
- Adopt an outside-in TDD approach: start by writing tests for the ScoreKeeper interface before implementing the internal logic.
Suggested TDD Workflow
- Red: Write a failing test for the initial functionality (e.g., scoreTeamA1() should increase Team A's score by 1).
- Green: Implement the minimal code required to pass the test.
- Refactor: Clean up the code while ensuring all tests still pass.
- Repeat the cycle for each method and edge case.
Learning Objectives
- Practice the outside-in approach to TDD.
- Understand how to design a simple API that meets user requirements.
- Enhance skills in writing clear and effective unit tests.
- Experience collaborative coding through pair programming.
Links
Time to play!
Feel free to play with this small interface based on our Kata solution.
Comments
No Comments
Write comment