Skip to content

LilleCraft/tktdd-ocaml

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tktdd-ocaml

TKTDD in OCaml with esy workflow + Dune build system and Alcotest test framework

First time with OCaml ?

You should do an Iteration 0

Tennis

A tennis match consists of multiple sets that again are played as several games, in the kata, you only have to implement the scoring system for a single game:

  • Each player can have either of these points in one game: Love, 15, 30, 40.
  • If you have 40 and you win the ball, you win the game. There are, however, special rules.
  • If both have 40, the players are deuce.
  • If the game is in deuce, the winner of a ball will have advantage and game ball.
  • If the player with advantage wins the ball, (s)he wins the game.
  • If the player without advantage wins, they are back at deuce.

This problem is easy enough that it's fun to play with, but difficult enough that it's fun to play with.
(∩ `-´)⊃━☆゚.*・。゚

Setup

clone this repository and run

esy install

Players

In tennis, there are two players, which we can easily model with a discriminated union (a variant) :

type player =
  | PlayerOne
  | PlayerTwo

Winning the game

Advantage

When one of the players have the advantage in tennis, the result can go one of two ways: either the player with the advantage wins the ball, in which case he or she wins the game, or the other player wins, in which case the next score is deuce.

Forty

When one of the players have forty points, there are three possible outcomes of the next ball:

  • If the player with forty points wins the ball, (s)he wins the game.
  • If the other player has thirty points, and wins the ball, the score is deuce.
  • If the other player has less than thirty points, and wins the ball, his or her points increases to the next level (from love to fifteen, or from fifteen to thirty).

Challenge

You get some tests in test/test.ml folder which should serve you as a specification of what you can code. This Kata will consist in several iterations. At the end of each iteration you score the number of green tests ! (•̀ᴗ•́)و Between iterations you will the animator will give you some clues to improve the safety and confidence in your code.

esy build # compile your lib
esy test # run unit tests

Next iterations

Your are free to cheat ... But you shouldn't do it if you really whant to learn something :

Releases

No releases published

Packages

No packages published

Languages