FizzBuzz Guided Kata

Mike Clement
Mike ClementHusband, Father and VP of Engineering at Emmersion, Founder Software Craftsmanship Atlanta
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
1 of 29

Recommended

Commit ускоривший python 2.7.11 на 30% и новое в python 3.5 by
Commit ускоривший python 2.7.11 на 30% и новое в python 3.5Commit ускоривший python 2.7.11 на 30% и новое в python 3.5
Commit ускоривший python 2.7.11 на 30% и новое в python 3.5PyNSK
906 views11 slides
Spock by
SpockSpock
SpockEvgeny Borisov
2.6K views29 slides
Introduction to Erlang by
Introduction to ErlangIntroduction to Erlang
Introduction to ErlangGabriele Lana
1.6K views46 slides
Use PEG to Write a Programming Language Parser by
Use PEG to Write a Programming Language ParserUse PEG to Write a Programming Language Parser
Use PEG to Write a Programming Language ParserYodalee
1.7K views36 slides
The Ring programming language version 1.6 book - Part 82 of 189 by
The Ring programming language version 1.6 book - Part 82 of 189The Ring programming language version 1.6 book - Part 82 of 189
The Ring programming language version 1.6 book - Part 82 of 189Mahmoud Samir Fayed
13 views10 slides
Python and sysadmin I by
Python and sysadmin IPython and sysadmin I
Python and sysadmin IGuixing Bai
2.9K views65 slides

More Related Content

What's hot

The Ring programming language version 1.6 book - Part 28 of 189 by
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 189Mahmoud Samir Fayed
6 views10 slides
Intro to Testing in Zope, Plone by
Intro to Testing in Zope, PloneIntro to Testing in Zope, Plone
Intro to Testing in Zope, PloneQuintagroup
1.6K views37 slides
Rbootcamp Day 5 by
Rbootcamp Day 5Rbootcamp Day 5
Rbootcamp Day 5Olga Scrivner
572 views56 slides
The Ring programming language version 1.8 book - Part 31 of 202 by
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 202Mahmoud Samir Fayed
6 views10 slides
Functional Programming with Groovy by
Functional Programming with GroovyFunctional Programming with Groovy
Functional Programming with GroovyArturo Herrero
13.4K views71 slides
The Ring programming language version 1.5.2 book - Part 9 of 181 by
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 181Mahmoud Samir Fayed
10 views10 slides

What's hot(20)

The Ring programming language version 1.6 book - Part 28 of 189 by Mahmoud Samir Fayed
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 by Quintagroup
Intro to Testing in Zope, PloneIntro to Testing in Zope, Plone
Intro to Testing in Zope, Plone
Quintagroup1.6K views
The Ring programming language version 1.8 book - Part 31 of 202 by Mahmoud Samir Fayed
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 by Arturo Herrero
Functional Programming with GroovyFunctional Programming with Groovy
Functional Programming with Groovy
Arturo Herrero13.4K views
The Ring programming language version 1.5.2 book - Part 9 of 181 by Mahmoud Samir Fayed
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 by Paul King
functional groovyfunctional groovy
functional groovy
Paul King3K views
The Ring programming language version 1.5.1 book - Part 24 of 180 by Mahmoud Samir Fayed
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 by Paul King
groovy databasesgroovy databases
groovy databases
Paul King5.3K views
BDD - Behavior Driven Development Webapps mit Groovy Spock und Geb by Christian Baranowski
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 by loffenauer
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
loffenauer1.3K views
Secuencias Recursivas, Sucesiones Recursivas & Progresiones con Geogebra by Jose Perez
Secuencias Recursivas, Sucesiones Recursivas & Progresiones con GeogebraSecuencias Recursivas, Sucesiones Recursivas & Progresiones con Geogebra
Secuencias Recursivas, Sucesiones Recursivas & Progresiones con Geogebra
Jose Perez160 views
The Ring programming language version 1.6 book - Part 11 of 189 by Mahmoud Samir Fayed
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 by Mahmoud Samir Fayed
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 by Mahmoud Samir Fayed
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
Programming Java - Lection 04 - Generics and Lambdas - Lavrentyev Fedor by Fedor Lavrentyev
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
Fedor Lavrentyev479 views

Viewers also liked

