-
-
Notifications
You must be signed in to change notification settings - Fork 546
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add diamond kata exercise #191
Conversation
Have you also prepared an example for one of the live tracks? Erik Schierboom [email protected] schrieb am Di., 8. März 2016
|
@NobbZ I do, for the F# track. This is the implementation: module Diamond
let make letter =
let makeLine letterCount (row, letter) =
let outerSpaces = "".PadRight(letterCount - row - 1)
let innerSpaces = "".PadRight(if row = 0 then 0 else row * 2 - 1)
if letter = 'A' then sprintf "%s%c%s" outerSpaces letter outerSpaces
else sprintf "%s%c%s%c%s" outerSpaces letter innerSpaces letter outerSpaces
let letters = ['A'..letter] |> List.mapi (fun x y -> x, y)
letters @ (letters |> List.rev |> List.tail)
|> List.map (makeLine letters.Length)
|> List.reduce (fun x y -> sprintf "%s\n%s" x y) These are the tests:
|
This is nice, thanks! |
Should it be policy that implementing tracks should use the property-based tests, instead of the "check that the output is exactly this" (maybe called value-based tests, and now I see in the linked post is called example-based tests)? |
Well, policy is maybe a bit strict, but I would strongly be in favor that we mention that people should try to solve it using property-based tests (if their language has such a library). |
Update word-count version test comments to be more clear for user
This PR adds the diamond kata as an exercise. This kata has become popular as a means to show how property-based testing can help you implement an algorithm correctly. See e.g http://blog.ploeh.dk/2015/01/10/diamond-kata-with-fscheck/.