SlideShare una empresa de Scribd logo
1 de 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

Más contenido relacionado

La actualidad más candente

functional groovy
functional groovyfunctional groovy
functional groovy
Paul King
 

La actualidad más candente (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
 

Destacado

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
 

Destacado (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
 

Similar a 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
 

Similar a 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
 

Más de 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
 

Más de 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
 

Último

CHEAP Call Girls in Malviya Nagar, (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in  Malviya Nagar, (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in  Malviya Nagar, (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Malviya Nagar, (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Call Girls In Warangal Escorts ☎️7427069034 🔝 💃 Enjoy 24/7 Escort Service En...
Call Girls In Warangal Escorts ☎️7427069034  🔝 💃 Enjoy 24/7 Escort Service En...Call Girls In Warangal Escorts ☎️7427069034  🔝 💃 Enjoy 24/7 Escort Service En...
Call Girls In Warangal Escorts ☎️7427069034 🔝 💃 Enjoy 24/7 Escort Service En...
HyderabadDolls
 

Último (20)

WhatsApp Chat: 📞 8617697112 Hire Call Girls Raiganj For a Sensual Sex Experience
WhatsApp Chat: 📞 8617697112 Hire Call Girls Raiganj For a Sensual Sex ExperienceWhatsApp Chat: 📞 8617697112 Hire Call Girls Raiganj For a Sensual Sex Experience
WhatsApp Chat: 📞 8617697112 Hire Call Girls Raiganj For a Sensual Sex Experience
 
𓀤Call On 6297143586 𓀤 Sonagachi Call Girls In All Kolkata 24/7 Provide Call W...
𓀤Call On 6297143586 𓀤 Sonagachi Call Girls In All Kolkata 24/7 Provide Call W...𓀤Call On 6297143586 𓀤 Sonagachi Call Girls In All Kolkata 24/7 Provide Call W...
𓀤Call On 6297143586 𓀤 Sonagachi Call Girls In All Kolkata 24/7 Provide Call W...
 
Dum Dum ( Call Girls ) Kolkata ✔ 6297143586 ✔ Hot Model With Sexy Bhabi Ready...
Dum Dum ( Call Girls ) Kolkata ✔ 6297143586 ✔ Hot Model With Sexy Bhabi Ready...Dum Dum ( Call Girls ) Kolkata ✔ 6297143586 ✔ Hot Model With Sexy Bhabi Ready...
Dum Dum ( Call Girls ) Kolkata ✔ 6297143586 ✔ Hot Model With Sexy Bhabi Ready...
 
Almora call girls 📞 8617697112 At Low Cost Cash Payment Booking
Almora call girls 📞 8617697112 At Low Cost Cash Payment BookingAlmora call girls 📞 8617697112 At Low Cost Cash Payment Booking
Almora call girls 📞 8617697112 At Low Cost Cash Payment Booking
 
Call Girls Panaji Just Call 8617370543 Top Class Call Girl Service Available
Call Girls Panaji Just Call 8617370543 Top Class Call Girl Service AvailableCall Girls Panaji Just Call 8617370543 Top Class Call Girl Service Available
Call Girls Panaji Just Call 8617370543 Top Class Call Girl Service Available
 
Thane West \ Escort Service in Mumbai - 450+ Call Girl Cash Payment 983332523...
Thane West \ Escort Service in Mumbai - 450+ Call Girl Cash Payment 983332523...Thane West \ Escort Service in Mumbai - 450+ Call Girl Cash Payment 983332523...
Thane West \ Escort Service in Mumbai - 450+ Call Girl Cash Payment 983332523...
 
Verified Trusted Call Girls Singaperumal Koil Chennai ✔✔7427069034 Independe...
Verified Trusted Call Girls Singaperumal Koil Chennai ✔✔7427069034  Independe...Verified Trusted Call Girls Singaperumal Koil Chennai ✔✔7427069034  Independe...
Verified Trusted Call Girls Singaperumal Koil Chennai ✔✔7427069034 Independe...
 
Mumbai ] Call Girls Service Mumbai ₹7.5k Pick Up & Drop With Cash Payment 983...
Mumbai ] Call Girls Service Mumbai ₹7.5k Pick Up & Drop With Cash Payment 983...Mumbai ] Call Girls Service Mumbai ₹7.5k Pick Up & Drop With Cash Payment 983...
Mumbai ] Call Girls Service Mumbai ₹7.5k Pick Up & Drop With Cash Payment 983...
 
Verified Trusted Call Girls Ambattur Chennai ✔✔7427069034 Independent Chenna...
Verified Trusted Call Girls Ambattur Chennai ✔✔7427069034  Independent Chenna...Verified Trusted Call Girls Ambattur Chennai ✔✔7427069034  Independent Chenna...
Verified Trusted Call Girls Ambattur Chennai ✔✔7427069034 Independent Chenna...
 
Model Call Girls In Pazhavanthangal WhatsApp Booking 7427069034 call girl ser...
Model Call Girls In Pazhavanthangal WhatsApp Booking 7427069034 call girl ser...Model Call Girls In Pazhavanthangal WhatsApp Booking 7427069034 call girl ser...
Model Call Girls In Pazhavanthangal WhatsApp Booking 7427069034 call girl ser...
 
❤Personal Whatsapp Number Keylong Call Girls 8617697112 💦✅.
❤Personal Whatsapp Number Keylong Call Girls 8617697112 💦✅.❤Personal Whatsapp Number Keylong Call Girls 8617697112 💦✅.
❤Personal Whatsapp Number Keylong Call Girls 8617697112 💦✅.
 
CHEAP Call Girls in Malviya Nagar, (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in  Malviya Nagar, (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in  Malviya Nagar, (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Malviya Nagar, (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Call Girls Manjri Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Manjri Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Manjri Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Manjri Call Me 7737669865 Budget Friendly No Advance Booking
 
Call Girls In Warangal Escorts ☎️7427069034 🔝 💃 Enjoy 24/7 Escort Service En...
Call Girls In Warangal Escorts ☎️7427069034  🔝 💃 Enjoy 24/7 Escort Service En...Call Girls In Warangal Escorts ☎️7427069034  🔝 💃 Enjoy 24/7 Escort Service En...
Call Girls In Warangal Escorts ☎️7427069034 🔝 💃 Enjoy 24/7 Escort Service En...
 
Model Call Girls In Ariyalur WhatsApp Booking 7427069034 call girl service 24...
Model Call Girls In Ariyalur WhatsApp Booking 7427069034 call girl service 24...Model Call Girls In Ariyalur WhatsApp Booking 7427069034 call girl service 24...
Model Call Girls In Ariyalur WhatsApp Booking 7427069034 call girl service 24...
 
Borum Call Girls Service ☎ ️93326-06886 ❤️‍🔥 Enjoy 24/7 Escort Service
Borum Call Girls Service ☎ ️93326-06886 ❤️‍🔥 Enjoy 24/7 Escort ServiceBorum Call Girls Service ☎ ️93326-06886 ❤️‍🔥 Enjoy 24/7 Escort Service
Borum Call Girls Service ☎ ️93326-06886 ❤️‍🔥 Enjoy 24/7 Escort Service
 
Sonagachi ( Call Girls ) Kolkata ✔ 6297143586 ✔ Hot Model With Sexy Bhabi Rea...
Sonagachi ( Call Girls ) Kolkata ✔ 6297143586 ✔ Hot Model With Sexy Bhabi Rea...Sonagachi ( Call Girls ) Kolkata ✔ 6297143586 ✔ Hot Model With Sexy Bhabi Rea...
Sonagachi ( Call Girls ) Kolkata ✔ 6297143586 ✔ Hot Model With Sexy Bhabi Rea...
 
Model Call Girls In Velappanchavadi WhatsApp Booking 7427069034 call girl ser...
Model Call Girls In Velappanchavadi WhatsApp Booking 7427069034 call girl ser...Model Call Girls In Velappanchavadi WhatsApp Booking 7427069034 call girl ser...
Model Call Girls In Velappanchavadi WhatsApp Booking 7427069034 call girl ser...
 
𓀤Call On 6297143586 𓀤 Park Street Call Girls In All Kolkata 24/7 Provide Call...
𓀤Call On 6297143586 𓀤 Park Street Call Girls In All Kolkata 24/7 Provide Call...𓀤Call On 6297143586 𓀤 Park Street Call Girls In All Kolkata 24/7 Provide Call...
𓀤Call On 6297143586 𓀤 Park Street Call Girls In All Kolkata 24/7 Provide Call...
 
Ranikhet call girls 📞 8617697112 At Low Cost Cash Payment Booking
Ranikhet call girls 📞 8617697112 At Low Cost Cash Payment BookingRanikhet call girls 📞 8617697112 At Low Cost Cash Payment Booking
Ranikhet call girls 📞 8617697112 At Low Cost Cash Payment Booking
 

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) ...

Notas del editor

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