- By Emmanuel Valverde
- ·
- Posted Jan 28, 2023 9:00:00 AM
Shopping cart
What do we want to build? We are building a shopping cart for an online grocery shop. The idea of this kata is to build the product in an iterative..
This kata is used by the Codurance Academy during the Design stage of the training. The process of arriving at the solution for this exercise reinforces the principles of object-oriented design and also helps with learning to move forward in small steps, also known as "baby steps".
The kata deals with a solution where complex state logic needs to be maintained. It will show how good object-oriented design can help you to drive out a solution.
One of the fallacies of TDD is the perception that it is more time-consuming than coding an implementation only, or writing code and retro-fitting unit tests after the fact. This is only true for people who are new to the method! Adept TDDers are usually are no slower than people who write code in a non-test-driven manner. They also generally spend much less time debugging and fixing problems downstream.
Baby steps is the ideal way to practice TDD. Once you are proficient in doing this, you can incrementally progress to a solution to a problem. You will be surprised at how quick and efficient this process is once you’re accomplished at it.
Implement a finite version of Conway's Game of Life.
Here are the rules (courtesy of Wikipedia):
The universe of the Game of Life is an infinite two-dimensional orthogonal grid of square cells, each of which is in one of two possible states: alive or dead. Every cell interacts with its eight neighbours, which are the cells that are horizontally, vertically, or diagonally adjacent to it. At each step in time, the following transitions occur:
- Any live cell with fewer than two live neighbours dies, as if caused by under-population.
- Any live cell with two or three live neighbours lives on to the next generation.
- Any live cell with more than three live neighbours dies, as if by overcrowding.
- Any dead cell with exactly three live neighbours becomes a live cell, as if by reproduction.
The initial pattern constitutes the seed of the system. The first generation is created by applying the above rules simultaneously to every cell in the seed—births and deaths occur simultaneously, and the discrete moment at which this happens is sometimes called a tick (in other words, each generation is a pure function of the preceding one)
Your game should be constructed with initial state of a two-dimensional array of boolean values, and a single public method to move to the next generation:
public class GameOfLife {
public GameOfLife(boolean[][] board);
public void nextGen();
}
Credit: Kata-Log
test && commit || revert
by Kent BeckWhat do we want to build? We are building a shopping cart for an online grocery shop. The idea of this kata is to build the product in an iterative..
Iteration 1 Business rules We want to build an ATM machine and the first thing we need to do, is to create the software that will breakdown which..
In computer science, a stack is a famous abstract data type that provides certain operations on a collection of elements. Stacks have a long history,..
Join our newsletter for expert tips and inspirational case studies
Join our newsletter for expert tips and inspirational case studies