SlideShare ist ein Scribd-Unternehmen logo
1 von 29
FizzBuzz Guided Kata
  for C# and NUnit
           Mike Clement
  mike@softwareontheside.com
           @mdclement
http://blog.softwareontheside.com
FizzBuzz
•   If multiple of 3, get “Fizz”
•   If multiple of 5, get “Buzz”
•   If not, return input int as string
•   Rules are in order
Quick Concepts Reminder
TDD                Simple Design
• Red              • Passes all tests
• Green            • Clear, expressive, consistent
• Refactor         • No duplication
                   • Minimal
Ways to get Green in TDD
• Fake it
• Obvious implementation
• Triangulation
Start!
• Create a “Class Library” project named
  FizzBuzz
• Add a reference to NUnit (recommend using
  NuGet but can use local dll)
using NUnit.Framework;

[TestFixture]
public class FizzBuzzTests
{
}
[Test]
public void TranslateOne()
{
    string result = Translator.Translate(1);
    Assert.That(result, Is.EqualTo("1"));
}




public class Translator
{
    public static string Translate(int i)
    {
        throw new NotImplementedException();
    }
}
[Test]
public void TranslateOne()
{
    string result = Translator.Translate(1);
    Assert.That(result, Is.EqualTo("1"));
}




public static string Translate(int i)
{
    return "1";
}
[Test]
public void TranslateTwo()
{
    string result = Translator.Translate(2);
    Assert.That(result, Is.EqualTo("2"));
}




public static string Translate(int i)
{
    return i.ToString();
}
[TestCase(1, "1")]
public void Translate(int input, string expected)
{
   string result = Translator.Translate(input);
   Assert.That(result, Is.EqualTo(expected));
}




public static string Translate(int i)
{
    return i.ToString();
}
[TestCase(1, "1")]
[TestCase(2, "2")]
public void Translate(int input, string expected)
{
    string result = Translator.Translate(input);
    Assert.That(result, Is.EqualTo(expected));
}




public static string Translate(int i)
{
    return i.ToString();
}
[TestCase(1, "1")]
[TestCase(2, "2")]
[TestCase(3, "Fizz")]
public void Translate(int input, string expected)
{
    string result = Translator.Translate(input);
    Assert.That(result, Is.EqualTo(expected));
}




public static string Translate(int i)
{
    return i.ToString();
}
[TestCase(1, "1")]
[TestCase(2, "2")]
[TestCase(3, "Fizz")]
public void Translate(int input, string expected)
{
    string result = Translator.Translate(input);
    Assert.That(result, Is.EqualTo(expected));
}




public static string Translate(int i)
{
    if (i == 3) return "Fizz";
    return i.ToString();
}
[TestCase(1, "1")]
[TestCase(2, "2")]
[TestCase(3, "Fizz")]
[TestCase(6, "Fizz")]
public void Translate(int input, string expected)
{
    string result = Translator.Translate(input);
    Assert.That(result, Is.EqualTo(expected));
}



public static string Translate(int i)
{
    if (i == 3) return "Fizz";
    return i.ToString();
}
[TestCase(1, "1")]
[TestCase(2, "2")]
[TestCase(3, "Fizz")]
[TestCase(6, "Fizz")]
public void Translate(int input, string expected)
{
    string result = Translator.Translate(input);
    Assert.That(result, Is.EqualTo(expected));
}



public static string Translate(int i)
{
    if (i % 3 == 0) return "Fizz";
    return i.ToString();
}
[TestCase(1, "1")]
[TestCase(2, "2")]
[TestCase(3, "Fizz")]
[TestCase(5, "Buzz")]
[TestCase(6, "Fizz")]
public void Translate(int input, string expected)
{
    string result = Translator.Translate(input);
    Assert.That(result, Is.EqualTo(expected));
}


public static string Translate(int i)
{
    if (i % 3 == 0) return "Fizz";
    return i.ToString();
}
[TestCase(1, "1")]
[TestCase(2, "2")]
[TestCase(3, "Fizz")]
[TestCase(5, "Buzz")]
[TestCase(6, "Fizz")]
public void Translate(int input, string expected)
{
    string result = Translator.Translate(input);
    Assert.That(result, Is.EqualTo(expected));
}


public static string Translate(int i)
{
    if (i % 3 == 0) return "Fizz";
    if (i == 5) return "Buzz";
    return i.ToString();
}
[TestCase(1, "1")]
[TestCase(2, "2")]
[TestCase(3, "Fizz")]
[TestCase(5, "Buzz")]
[TestCase(6, "Fizz")]
[TestCase(10, "Buzz")]
public void Translate(int input, string expected)
{
    string result = Translator.Translate(input);
    Assert.That(result, Is.EqualTo(expected));
}
public static string Translate(int i)
{
    if (i % 3 == 0) return "Fizz";
    if (i == 5) return "Buzz";
    return i.ToString();
}
[TestCase(1, "1")]
[TestCase(2, "2")]
[TestCase(3, "Fizz")]
[TestCase(5, "Buzz")]
[TestCase(6, "Fizz")]
[TestCase(10, "Buzz")]
public void Translate(int input, string expected)
{
    string result = Translator.Translate(input);
    Assert.That(result, Is.EqualTo(expected));
}