Play to Learn: Agile Games with Cards and Dice by
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 DiceMike Clement
1.8K views33 slides
Software Craftsmanship and Agile Code Games by
Software Craftsmanship and Agile Code GamesSoftware Craftsmanship and Agile Code Games
Software Craftsmanship and Agile Code GamesMike Clement
6.3K views62 slides
Put the Tests Before the Code by
Put the Tests Before the CodePut the Tests Before the Code
Put the Tests Before the CodeMike Clement
960 views39 slides
Using Rhino Mocks for Effective Unit Testing by
Using Rhino Mocks for Effective Unit TestingUsing Rhino Mocks for Effective Unit Testing
Using Rhino Mocks for Effective Unit TestingMike Clement
6.8K views18 slides
Thinking in F# by
Thinking in F#Thinking in F#
Thinking in F#Mike Clement
1.7K views12 slides
Power of Patterns: Refactoring to (or away from) Patterns by
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) PatternsMike Clement
2.6K views68 slides

Viewers also liked(12)

Play to Learn: Agile Games with Cards and Dice by Mike Clement
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
Mike Clement1.8K views
Software Craftsmanship and Agile Code Games by Mike Clement
Software Craftsmanship and Agile Code GamesSoftware Craftsmanship and Agile Code Games
Software Craftsmanship and Agile Code Games
Mike Clement6.3K views
Put the Tests Before the Code by Mike Clement
Put the Tests Before the CodePut the Tests Before the Code
Put the Tests Before the Code
Mike Clement960 views
Using Rhino Mocks for Effective Unit Testing by Mike Clement
Using Rhino Mocks for Effective Unit TestingUsing Rhino Mocks for Effective Unit Testing
Using Rhino Mocks for Effective Unit Testing
Mike Clement6.8K views
Power of Patterns: Refactoring to (or away from) Patterns by Mike Clement
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
Mike Clement2.6K views
Transformation Priority Premise: TDD Test Order Matters by Mike Clement
Transformation Priority Premise: TDD Test Order MattersTransformation Priority Premise: TDD Test Order Matters
Transformation Priority Premise: TDD Test Order Matters
Mike Clement3.3K views
The Quest for Continuous Delivery at Pluralsight by Mike Clement
The Quest for Continuous Delivery at PluralsightThe Quest for Continuous Delivery at Pluralsight
The Quest for Continuous Delivery at Pluralsight
Mike Clement2.4K views
Mob Programming for Continuous Learning by Mike Clement
Mob Programming for Continuous LearningMob Programming for Continuous Learning
Mob Programming for Continuous Learning
Mike Clement1.7K views
Testing sad-paths by Solano Labs
Testing sad-pathsTesting sad-paths
Testing sad-paths
Solano Labs2.1K views

Similar to FizzBuzz Guided Kata

Bdd: Tdd and beyond the infinite by
Bdd: Tdd and beyond the infiniteBdd: Tdd and beyond the infinite
Bdd: Tdd and beyond the infiniteGiordano Scalzo
32.8K views123 slides
Basic TDD moves by
Basic TDD movesBasic TDD moves
Basic TDD movesFernando Cuenca
468 views32 slides
What FizzBuzz can teach us about design by
What FizzBuzz can teach us about designWhat FizzBuzz can teach us about design
What FizzBuzz can teach us about designMassimo Iacolare
665 views191 slides
ALE2014 let tests drive or let dijkstra derive by
ALE2014 let tests drive or let dijkstra deriveALE2014 let tests drive or let dijkstra derive
ALE2014 let tests drive or let dijkstra deriveSanderSlideShare
537 views40 slides
Kotlin : Happy Development by
Kotlin : Happy DevelopmentKotlin : Happy Development
Kotlin : Happy DevelopmentMd Sazzad Islam
195 views27 slides
Introduction to F# for the C# developer by
Introduction to F# for the C# developerIntroduction to F# for the C# developer
Introduction to F# for the C# developernjpst8
991 views41 slides

Similar to FizzBuzz Guided Kata(20)

