Tuesday, September 13, 2011

Dojos and Katas

I recently got back from a very successful Socrates 2011 (Software craftsmanship and testing camp) where I spent just over 2 days hanging around with a bunch of smart people and spent the whole time either writing code, or talking about code. I was involved in a lot of discussions about software craftsmanship as well as a few coding dojos. Dojos and Katas were always something I've done when I've felt like it, but never as part of a habit. Following the conference I started using Stefan Roock's great site codersdojo. It allows you to work on a kata, and upload it to the site when you're done. It provides statistics about how long each step took as well as when the tests were passing or failing: Thanks to Stefan for a great site and helping me add Haskell Support! Take a look at my haskell fizzbuzz kata below and please checkout Stefan's site.
import Test.HUnit
fizzbuzz :: Int -> String
fizzbuzz x
| x `mod` 15 == 0 = "fizzbuzz"
| x `mod` 3 == 0 = "fizz"
| x `mod` 5 == 0 = "buzz"
| True = show x
test1 = TestCase (do assertEqual "" "1" (fizzbuzz 1))
test2 = TestCase (do assertEqual "" "fizz" (fizzbuzz 3))
test3 = TestCase (do assertEqual "" "4" (fizzbuzz 4))
test4 = TestCase (do assertEqual "" "buzz" (fizzbuzz 5))
test5 = TestCase (do assertEqual "" "fizz" (fizzbuzz 6))
test6 = TestCase (do assertEqual "" "buzz" (fizzbuzz 10))
test7 = TestCase (do assertEqual "" "fizzbuzz" (fizzbuzz 15))
tests :: Test
tests = TestList [TestLabel "test1" test1,
TestLabel "test2" test2,
TestLabel "test3" test3,
TestLabel "test4" test4,
TestLabel "test5" test5,
TestLabel "test6" test6,
TestLabel "test7" test7]
main :: IO Counts
main = do runTestTT tests
view raw fizzbuzz.hs hosted with ❤ by GitHub

No comments:

Post a Comment