public static string Translate(int i)
{
    if (i % 3 == 0) return "Fizz";
    if (i % 5 == 0) return "Buzz";
    return i.ToString();
}
[TestCase(1, "1")]
[TestCase(2, "2")]
[TestCase(3, "Fizz")]
[TestCase(5, "Buzz")]
[TestCase(6, "Fizz")]
[TestCase(10, "Buzz")]


public static string Translate(int i)
{
    if (ShouldFizz(i)) return "Fizz";
    if (ShouldBuzz(i)) return "Buzz";
    return i.ToString();
}
private static bool ShouldBuzz(int i)
{
    return i % 5 == 0;
}
private static bool ShouldFizz(int i)
{
    return i % 3 == 0;
}
[TestCase(1, "1")]
[TestCase(2, "2")]
[TestCase(3, "Fizz")]
[TestCase(5, "Buzz")]
[TestCase(6, "Fizz")]
[TestCase(10, "Buzz")]
[TestCase(15, "FizzBuzz")]


public static string Translate(int i)
{
    if (ShouldFizz(i)) return "Fizz";
    if (ShouldBuzz(i)) return "Buzz";
    return i.ToString();
}
private static bool ShouldBuzz(int i)
{
    return i % 5 == 0;
}
private static bool ShouldFizz(int i)
{
    return i % 3 == 0;
}
[TestCase(1, "1")]
[TestCase(2, "2")]
[TestCase(3, "Fizz")]
[TestCase(5, "Buzz")]
[TestCase(6, "Fizz")]
[TestCase(10, "Buzz")]
[TestCase(15, "FizzBuzz")]


public static string Translate(int i)
{
    string returnString = string.Empty;
    if (ShouldFizz(i)) returnString += "Fizz";
    if (ShouldBuzz(i)) returnString += "Buzz";
    if (string.IsNullOrEmpty(returnString))
    {
        returnString = i.ToString();
    }
    return returnString;
}
[TestCase(1, "1")]
[TestCase(2, "2")]
[TestCase(3, "Fizz")]
[TestCase(5, "Buzz")]
[TestCase(6, "Fizz")]
[TestCase(10, "Buzz")]
[TestCase(15, "FizzBuzz")]
public static string Translate(int i)
{
    string returnString = string.Empty;
    returnString = Fizzy(i, returnString);
    if (ShouldBuzz(i)) returnString += "Buzz";
    if (string.IsNullOrEmpty(returnString))
    {
        returnString = i.ToString();
    }
    return returnString;
}
private static string Fizzy(int i, string returnString)
{
    return returnString + (ShouldFizz(i) ? "Fizz" : string.Empty);
}
[TestCase(1, "1")]
[TestCase(2, "2")]
[TestCase(3, "Fizz")]
[TestCase(5, "Buzz")]
[TestCase(6, "Fizz")]
[TestCase(10, "Buzz")]
[TestCase(15, "FizzBuzz")]
public static string Translate(int i)
{
    string returnString = string.Empty;
    returnString = Fizzy(i, returnString);
    returnString = Buzzy(i, returnString);
    if (string.IsNullOrEmpty(returnString))
    {
        returnString = i.ToString();
    }
    return returnString;
}
private static string Buzzy(int i, string returnString)
{
    return returnString + (ShouldBuzz(i) ? "Buzz" : string.Empty);
}
[TestCase(1, "1")]
[TestCase(2, "2")]
[TestCase(3, "Fizz")]
[TestCase(5, "Buzz")]
[TestCase(6, "Fizz")]
[TestCase(10, "Buzz")]
[TestCase(15, "FizzBuzz")]

public static string Translate(int i)
{
    string returnString = string.Empty;
    returnString = Fizzy(i, returnString);
    returnString = Buzzy(i, returnString);
    returnString = Other(i, returnString);
    return returnString;
}
private static string Other(int i, string returnString)
{
    return string.IsNullOrEmpty(returnString) ? i.ToString() :
returnString;
}
[TestCase(1, "1")]
[TestCase(2, "2")]
[TestCase(3, "Fizz")]
[TestCase(5, "Buzz")]
[TestCase(6, "Fizz")]
[TestCase(10, "Buzz")]
[TestCase(15, "FizzBuzz")]