Bdd: Tdd and beyond the infinite by Giordano Scalzo
Bdd: Tdd and beyond the infiniteBdd: Tdd and beyond the infinite
Bdd: Tdd and beyond the infinite
Giordano Scalzo32.8K views
What FizzBuzz can teach us about design by Massimo Iacolare
What FizzBuzz can teach us about designWhat FizzBuzz can teach us about design
What FizzBuzz can teach us about design
Massimo Iacolare665 views
ALE2014 let tests drive or let dijkstra derive by SanderSlideShare
ALE2014 let tests drive or let dijkstra deriveALE2014 let tests drive or let dijkstra derive
ALE2014 let tests drive or let dijkstra derive
SanderSlideShare537 views
Introduction to F# for the C# developer by njpst8
Introduction to F# for the C# developerIntroduction to F# for the C# developer
Introduction to F# for the C# developer
njpst8991 views
Are we ready to Go? by Adam Dudczak
Are we ready to Go?Are we ready to Go?
Are we ready to Go?
Adam Dudczak1.3K views
STAMP Descartes Presentation by STAMP Project
STAMP Descartes PresentationSTAMP Descartes Presentation
STAMP Descartes Presentation
STAMP Project105 views
XpUg Coding Dojo: KataYahtzee in Ocp way by Giordano Scalzo
XpUg Coding Dojo: KataYahtzee in Ocp wayXpUg Coding Dojo: KataYahtzee in Ocp way
XpUg Coding Dojo: KataYahtzee in Ocp way
Giordano Scalzo5.5K views
OrderTest.javapublic class OrderTest {       Get an arra.pdf by akkhan101
OrderTest.javapublic class OrderTest {         Get an arra.pdfOrderTest.javapublic class OrderTest {         Get an arra.pdf
OrderTest.javapublic class OrderTest {       Get an arra.pdf
akkhan1013 views
とある断片の超動的言語 by Kiyotaka Oku
とある断片の超動的言語とある断片の超動的言語
とある断片の超動的言語
Kiyotaka Oku522 views
Better Software: introduction to good code by Giordano Scalzo
Better Software: introduction to good codeBetter Software: introduction to good code
Better Software: introduction to good code
Giordano Scalzo2.1K views
MUTANTS KILLER (Revised) - PIT: state of the art of mutation testing system by Tarin Gamberini
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
Tarin Gamberini2.1K views
Mutation Testing at BzhJUG by STAMP Project
Mutation Testing at BzhJUGMutation Testing at BzhJUG
Mutation Testing at BzhJUG
STAMP Project159 views
Advanced Java Practical File by Soumya Behera
Advanced Java Practical FileAdvanced Java Practical File
Advanced Java Practical File
Soumya Behera14.3K views
Testing the Next Generation by Mike Harris
Testing the Next GenerationTesting the Next Generation
Testing the Next Generation
Mike Harris736 views
Testing for Educational Gaming and Educational Gaming for Testing by Tao Xie
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
Tao Xie595 views
Дмитрий Верескун «Синтаксический сахар C#» by SpbDotNet Community
Дмитрий Верескун «Синтаксический сахар C#»Дмитрий Верескун «Синтаксический сахар C#»
Дмитрий Верескун «Синтаксический сахар C#»
Lezione03 by robynho86
Lezione03Lezione03
Lezione03
robynho86130 views

More from Mike Clement

Collaboration Principles from Mob Programming by
Collaboration Principles from Mob ProgrammingCollaboration Principles from Mob Programming
Collaboration Principles from Mob ProgrammingMike Clement
113 views116 slides
Focus on Flow: Lean Principles in Action by
Focus on Flow: Lean Principles in ActionFocus on Flow: Lean Principles in Action
Focus on Flow: Lean Principles in ActionMike Clement
130 views108 slides
Taming scary production code that nobody wants to touch by
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 touchMike Clement
912 views60 slides
Develop your sense of code smell by
Develop your sense of code smellDevelop your sense of code smell
Develop your sense of code smellMike Clement
1.2K views51 slides
Maps over Backlogs: User Story Mapping to Share the Big Picture by
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 PictureMike Clement
989 views45 slides
Escaping the Pitfalls of Software Product Development by
Escaping the Pitfalls of Software Product DevelopmentEscaping the Pitfalls of Software Product Development
Escaping the Pitfalls of Software Product DevelopmentMike Clement
154 views44 slides

More from Mike Clement(11)

Collaboration Principles from Mob Programming by Mike Clement
Collaboration Principles from Mob ProgrammingCollaboration Principles from Mob Programming
Collaboration Principles from Mob Programming
Mike Clement113 views
Focus on Flow: Lean Principles in Action by Mike Clement
Focus on Flow: Lean Principles in ActionFocus on Flow: Lean Principles in Action
Focus on Flow: Lean Principles in Action
Mike Clement130 views
Taming scary production code that nobody wants to touch by Mike Clement
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
Mike Clement912 views
Develop your sense of code smell by Mike Clement
Develop your sense of code smellDevelop your sense of code smell
Develop your sense of code smell
Mike Clement1.2K views
Maps over Backlogs: User Story Mapping to Share the Big Picture by Mike Clement
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
Mike Clement989 views
Escaping the Pitfalls of Software Product Development by Mike Clement
Escaping the Pitfalls of Software Product DevelopmentEscaping the Pitfalls of Software Product Development
Escaping the Pitfalls of Software Product Development
Mike Clement154 views
Code Katas Spring 2012 by Mike Clement
Code Katas Spring 2012Code Katas Spring 2012
Code Katas Spring 2012
Mike Clement2.8K views
Linq (from the inside) by Mike Clement
Linq (from the inside)Linq (from the inside)
Linq (from the inside)
Mike Clement1.3K views
Bowling Game Kata in C# Adapted by Mike Clement
Bowling Game Kata in C# AdaptedBowling Game Kata in C# Adapted
Bowling Game Kata in C# Adapted
Mike Clement4.8K views
Code Katas: Practicing Your Craft by Mike Clement
Code Katas: Practicing Your CraftCode Katas: Practicing Your Craft
Code Katas: Practicing Your Craft
Mike Clement4.4K views
Software Craftsmanship by Mike Clement
Software CraftsmanshipSoftware Craftsmanship
Software Craftsmanship
Mike Clement947 views

Recently uploaded

Horror reddit story by
Horror reddit storyHorror reddit story
Horror reddit storytyronesmith1582
5 views1 slide
WATCH THIS YOUTUBE VIDEO by
WATCH THIS YOUTUBE VIDEOWATCH THIS YOUTUBE VIDEO
WATCH THIS YOUTUBE VIDEOolakanmijoel24
11 views1 slide
Maria Gjieli.pdf by
Maria Gjieli.pdfMaria Gjieli.pdf
Maria Gjieli.pdfget joys
18 views6 slides
LETTERS TO SANTA CLAUS by
LETTERS TO SANTA CLAUSLETTERS TO SANTA CLAUS
LETTERS TO SANTA CLAUSJudy 1028
12 views42 slides
https://pin.it/1TgD6Uq by
https://pin.it/1TgD6Uqhttps://pin.it/1TgD6Uq
https://pin.it/1TgD6Uqbestoto
5 views1 slide
MAHALAYA QUIZ.pptx by
MAHALAYA QUIZ.pptxMAHALAYA QUIZ.pptx
MAHALAYA QUIZ.pptxsouravkrpodder
17 views110 slides

Recently uploaded(15)

Maria Gjieli.pdf by get joys
Maria Gjieli.pdfMaria Gjieli.pdf
Maria Gjieli.pdf
get joys18 views
LETTERS TO SANTA CLAUS by Judy 1028
LETTERS TO SANTA CLAUSLETTERS TO SANTA CLAUS
LETTERS TO SANTA CLAUS
Judy 102812 views
https://pin.it/1TgD6Uq by bestoto
https://pin.it/1TgD6Uqhttps://pin.it/1TgD6Uq
https://pin.it/1TgD6Uq
bestoto5 views
What Makes an Excellent Short Film by Hampton Luzak
What Makes an Excellent Short FilmWhat Makes an Excellent Short Film
What Makes an Excellent Short Film
Hampton Luzak5 views
Lyric Presentation.pdf by ally508153
Lyric Presentation.pdfLyric Presentation.pdf
Lyric Presentation.pdf
ally50815310 views
Scratches in the Attic - Script.pdf by ColbyHoltman
Scratches in the Attic - Script.pdfScratches in the Attic - Script.pdf
Scratches in the Attic - Script.pdf
ColbyHoltman6 views
JADOO FLIX by Sagar.pptx by getseokey
JADOO FLIX by Sagar.pptxJADOO FLIX by Sagar.pptx
JADOO FLIX by Sagar.pptx
getseokey6 views
Free eBook ~ 200 GREAT PUNS.pdf by OH TEIK BIN
Free eBook ~ 200 GREAT PUNS.pdfFree eBook ~ 200 GREAT PUNS.pdf
Free eBook ~ 200 GREAT PUNS.pdf
OH TEIK BIN27 views
BOOTS PUT FOR SANTA by Judy 1028
BOOTS PUT FOR SANTABOOTS PUT FOR SANTA
BOOTS PUT FOR SANTA
Judy 102810 views
Perfect Wedding Hub Magazine Nov Edition by rakhiraajan
Perfect Wedding Hub Magazine Nov EditionPerfect Wedding Hub Magazine Nov Edition
Perfect Wedding Hub Magazine Nov Edition
rakhiraajan10 views
Retail Store Scavenger Hunt.pdf by RoxanneReed
Retail Store Scavenger Hunt.pdfRetail Store Scavenger Hunt.pdf
Retail Store Scavenger Hunt.pdf
RoxanneReed43 views

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

Editor's Notes

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