Skip to main content
Tweeted twitter.com/#!/StackCodeReview/status/519246771612954625
Title and tags
Source Link
rolfl
  • 97.5k
  • 17
  • 218
  • 418

Kata F# The Functional FizzBuzz Kata

I run a coding dojo at work. forFor one session I'm to showing that you can use a kata to get into a new language.

I'm using the FizzBuzz Kata to to show F# (and javascriptJavaScript) because it is short. The problem is I am very new to F# and find myself devolving to objects instead of being functional.

Thus, I would like to see better ways of doing this (using nunit):

namespace FizzBuzzFSharp
    open NUnit.Framework

    module FizzBuzzer = 
        let FizzBuzz number = 
            match number with 
            | i when i % 3 = 0 && i % 5 = 0 -> "FizzBuzz"
            | i when i % 5 = 0 -> "Buzz"
            | i when i % 3 = 0 -> "Fizz"
            | _ -> number.ToString()


        [<Test>]
        [<TestCase(1, "1")>]
        [<TestCase(2, "2")>]
        [<TestCase(3, "Fizz")>]        
        [<TestCase(4, "4")>]
        [<TestCase(5, "Buzz")>]
        [<TestCase(6, "Fizz")>]
        [<TestCase(7, "7")>]
        [<TestCase(8, "8")>]
        [<TestCase(9, "Fizz")>]
        [<TestCase(10, "Buzz")>]
        [<TestCase(11, "11")>]
        [<TestCase(12, "Fizz")>]
        [<TestCase(13, "13")>]        
        [<TestCase(14, "14")>]
        [<TestCase(15, "FizzBuzz")>]        
        [<TestCase(30, "FizzBuzz")>]
        let WhenNumber_ThenResult(number, expected) = 
            Assert.AreEqual(expected, FizzBuzz(number));

Kata F# FizzBuzz

I run a coding dojo at work. for one session I'm to showing that you can use a kata to get into a new language.

I'm using the FizzBuzz Kata to to show F# (and javascript) because it is short. The problem is I am very new to F# and find myself devolving to objects instead of being functional.

Thus, I would like to see better ways of doing this (using nunit):

namespace FizzBuzzFSharp
    open NUnit.Framework

    module FizzBuzzer = 
        let FizzBuzz number = 
            match number with 
            | i when i % 3 = 0 && i % 5 = 0 -> "FizzBuzz"
            | i when i % 5 = 0 -> "Buzz"
            | i when i % 3 = 0 -> "Fizz"
            | _ -> number.ToString()


        [<Test>]
        [<TestCase(1, "1")>]
        [<TestCase(2, "2")>]
        [<TestCase(3, "Fizz")>]        
        [<TestCase(4, "4")>]
        [<TestCase(5, "Buzz")>]
        [<TestCase(6, "Fizz")>]
        [<TestCase(7, "7")>]
        [<TestCase(8, "8")>]
        [<TestCase(9, "Fizz")>]
        [<TestCase(10, "Buzz")>]
        [<TestCase(11, "11")>]
        [<TestCase(12, "Fizz")>]
        [<TestCase(13, "13")>]        
        [<TestCase(14, "14")>]
        [<TestCase(15, "FizzBuzz")>]        
        [<TestCase(30, "FizzBuzz")>]
        let WhenNumber_ThenResult(number, expected) = 
            Assert.AreEqual(expected, FizzBuzz(number));

The Functional FizzBuzz Kata

I run a coding dojo at work. For one session I'm to showing that you can use a kata to get into a new language.

I'm using the FizzBuzz Kata to to show F# (and JavaScript) because it is short. The problem is I am very new to F# and find myself devolving to objects instead of being functional.

Thus, I would like to see better ways of doing this (using nunit):

namespace FizzBuzzFSharp
    open NUnit.Framework

    module FizzBuzzer = 
        let FizzBuzz number = 
            match number with 
            | i when i % 3 = 0 && i % 5 = 0 -> "FizzBuzz"
            | i when i % 5 = 0 -> "Buzz"
            | i when i % 3 = 0 -> "Fizz"
            | _ -> number.ToString()


        [<Test>]
        [<TestCase(1, "1")>]
        [<TestCase(2, "2")>]
        [<TestCase(3, "Fizz")>]        
        [<TestCase(4, "4")>]
        [<TestCase(5, "Buzz")>]
        [<TestCase(6, "Fizz")>]
        [<TestCase(7, "7")>]
        [<TestCase(8, "8")>]
        [<TestCase(9, "Fizz")>]
        [<TestCase(10, "Buzz")>]
        [<TestCase(11, "11")>]
        [<TestCase(12, "Fizz")>]
        [<TestCase(13, "13")>]        
        [<TestCase(14, "14")>]
        [<TestCase(15, "FizzBuzz")>]        
        [<TestCase(30, "FizzBuzz")>]
        let WhenNumber_ThenResult(number, expected) = 
            Assert.AreEqual(expected, FizzBuzz(number));
Source Link

Kata F# FizzBuzz

I run a coding dojo at work. for one session I'm to showing that you can use a kata to get into a new language.

I'm using the FizzBuzz Kata to to show F# (and javascript) because it is short. The problem is I am very new to F# and find myself devolving to objects instead of being functional.

Thus, I would like to see better ways of doing this (using nunit):

namespace FizzBuzzFSharp
    open NUnit.Framework

    module FizzBuzzer = 
        let FizzBuzz number = 
            match number with 
            | i when i % 3 = 0 && i % 5 = 0 -> "FizzBuzz"
            | i when i % 5 = 0 -> "Buzz"
            | i when i % 3 = 0 -> "Fizz"
            | _ -> number.ToString()


        [<Test>]
        [<TestCase(1, "1")>]
        [<TestCase(2, "2")>]
        [<TestCase(3, "Fizz")>]        
        [<TestCase(4, "4")>]
        [<TestCase(5, "Buzz")>]
        [<TestCase(6, "Fizz")>]
        [<TestCase(7, "7")>]
        [<TestCase(8, "8")>]
        [<TestCase(9, "Fizz")>]
        [<TestCase(10, "Buzz")>]
        [<TestCase(11, "11")>]
        [<TestCase(12, "Fizz")>]
        [<TestCase(13, "13")>]        
        [<TestCase(14, "14")>]
        [<TestCase(15, "FizzBuzz")>]        
        [<TestCase(30, "FizzBuzz")>]
        let WhenNumber_ThenResult(number, expected) = 
            Assert.AreEqual(expected, FizzBuzz(number));