public static IList<Func<int, string, string>> Rules = new
List<Func<int, string, string>>
{
    Fizzy, Buzzy, Other
};
public static string Translate(int i)
{
    string returnString = string.Empty;
    foreach (var rule in Rules)
    {
        returnString = rule(i, returnString);
    }
    return returnString;
}
[TestCase(1, "1")]
[TestCase(2, "2")]
[TestCase(3, “3")]
[TestCase(7, "Monkey")]
[TestCase(14, "Monkey")]
public void TranslateDifferentRules(int input, string expected)
{
    var translator = new Translator();
    translator.Rules = new List<Func<int, string, string>>
    {
        (i, returnString) => returnString + ((i%7 == 0) ? "Monkey"
: string.Empty),
        (i, returnString) => string.IsNullOrEmpty(returnString) ?
i.ToString() : returnString
    };
    string result = translator.Translate(input);
    Assert.That(result, Is.EqualTo(expected));
}

public static IList<Func<int, string, string>> Rules =   ...
public static string Translate(int i) ...
public void Translate(int input, string expected)
{
    var translator = new Translator();
    string result = translator.Translate(input);
    Assert.That(result, Is.EqualTo(expected));
}




public IList<Func<int, string, string>> Rules =   ...
public string Translate(int i) ...
FizzBuzz Guided Kata

Weitere ähnliche Inhalte

Was ist angesagt?

functional groovy
functional groovyfunctional groovy
functional groovy
Paul King
 

Was ist angesagt? (20)

The Ring programming language version 1.6 book - Part 28 of 189
The Ring programming language version 1.6 book - Part 28 of 189The Ring programming language version 1.6 book - Part 28 of 189
The Ring programming language version 1.6 book - Part 28 of 189
 
Intro to Testing in Zope, Plone
Intro to Testing in Zope, PloneIntro to Testing in Zope, Plone
Intro to Testing in Zope, Plone
 
Rbootcamp Day 5
Rbootcamp Day 5Rbootcamp Day 5
Rbootcamp Day 5
 
The Ring programming language version 1.8 book - Part 31 of 202
The Ring programming language version 1.8 book - Part 31 of 202The Ring programming language version 1.8 book - Part 31 of 202
The Ring programming language version 1.8 book - Part 31 of 202
 
Functional Programming with Groovy
Functional Programming with GroovyFunctional Programming with Groovy
Functional Programming with Groovy
 
The Ring programming language version 1.5.2 book - Part 9 of 181
The Ring programming language version 1.5.2 book - Part 9 of 181The Ring programming language version 1.5.2 book - Part 9 of 181
The Ring programming language version 1.5.2 book - Part 9 of 181
 
functional groovy
functional groovyfunctional groovy
functional groovy
 
The Ring programming language version 1.5.1 book - Part 24 of 180
The Ring programming language version 1.5.1 book - Part 24 of 180The Ring programming language version 1.5.1 book - Part 24 of 180
The Ring programming language version 1.5.1 book - Part 24 of 180
 
groovy databases
groovy databasesgroovy databases
groovy databases
 
Input and Output
Input and OutputInput and Output
Input and Output
 
Transaction is a monad
Transaction is a  monadTransaction is a  monad
Transaction is a monad
 
BDD - Behavior Driven Development Webapps mit Groovy Spock und Geb
BDD - Behavior Driven Development Webapps mit Groovy Spock und GebBDD - Behavior Driven Development Webapps mit Groovy Spock und Geb
BDD - Behavior Driven Development Webapps mit Groovy Spock und Geb
 
2007 09 10 Fzi Training Groovy Grails V Ws
2007 09 10 Fzi Training Groovy Grails V Ws2007 09 10 Fzi Training Groovy Grails V Ws
2007 09 10 Fzi Training Groovy Grails V Ws
 
Secuencias Recursivas, Sucesiones Recursivas & Progresiones con Geogebra
Secuencias Recursivas, Sucesiones Recursivas & Progresiones con GeogebraSecuencias Recursivas, Sucesiones Recursivas & Progresiones con Geogebra
Secuencias Recursivas, Sucesiones Recursivas & Progresiones con Geogebra
 
The Ring programming language version 1.6 book - Part 11 of 189
The Ring programming language version 1.6 book - Part 11 of 189The Ring programming language version 1.6 book - Part 11 of 189
The Ring programming language version 1.6 book - Part 11 of 189
 
The Ring programming language version 1.10 book - Part 34 of 212
The Ring programming language version 1.10 book - Part 34 of 212The Ring programming language version 1.10 book - Part 34 of 212
The Ring programming language version 1.10 book - Part 34 of 212
 
The Ring programming language version 1.9 book - Part 15 of 210
The Ring programming language version 1.9 book - Part 15 of 210The Ring programming language version 1.9 book - Part 15 of 210
The Ring programming language version 1.9 book - Part 15 of 210
 
Pure kotlin
Pure kotlinPure kotlin
Pure kotlin
 
Programming Java - Lection 04 - Generics and Lambdas - Lavrentyev Fedor
Programming Java - Lection 04 - Generics and Lambdas - Lavrentyev FedorProgramming Java - Lection 04 - Generics and Lambdas - Lavrentyev Fedor
Programming Java - Lection 04 - Generics and Lambdas - Lavrentyev Fedor
 
Python tutorial
Python tutorialPython tutorial
Python tutorial
 

Andere mochten auch

Using Rhino Mocks for Effective Unit Testing
Using Rhino Mocks for Effective Unit TestingUsing Rhino Mocks for Effective Unit Testing
Using Rhino Mocks for Effective Unit Testing
Mike Clement
 
The ten commandments of TDD
The ten commandments of TDDThe ten commandments of TDD
The ten commandments of TDD
Hernan Wilkinson
 

Andere mochten auch (12)

Play to Learn: Agile Games with Cards and Dice
Play to Learn: Agile Games with Cards and DicePlay to Learn: Agile Games with Cards and Dice
Play to Learn: Agile Games with Cards and Dice
 
Software Craftsmanship and Agile Code Games
Software Craftsmanship and Agile Code GamesSoftware Craftsmanship and Agile Code Games
Software Craftsmanship and Agile Code Games
 
Put the Tests Before the Code
Put the Tests Before the CodePut the Tests Before the Code
Put the Tests Before the Code
 
Using Rhino Mocks for Effective Unit Testing
Using Rhino Mocks for Effective Unit TestingUsing Rhino Mocks for Effective Unit Testing
Using Rhino Mocks for Effective Unit Testing
 
Thinking in F#
Thinking in F#Thinking in F#
Thinking in F#
 
Power of Patterns: Refactoring to (or away from) Patterns
Power of Patterns: Refactoring to (or away from) PatternsPower of Patterns: Refactoring to (or away from) Patterns
Power of Patterns: Refactoring to (or away from) Patterns
 
Transformation Priority Premise: TDD Test Order Matters
Transformation Priority Premise: TDD Test Order MattersTransformation Priority Premise: TDD Test Order Matters
Transformation Priority Premise: TDD Test Order Matters
 
The Quest for Continuous Delivery at Pluralsight
The Quest for Continuous Delivery at PluralsightThe Quest for Continuous Delivery at Pluralsight
The Quest for Continuous Delivery at Pluralsight
 
Mob Programming for Continuous Learning
Mob Programming for Continuous LearningMob Programming for Continuous Learning
Mob Programming for Continuous Learning
 
Testing sad-paths
Testing sad-pathsTesting sad-paths
Testing sad-paths
 
The ten commandments of TDD
The ten commandments of TDDThe ten commandments of TDD
The ten commandments of TDD
 
Top Rumors About Apple March 21 Big Event
Top Rumors About Apple March 21 Big EventTop Rumors About Apple March 21 Big Event
Top Rumors About Apple March 21 Big Event
 

Ähnlich wie FizzBuzz Guided Kata

Bdd: Tdd and beyond the infinite
Bdd: Tdd and beyond the infiniteBdd: Tdd and beyond the infinite
Bdd: Tdd and beyond the infinite
Giordano Scalzo
 
OrderTest.javapublic class OrderTest {       Get an arra.pdf
OrderTest.javapublic class OrderTest {         Get an arra.pdfOrderTest.javapublic class OrderTest {         Get an arra.pdf
OrderTest.javapublic class OrderTest {       Get an arra.pdf
akkhan101
 
とある断片の超動的言語
とある断片の超動的言語とある断片の超動的言語
とある断片の超動的言語
Kiyotaka Oku
 
Better Software: introduction to good code
Better Software: introduction to good codeBetter Software: introduction to good code
Better Software: introduction to good code
Giordano Scalzo
 
Advanced Java Practical File
Advanced Java Practical FileAdvanced Java Practical File
Advanced Java Practical File
Soumya Behera
 

Ähnlich wie FizzBuzz Guided Kata (20)

Bdd: Tdd and beyond the infinite
Bdd: Tdd and beyond the infiniteBdd: Tdd and beyond the infinite
Bdd: Tdd and beyond the infinite
 
Basic TDD moves
Basic TDD movesBasic TDD moves
Basic TDD moves
 
What FizzBuzz can teach us about design
What FizzBuzz can teach us about designWhat FizzBuzz can teach us about design
What FizzBuzz can teach us about design
 
ALE2014 let tests drive or let dijkstra derive
ALE2014 let tests drive or let dijkstra deriveALE2014 let tests drive or let dijkstra derive
ALE2014 let tests drive or let dijkstra derive
 
Kotlin : Happy Development
Kotlin : Happy DevelopmentKotlin : Happy Development
Kotlin : Happy Development
 
Introduction to F# for the C# developer
Introduction to F# for the C# developerIntroduction to F# for the C# developer
Introduction to F# for the C# developer
 
Are we ready to Go?
Are we ready to Go?Are we ready to Go?
Are we ready to Go?
 
STAMP Descartes Presentation
STAMP Descartes PresentationSTAMP Descartes Presentation
STAMP Descartes Presentation
 
XpUg Coding Dojo: KataYahtzee in Ocp way
XpUg Coding Dojo: KataYahtzee in Ocp wayXpUg Coding Dojo: KataYahtzee in Ocp way
XpUg Coding Dojo: KataYahtzee in Ocp way
 
OrderTest.javapublic class OrderTest {       Get an arra.pdf
OrderTest.javapublic class OrderTest {         Get an arra.pdfOrderTest.javapublic class OrderTest {         Get an arra.pdf
OrderTest.javapublic class OrderTest {       Get an arra.pdf
 
とある断片の超動的言語
とある断片の超動的言語とある断片の超動的言語
とある断片の超動的言語
 
Better Software: introduction to good code
Better Software: introduction to good codeBetter Software: introduction to good code
Better Software: introduction to good code
 
MUTANTS KILLER (Revised) - PIT: state of the art of mutation testing system
MUTANTS KILLER (Revised) - PIT: state of the art of mutation testing system MUTANTS KILLER (Revised) - PIT: state of the art of mutation testing system
MUTANTS KILLER (Revised) - PIT: state of the art of mutation testing system
 
C Language Lecture 8
C Language Lecture 8C Language Lecture 8
C Language Lecture 8
 
Mutation Testing at BzhJUG
Mutation Testing at BzhJUGMutation Testing at BzhJUG
Mutation Testing at BzhJUG
 
Advanced Java Practical File
Advanced Java Practical FileAdvanced Java Practical File
Advanced Java Practical File
 
Testing the Next Generation
Testing the Next GenerationTesting the Next Generation
Testing the Next Generation
 
Testing for Educational Gaming and Educational Gaming for Testing
Testing for Educational Gaming and Educational Gaming for TestingTesting for Educational Gaming and Educational Gaming for Testing
Testing for Educational Gaming and Educational Gaming for Testing
 
Дмитрий Верескун «Синтаксический сахар C#»
Дмитрий Верескун «Синтаксический сахар C#»Дмитрий Верескун «Синтаксический сахар C#»
Дмитрий Верескун «Синтаксический сахар C#»
 
Lezione03
Lezione03Lezione03
Lezione03
 

Mehr von Mike Clement

Code Katas Spring 2012
Code Katas Spring 2012Code Katas Spring 2012
Code Katas Spring 2012
Mike Clement
 
Bowling Game Kata in C# Adapted
Bowling Game Kata in C# AdaptedBowling Game Kata in C# Adapted
Bowling Game Kata in C# Adapted
Mike Clement
 
Software Craftsmanship
Software CraftsmanshipSoftware Craftsmanship
Software Craftsmanship
Mike Clement
 

Mehr von Mike Clement (11)

Collaboration Principles from Mob Programming
Collaboration Principles from Mob ProgrammingCollaboration Principles from Mob Programming
Collaboration Principles from Mob Programming
 
Focus on Flow: Lean Principles in Action
Focus on Flow: Lean Principles in ActionFocus on Flow: Lean Principles in Action
Focus on Flow: Lean Principles in Action
 
Taming scary production code that nobody wants to touch
Taming scary production code that nobody wants to touchTaming scary production code that nobody wants to touch
Taming scary production code that nobody wants to touch
 
Develop your sense of code smell
Develop your sense of code smellDevelop your sense of code smell
Develop your sense of code smell
 
Maps over Backlogs: User Story Mapping to Share the Big Picture
Maps over Backlogs: User Story Mapping to Share the Big PictureMaps over Backlogs: User Story Mapping to Share the Big Picture
Maps over Backlogs: User Story Mapping to Share the Big Picture
 
Escaping the Pitfalls of Software Product Development
Escaping the Pitfalls of Software Product DevelopmentEscaping the Pitfalls of Software Product Development
Escaping the Pitfalls of Software Product Development
 
Code Katas Spring 2012
Code Katas Spring 2012Code Katas Spring 2012
Code Katas Spring 2012
 
Linq (from the inside)
Linq (from the inside)Linq (from the inside)
Linq (from the inside)
 
Bowling Game Kata in C# Adapted
Bowling Game Kata in C# AdaptedBowling Game Kata in C# Adapted
Bowling Game Kata in C# Adapted
 
Code Katas: Practicing Your Craft
Code Katas: Practicing Your CraftCode Katas: Practicing Your Craft
Code Katas: Practicing Your Craft
 
Software Craftsmanship
Software CraftsmanshipSoftware Craftsmanship
Software Craftsmanship
 

Kürzlich hochgeladen

Pakistani Call girls in Deira 0567006274 Deira Call girls
Pakistani Call girls in Deira 0567006274 Deira Call girlsPakistani Call girls in Deira 0567006274 Deira Call girls
Pakistani Call girls in Deira 0567006274 Deira Call girls
Monica Sydney
 
Models in Deira 0567006274 Deira Call girl Service
Models in Deira 0567006274 Deira Call girl ServiceModels in Deira 0567006274 Deira Call girl Service
Models in Deira 0567006274 Deira Call girl Service
Monica Sydney
 
Haridwar Call Girls, 8699214473 Hot Girls Service Haridwar
Haridwar Call Girls, 8699214473 Hot Girls Service HaridwarHaridwar Call Girls, 8699214473 Hot Girls Service Haridwar
Haridwar Call Girls, 8699214473 Hot Girls Service Haridwar
ranekokila
 
Abortion pills in Saudi RIYADH (+919707899604 } Get Cytotec
Abortion pills in Saudi RIYADH (+919707899604 } Get CytotecAbortion pills in Saudi RIYADH (+919707899604 } Get Cytotec
Abortion pills in Saudi RIYADH (+919707899604 } Get Cytotec
Abortion pills in Riyadh +966572737505 get cytotec
 

Kürzlich hochgeladen (20)

Satara call girl 8617370543♥️ call girls in satara escort service
Satara call girl 8617370543♥️ call girls in satara escort serviceSatara call girl 8617370543♥️ call girls in satara escort service
Satara call girl 8617370543♥️ call girls in satara escort service
 
Pakistani Call girls in Deira 0567006274 Deira Call girls
Pakistani Call girls in Deira 0567006274 Deira Call girlsPakistani Call girls in Deira 0567006274 Deira Call girls
Pakistani Call girls in Deira 0567006274 Deira Call girls
 
Call Girls in Ernakulam - 9332606886 Our call girls are sure to provide you w...
Call Girls in Ernakulam - 9332606886 Our call girls are sure to provide you w...Call Girls in Ernakulam - 9332606886 Our call girls are sure to provide you w...
Call Girls in Ernakulam - 9332606886 Our call girls are sure to provide you w...
 
Call Girls Moradabad Just Call 8617370543 Top Class Call Girl Service Available
Call Girls Moradabad Just Call 8617370543 Top Class Call Girl Service AvailableCall Girls Moradabad Just Call 8617370543 Top Class Call Girl Service Available
Call Girls Moradabad Just Call 8617370543 Top Class Call Girl Service Available
 
Models in Deira 0567006274 Deira Call girl Service
Models in Deira 0567006274 Deira Call girl ServiceModels in Deira 0567006274 Deira Call girl Service
Models in Deira 0567006274 Deira Call girl Service
 
Vip Call Girls Bhubaneswar 🐱‍🏍 9777949614 Independent Escorts Service Bhubane...
Vip Call Girls Bhubaneswar 🐱‍🏍 9777949614 Independent Escorts Service Bhubane...Vip Call Girls Bhubaneswar 🐱‍🏍 9777949614 Independent Escorts Service Bhubane...
Vip Call Girls Bhubaneswar 🐱‍🏍 9777949614 Independent Escorts Service Bhubane...
 
Haridwar Call Girls, 8699214473 Hot Girls Service Haridwar
Haridwar Call Girls, 8699214473 Hot Girls Service HaridwarHaridwar Call Girls, 8699214473 Hot Girls Service Haridwar
Haridwar Call Girls, 8699214473 Hot Girls Service Haridwar
 
Turbhe Female Escorts 09167354423 Turbhe Escorts,Call Girls In Turbhe
Turbhe Female Escorts 09167354423  Turbhe Escorts,Call Girls In TurbheTurbhe Female Escorts 09167354423  Turbhe Escorts,Call Girls In Turbhe
Turbhe Female Escorts 09167354423 Turbhe Escorts,Call Girls In Turbhe
 
Call Girls in Perumbavoor / 9332606886 Genuine Call girls with real Photos an...
Call Girls in Perumbavoor / 9332606886 Genuine Call girls with real Photos an...Call Girls in Perumbavoor / 9332606886 Genuine Call girls with real Photos an...
Call Girls in Perumbavoor / 9332606886 Genuine Call girls with real Photos an...
 
Call girls Service Bellary - 9332606886 Rs 3000 Free Pickup & Drop Services 2...
Call girls Service Bellary - 9332606886 Rs 3000 Free Pickup & Drop Services 2...Call girls Service Bellary - 9332606886 Rs 3000 Free Pickup & Drop Services 2...
Call girls Service Bellary - 9332606886 Rs 3000 Free Pickup & Drop Services 2...
 
Jann Mardenborough's Better Half in Racing and Life
Jann Mardenborough's Better Half in Racing and LifeJann Mardenborough's Better Half in Racing and Life
Jann Mardenborough's Better Half in Racing and Life
 
Bhubaneswar🌹Call Girls Kalpana Mesuem ❤Komal 9777949614 💟 Full Trusted CALL ...
Bhubaneswar🌹Call Girls Kalpana Mesuem  ❤Komal 9777949614 💟 Full Trusted CALL ...Bhubaneswar🌹Call Girls Kalpana Mesuem  ❤Komal 9777949614 💟 Full Trusted CALL ...
Bhubaneswar🌹Call Girls Kalpana Mesuem ❤Komal 9777949614 💟 Full Trusted CALL ...
 
Hire 💕 8617370543 Kushinagar Call Girls Service Call Girls Agency
Hire 💕 8617370543 Kushinagar Call Girls Service Call Girls AgencyHire 💕 8617370543 Kushinagar Call Girls Service Call Girls Agency
Hire 💕 8617370543 Kushinagar Call Girls Service Call Girls Agency
 
Call Girls in Kollam - 9332606886 Our call girls are sure to provide you with...
Call Girls in Kollam - 9332606886 Our call girls are sure to provide you with...Call Girls in Kollam - 9332606886 Our call girls are sure to provide you with...
Call Girls in Kollam - 9332606886 Our call girls are sure to provide you with...
 
Call Girls In Gorakhpur Escorts ☎️8617370543 🔝 💃 Enjoy 24/7 Escort Service En...
Call Girls In Gorakhpur Escorts ☎️8617370543 🔝 💃 Enjoy 24/7 Escort Service En...Call Girls In Gorakhpur Escorts ☎️8617370543 🔝 💃 Enjoy 24/7 Escort Service En...
Call Girls In Gorakhpur Escorts ☎️8617370543 🔝 💃 Enjoy 24/7 Escort Service En...
 
Abortion pills in Saudi RIYADH (+919707899604 } Get Cytotec
Abortion pills in Saudi RIYADH (+919707899604 } Get CytotecAbortion pills in Saudi RIYADH (+919707899604 } Get Cytotec
Abortion pills in Saudi RIYADH (+919707899604 } Get Cytotec
 
Call Girls Kozhikode - 9332606886 Our call girls are sure to provide you with...
Call Girls Kozhikode - 9332606886 Our call girls are sure to provide you with...Call Girls Kozhikode - 9332606886 Our call girls are sure to provide you with...
Call Girls Kozhikode - 9332606886 Our call girls are sure to provide you with...
 
Top IPTV Subscription Service to Stream Your Favorite Shows in 2024.pdf
Top IPTV Subscription Service to Stream Your Favorite Shows in 2024.pdfTop IPTV Subscription Service to Stream Your Favorite Shows in 2024.pdf
Top IPTV Subscription Service to Stream Your Favorite Shows in 2024.pdf
 
Deira call girls 0507330913 Call girls in Deira
Deira call girls 0507330913  Call girls in DeiraDeira call girls 0507330913  Call girls in Deira
Deira call girls 0507330913 Call girls in Deira
 
Hire 💕 8617370543 Auraiya Call Girls Service Call Girls Agency
Hire 💕 8617370543 Auraiya Call Girls Service Call Girls AgencyHire 💕 8617370543 Auraiya Call Girls Service Call Girls Agency
Hire 💕 8617370543 Auraiya Call Girls Service Call Girls Agency
 

FizzBuzz Guided Kata

  • 1. FizzBuzz Guided Kata for C# and NUnit Mike Clement mike@softwareontheside.com @mdclement http://blog.softwareontheside.com
  • 2. FizzBuzz • If multiple of 3, get “Fizz” • If multiple of 5, get “Buzz” • If not, return input int as string • Rules are in order
  • 3. Quick Concepts Reminder TDD Simple Design • Red • Passes all tests • Green • Clear, expressive, consistent • Refactor • No duplication • Minimal
  • 4. Ways to get Green in TDD • Fake it • Obvious implementation • Triangulation
  • 5. Start! • Create a “Class Library” project named FizzBuzz • Add a reference to NUnit (recommend using NuGet but can use local dll)
  • 7. [Test] public void TranslateOne() { string result = Translator.Translate(1); Assert.That(result, Is.EqualTo("1")); } public class Translator { public static string Translate(int i) { throw new NotImplementedException(); } }
  • 8. [Test] public void TranslateOne() { string result = Translator.Translate(1); Assert.That(result, Is.EqualTo("1")); } public static string Translate(int i) { return "1"; }
  • 9. [Test] public void TranslateTwo() { string result = Translator.Translate(2); Assert.That(result, Is.EqualTo("2")); } public static string Translate(int i) { return i.ToString(); }
  • 10. [TestCase(1, "1")] public void Translate(int input, string expected) { string result = Translator.Translate(input); Assert.That(result, Is.EqualTo(expected)); } public static string Translate(int i) { return i.ToString(); }
  • 11. [TestCase(1, "1")] [TestCase(2, "2")] public void Translate(int input, string expected) { string result = Translator.Translate(input); Assert.That(result, Is.EqualTo(expected)); } public static string Translate(int i) { return i.ToString(); }
  • 12. [TestCase(1, "1")] [TestCase(2, "2")] [TestCase(3, "Fizz")] public void Translate(int input, string expected) { string result = Translator.Translate(input); Assert.That(result, Is.EqualTo(expected)); } public static string Translate(int i) { return i.ToString(); }
  • 13. [TestCase(1, "1")] [TestCase(2, "2")] [TestCase(3, "Fizz")] public void Translate(int input, string expected) { string result = Translator.Translate(input); Assert.That(result, Is.EqualTo(expected)); } public static string Translate(int i) { if (i == 3) return "Fizz"; return i.ToString(); }
  • 14. [TestCase(1, "1")] [TestCase(2, "2")] [TestCase(3, "Fizz")] [TestCase(6, "Fizz")] public void Translate(int input, string expected) { string result = Translator.Translate(input); Assert.That(result, Is.EqualTo(expected)); } public static string Translate(int i) { if (i == 3) return "Fizz"; return i.ToString(); }
  • 15. [TestCase(1, "1")] [TestCase(2, "2")] [TestCase(3, "Fizz")] [TestCase(6, "Fizz")] public void Translate(int input, string expected) { string result = Translator.Translate(input); Assert.That(result, Is.EqualTo(expected)); } public static string Translate(int i) { if (i % 3 == 0) return "Fizz"; return i.ToString(); }
  • 16. [TestCase(1, "1")] [TestCase(2, "2")] [TestCase(3, "Fizz")] [TestCase(5, "Buzz")] [TestCase(6, "Fizz")] public void Translate(int input, string expected) { string result = Translator.Translate(input); Assert.That(result, Is.EqualTo(expected)); } public static string Translate(int i) { if (i % 3 == 0) return "Fizz"; return i.ToString(); }
  • 17. [TestCase(1, "1")] [TestCase(2, "2")] [TestCase(3, "Fizz")] [TestCase(5, "Buzz")] [TestCase(6, "Fizz")] public void Translate(int input, string expected) { string result = Translator.Translate(input); Assert.That(result, Is.EqualTo(expected)); } public static string Translate(int i) { if (i % 3 == 0) return "Fizz"; if (i == 5) return "Buzz"; return i.ToString(); }
  • 18. [TestCase(1, "1")] [TestCase(2, "2")] [TestCase(3, "Fizz")] [TestCase(5, "Buzz")] [TestCase(6, "Fizz")] [TestCase(10, "Buzz")] public void Translate(int input, string expected) { string result = Translator.Translate(input); Assert.That(result, Is.EqualTo(expected)); } public static string Translate(int i) { if (i % 3 == 0) return "Fizz"; if (i == 5) return "Buzz"; return i.ToString(); }
  • 19. [TestCase(1, "1")] [TestCase(2, "2")] [TestCase(3, "Fizz")] [TestCase(5, "Buzz")] [TestCase(6, "Fizz")] [TestCase(10, "Buzz")] public void Translate(int input, string expected) { string result = Translator.Translate(input); Assert.That(result, Is.EqualTo(expected)); } public static string Translate(int i) { if (i % 3 == 0) return "Fizz"; if (i % 5 == 0) return "Buzz"; return i.ToString(); }
  • 20. [TestCase(1, "1")] [TestCase(2, "2")] [TestCase(3, "Fizz")] [TestCase(5, "Buzz")] [TestCase(6, "Fizz")] [TestCase(10, "Buzz")] public static string Translate(int i) { if (ShouldFizz(i)) return "Fizz"; if (ShouldBuzz(i)) return "Buzz"; return i.ToString(); } private static bool ShouldBuzz(int i) { return i % 5 == 0; } private static bool ShouldFizz(int i) { return i % 3 == 0; }
  • 21. [TestCase(1, "1")] [TestCase(2, "2")] [TestCase(3, "Fizz")] [TestCase(5, "Buzz")] [TestCase(6, "Fizz")] [TestCase(10, "Buzz")] [TestCase(15, "FizzBuzz")] public static string Translate(int i) { if (ShouldFizz(i)) return "Fizz"; if (ShouldBuzz(i)) return "Buzz"; return i.ToString(); } private static bool ShouldBuzz(int i) { return i % 5 == 0; } private static bool ShouldFizz(int i) { return i % 3 == 0; }
  • 22. [TestCase(1, "1")] [TestCase(2, "2")] [TestCase(3, "Fizz")] [TestCase(5, "Buzz")] [TestCase(6, "Fizz")] [TestCase(10, "Buzz")] [TestCase(15, "FizzBuzz")] public static string Translate(int i) { string returnString = string.Empty; if (ShouldFizz(i)) returnString += "Fizz"; if (ShouldBuzz(i)) returnString += "Buzz"; if (string.IsNullOrEmpty(returnString)) { returnString = i.ToString(); } return returnString; }
  • 23. [TestCase(1, "1")] [TestCase(2, "2")] [TestCase(3, "Fizz")] [TestCase(5, "Buzz")] [TestCase(6, "Fizz")] [TestCase(10, "Buzz")] [TestCase(15, "FizzBuzz")] public static string Translate(int i) { string returnString = string.Empty; returnString = Fizzy(i, returnString); if (ShouldBuzz(i)) returnString += "Buzz"; if (string.IsNullOrEmpty(returnString)) { returnString = i.ToString(); } return returnString; } private static string Fizzy(int i, string returnString) { return returnString + (ShouldFizz(i) ? "Fizz" : string.Empty); }
  • 24. [TestCase(1, "1")] [TestCase(2, "2")] [TestCase(3, "Fizz")] [TestCase(5, "Buzz")] [TestCase(6, "Fizz")] [TestCase(10, "Buzz")] [TestCase(15, "FizzBuzz")] public static string Translate(int i) { string returnString = string.Empty; returnString = Fizzy(i, returnString); returnString = Buzzy(i, returnString); if (string.IsNullOrEmpty(returnString)) { returnString = i.ToString(); } return returnString; } private static string Buzzy(int i, string returnString) { return returnString + (ShouldBuzz(i) ? "Buzz" : string.Empty); }
  • 25. [TestCase(1, "1")] [TestCase(2, "2")] [TestCase(3, "Fizz")] [TestCase(5, "Buzz")] [TestCase(6, "Fizz")] [TestCase(10, "Buzz")] [TestCase(15, "FizzBuzz")] public static string Translate(int i) { string returnString = string.Empty; returnString = Fizzy(i, returnString); returnString = Buzzy(i, returnString); returnString = Other(i, returnString); return returnString; } private static string Other(int i, string returnString) { return string.IsNullOrEmpty(returnString) ? i.ToString() : returnString; }
  • 26. [TestCase(1, "1")] [TestCase(2, "2")] [TestCase(3, "Fizz")] [TestCase(5, "Buzz")] [TestCase(6, "Fizz")] [TestCase(10, "Buzz")] [TestCase(15, "FizzBuzz")] public static IList<Func<int, string, string>> Rules = new List<Func<int, string, string>> { Fizzy, Buzzy, Other }; public static string Translate(int i) { string returnString = string.Empty; foreach (var rule in Rules) { returnString = rule(i, returnString); } return returnString; }
  • 27. [TestCase(1, "1")] [TestCase(2, "2")] [TestCase(3, “3")] [TestCase(7, "Monkey")] [TestCase(14, "Monkey")] public void TranslateDifferentRules(int input, string expected) { var translator = new Translator(); translator.Rules = new List<Func<int, string, string>> { (i, returnString) => returnString + ((i%7 == 0) ? "Monkey" : string.Empty), (i, returnString) => string.IsNullOrEmpty(returnString) ? i.ToString() : returnString }; string result = translator.Translate(input); Assert.That(result, Is.EqualTo(expected)); } public static IList<Func<int, string, string>> Rules = ... public static string Translate(int i) ...
  • 28. public void Translate(int input, string expected) { var translator = new Translator(); string result = translator.Translate(input); Assert.That(result, Is.EqualTo(expected)); } public IList<Func<int, string, string>> Rules = ... public string Translate(int i) ...

Hinweis der Redaktion

  1. Refactor step also includes refactoring tests!
  2. Make it non-static