SlideShare a Scribd company logo
1 of 143
Download to read offline
T E S T I N G 

T H E N E X T G E N E R AT I O N
M I K E H A R R I S
fscheck
specflow
is testing of

traits
specflow
is testing of

properties
fscheck
B E I N G
B E I N G
B E I N G
T H I N G S
B E I N G
T H I N G S 

A S M A R T I N H E I D E G G E R
S P E A K S O F T H E M I N
“ T H E O R I G I N O F T H E
W O R K O F A R T "
I N T E R P R E TAT I O N S O F T H I N G S
• substances with properties or as bearers of traits
• sense perceptions
• formed stuff
S U B S TA N C E S W I T H P R O P E R T I E S 

O R A S B E A R E R S O F T R A I T S
fscheck
specflow
is testing of

traits
specflow
is testing of

properties
fscheck
S U B S TA N C E S W I T H P R O P E R T I E S 

O R A S B E A R E R S O F T R A I T S
Testing of Traits
is testing of

traits
specflow
I N E E D A 

F I Z Z B U Z Z T R A N S L AT O R
C H E C K P O I N T


1 ) N O B M I ' D I V I S I B L E P O N G 3 F I Z Z J I C H E G H ' O H .
N O B M I ' D I V I S I B L E P O N G 5 B U Z Z J I C H E G H ' O H .
L AT L H S O ' M E H J I C H E G H ‘ O H .
!
2 ) ⎕ I O ← 0
( L , ' F I Z Z ' ' B U Z Z ' ' F I Z Z B U Z Z ' ) [ ¯ 1 +
( L × W = 0 ) + W ← ( 1 0 0 × ~ 0 = W ) + W ← ⊃ + / 1 2 × 0 = 3 5 |
⊂ L ← 1 + ⍳ 1 0 0 ]
S A M E PA G E !
C H E C K P O I N T


2 - > 2
3 - > F I Z Z
4 - > 4
5 - > B U Z Z
6 - > F I Z Z
M A K E I T S O .
F I Z Z B U Z Z
FizzBuzz(1 ) => “1”

FizzBuzz(2 ) => “2”
FizzBuzz(3 ) => “Fizz”
FizzBuzz(4 ) => “4”
FizzBuzz(5 ) => “Buzz”
FizzBuzz(6 ) => “Fizz”
…
FizzBuzz(15) => “FizzBuzz”
namespace FizzBuzz
{
public class FizzBuzzer
{
public string Translate(int value)
{
var result = string.Empty;
if (value % 3 == 0) result += "Fizz";
if (value % 5 == 0) result += "Buzz";
return string.IsNullOrEmpty(result) ? value.ToString() : result;
}
}
}
T E S T I N G T R A I T S
T H E N U N I T WAY
[TestCase( 2, Result = "2")]
[TestCase( 3, Result = "Fizz")]
[TestCase( 4, Result = "4")]
[TestCase( 5, Result = "Buzz")]
[TestCase( 6, Result = "Fizz")]
[TestCase(10, Result = "Buzz")]
[TestCase(15, Result = "FizzBuzz")]
[TestCase(45, Result = "FizzBuzz")]
public string FizzBuzz_Tests(int value)
{
return fizzbuzzer.Translate(value);
}
S P E C F L O W WAY
Feature: FizzBuzzerSpec
In order to be able to communicate with the
FizzBuzzons
As a Starfleet Captain
I want to be able to translate numbers to their
FizzBuzz value
Scenario: 2 must translate to the string 2
Given a FizzBuzzer
And the value of '2'
When translate is invoked
Then the result should be '2'
Scenario: 3 must translate to the string Fizz
Given a FizzBuzzer
And the value of '3'
When translate is invoked
Then the result should be 'Fizz'
Scenario: 5 must translate to the string Buzz
Given a FizzBuzzer
And the value of '5'
When translate is invoked
Then the result should be 'Buzz'
Scenario: 15 must translate to the string FizzBuzz
Given a FizzBuzzer
And the value of '15'
When translate is invoked
Then the result should be 'FizzBuzz'
Feature: FizzBuzzerSpec
In order to be able to communicate with the FizzBuzzons
As a Starfleet Captain
I want to be able to translate numbers to their FizzBuzz value
Scenario: 2 must translate to the string 2
Given a FizzBuzzer
And the value of '2'
When translate is invoked
Then the result should be '2'
Scenario: 3 must translate to the string Fizz
Given a FizzBuzzer
And the value of '3'
When translate is invoked
Then the result should be 'Fizz'
Scenario: 5 must translate to the string Buzz
Given a FizzBuzzer
And the value of '5'
When translate is invoked
Then the result should be 'Buzz'
Scenario: 15 must translate to the string FizzBuzz
Given a FizzBuzzer
And the value of '15'
When translate is invoked
Then the result should be 'FizzBuzz'
Feature: FizzBuzzerSpec
In order to be able to communicate with the
FizzBuzzons
As a Starfleet Captain
I want to be able to translate numbers to their
FizzBuzz value
Scenario: 2 must translate to the string 2
Given a FizzBuzzer
And the value of '2'
When translate is invoked
Then the result should be '2'
using FizzBuzz;
using TechTalk.SpecFlow;
using NUnit.Framework;
namespace FizzBuzzSpec
{
[Binding]
public class FizzBuzzerSpecSteps
{
[Given(@"a FizzBuzzer")]
public void GivenAFizzBuzzer()
{
ScenarioContext.Current.Add("FizzBuzzer", new FizzBuzzer());
}
[Given(@"the value of '(.*)'")]
public void GivenTheValueOf(int value)
{
ScenarioContext.Current.Add("value", value);
}
[When(@"translate is invoked")]
public void WhenTranslateIsInvoked()
{
var fizzbuzzer = ScenarioContext.Current.Get<FizzBuzzer>("FizzBuzzer");
var value = ScenarioContext.Current.Get<int>("value");
ScenarioContext.Current.Add("actual", fizzbuzzer.Translate(value));
}
[Then(@"the result should be '(.*)'")]
public void ThenTheResultShouldBe(string expected)
{
var actual = ScenarioContext.Current.Get<string>("actual");
Assert.That(expected, Is.EqualTo(actual));
}
}
}
Given a FizzBuzzer
!
[Given(@"a FizzBuzzer")]
public void GivenAFizzBuzzer()
{
ScenarioContext.Current.Add(
"FizzBuzzer", new FizzBuzzer());
}
And the value of '2'
!
[Given(@"the value of '(.*)'")]
public void GivenTheValueOf(int value)
{
ScenarioContext.Current.Add("value", value);
}
When translate is invoked
[When(@"translate is invoked")]
public void WhenTranslateIsInvoked()
{
var fizzbuzzer = ScenarioContext
.Current.Get<FizzBuzzer>("FizzBuzzer");
var value = ScenarioContext
.Current.Get<int>("value");
ScenarioContext
.Current.Add(
"actual", fizzbuzzer.Translate(value));
}
Then the result should be '2'
[Then(@"the result should be '(.*)'")]
public void ThenTheResultShouldBe(
string expected)
{
var actual = ScenarioContext
.Current.Get<string>("actual");
Assert.That(expected, Is.EqualTo(actual));
}
Scenario: 2 must translate to the string 2
Given a FizzBuzzer
And the value of '2'
When translate is invoked
Then the result should be '2'
Scenario: 5 must translate to the string Buzz
Given a FizzBuzzer
And the value of '5'
When translate is invoked
Then the result should be 'Buzz'
Given a FizzBuzzer
!
[Given(@"a FizzBuzzer")]
public void GivenAFizzBuzzer()
{
ScenarioContext.Current.Add(
"FizzBuzzer", new FizzBuzzer());
}
And the value of '5'
!
[Given(@"the value of '(.*)'")]
public void GivenTheValueOf(int value)
{
ScenarioContext.Current.Add("value", value);
}
When translate is invoked
[When(@"translate is invoked")]
public void WhenTranslateIsInvoked()
{
var fizzbuzzer = ScenarioContext
.Current.Get<FizzBuzzer>("FizzBuzzer");
var value = ScenarioContext
.Current.Get<int>("value");
ScenarioContext
.Current.Add(
"actual", fizzbuzzer.Translate(value));
}
Then the result should be 'Buzz'
[Then(@"the result should be '(.*)'")]
public void ThenTheResultShouldBe(
string expected)
{
var actual = ScenarioContext
.Current.Get<string>("actual");
Assert.That(expected, Is.EqualTo(actual));
}
Scenario: 2 must translate to the string 2
Given a FizzBuzzer
And the value of '2'
When translate is invoked
Then the result should be '2'
[NUnit.Framework.TestAttribute()]
[NUnit.Framework.DescriptionAttribute("2 must translate to the string 2")]
public virtual void _2MustTranslateToTheString2()
{
TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo(
"2 must translate to the string 2", ((string[])(null)));
#line 6
this.ScenarioSetup(scenarioInfo);
#line 7
testRunner.Given("a FizzBuzzer", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Given ");
#line 8
testRunner.And("the value of '2'", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And ");
#line 9
testRunner.When("translate is invoked", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "When ");
#line 10
testRunner.Then("the result should be '2'", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then ");
#line hidden
this.ScenarioCleanup();
}
G O O D , B U T N O T G R E AT.
Examples:
| value | expected value |
| 2 | 2 |
| 4 | 4 |
| 3 | Fizz |
| 9 | Fizz |
| 5 | Buzz |
| 25 | Buzz |
| 15 | FizzBuzz |
| 30 | FizzBuzz |
Scenario Outline: FizzBuzz translation
Given a FizzBuzzer
And the value of '<value>'
When translate is invoked
Then the result should be '<expected value>'
Examples:
| value | expected value |
| 2 | 2 |
| 4 | 4 |
| 3 | Fizz |
| 9 | Fizz |
| 5 | Buzz |
| 25 | Buzz |
| 15 | FizzBuzz |
| 30 | FizzBuzz |
[Given(@"a FizzBuzzer")]
public void GivenAFizzBuzzer()
{
ScenarioContext.Current.Add(
"FizzBuzzer", new FizzBuzzer());
}
[Given(@"the value of '(.*)'")]
public void GivenTheValueOf(int value)
{
ScenarioContext.Current.Add("value", value);
}
[When(@"translate is invoked")]
public void WhenTranslateIsInvoked()
{
var fizzbuzzer = ScenarioContext
.Current.Get<FizzBuzzer>("FizzBuzzer");
var value = ScenarioContext
.Current.Get<int>("value");
ScenarioContext
.Current.Add(
"actual", fizzbuzzer.Translate(value));
}
[Then(@"the result should be '(.*)'")]
public void ThenTheResultShouldBe(
string expected)
{
var actual = ScenarioContext
.Current.Get<string>("actual");
Assert.That(expected, Is.EqualTo(actual));
}
Examples:
| value | expected value |
| 2 | 2 |
| 4 | 4 |
| 3 | Fizz |
| 9 | Fizz |
| 5 | Buzz |
| 25 | Buzz |
| 15 | FizzBuzz |
| 30 | FizzBuzz |
[TestCase( 2, Result = "2")]
[TestCase( 3, Result = "Fizz")]
[TestCase( 4, Result = "4")]
[TestCase( 5, Result = "Buzz")]
[TestCase( 6, Result = "Fizz")]
[TestCase(10, Result = "Buzz")]
[TestCase(15, Result = "FizzBuzz")]
[TestCase(45, Result = "FizzBuzz")]
public string FizzBuzz_Tests(int value)
{
return fizzbuzzer.Translate(value);
}
Examples:
| value | expected value |
| 2 | 2 |
| 4 | 4 |
| 3 | Fizz |
| 9 | Fizz |
| 5 | Buzz |
| 25 | Buzz |
| 15 | FizzBuzz |
| 30 | FizzBuzz |
G R E AT.
"FizzBuzzSpecFizzBuzzSpecFizzBuzzerSpecFeature
_15MustTranslateToTheStringFizzBuzz","Passed","00:00:00.183","(loc
al)"
Given a FizzBuzzer
-> done: FizzBuzzerSpecSteps.GivenAFizzBuzzer() (0.0s)
And the value of '15'
-> done: FizzBuzzerSpecSteps.GivenTheValueOf(15) (0.0s)
When translate is invoked
-> done: FizzBuzzerSpecSteps.WhenTranslateIsInvoked() (0.0s)
Then the result should be 'FizzBuzz'
-> done: FizzBuzzerSpecSteps.ThenTheResultShouldBe("FizzBuzz")
(0.0s)
D O E S T H I S R E A L LY W O R K ? ! ?
W E C O U L D H AV E T H E 

S Y S T E M G E N E R AT E D ATA F O R U S 

T O I L L U S T R AT E T H E A D H E R E N C E O F P R O P E R T I E S
M A K E I T S O .
Testing of Properties
is testing of

properties
fscheck
T E S T I N G P R O P E R T I E S
T H E N U N I T WAY
[Test]
public void Divisible_By_3_Is_Fizz(
[Range(3, 300, 3)] int value)
{
var removeBuzz = (value % 5 == 0) ? 3 : value;
Assert.That(FizzBuzz(removeBuzz), Is.EqualTo("Fizz"));
}
[Test]
public void Divisible_By_5_Is_Buzz(
[Random(1, 10000, 100)] int value)
{
var removeFizz = (value % 3 == 0) ? 5 : value * 5;
Assert.That(FizzBuzz(removeFizz), Is.EqualTo("Buzz"));
}
F S C H E C K WAY
[TestCase]
public void Number_Divisible_By_3_Will_Return_Fizz()
{
Spec.ForAny<int>(value =>
_fizzBuzzer.Translate(value).Equals("Fizz"))
.When(value => value % 3 == 0 && value % 5 != 0)
.QuickCheckThrowOnFailure();
}
Ok, passed 100 tests.
[TestCase]
public void Number_Divisible_By_5_Will_Return_Buzz()
{
Spec.ForAny<int>(value =>
_fizzBuzzer.Translate(value).Equals("Buzz"))
.When(value => value % 3 != 0 && value % 5 == 0)
.QuickCheckThrowOnFailure();
}
Ok, passed 100 tests.
[TestCase]
public void Number_Divisible_By_15_Returns_FizzBuzz()
{
Spec.ForAny<int>(value =>
_fizzBuzzer.Translate(value).Equals("FizzBuzz"))
.Or(value => value % 15 != 0)
.QuickCheckThrowOnFailure();
}
Ok, passed 100 tests.
H M M M M
W E C O U L D C R E AT E A 

M O D E L T O D E M O N S T R AT E T H E 

R O B U S T N E S S O F T H E S O L U T I O N
M A K E I T S O .
T E S T I N G A G A I N S T 

A M O D E L
F S C H E C K WAY
class FizzBuzzModel
{
public static string Translate(int value)
{
if (value % 15 == 0) return "FizzBuzz";
if (value % 3 == 0) return "Fizz";
if (value % 5 == 0) return "Buzz";
return value.ToString(CultureInfo.InvariantCulture);
}
}
[TestCase]
public void Will_Match_Model()
{
Spec.ForAny<int>(value =>
FizzBuzzModel.Translate(value).Equals(_fizzBuzzer.Translate(value)))
.QuickCheckThrowOnFailure();
}
class FizzBuzzModel
{
public static string Translate(int value)
{
if (value % 15 == 0) return "FizzBuzz";
if (value % 3 == 0) return "Fizz";
if (value % 5 == 0) return "Buzz";
return value.ToString(CultureInfo.InvariantCulture);
}
}
[TestCase]
public void Will_Match_Model()
{
Spec.ForAny<int>(value =>
FizzBuzzModel.Translate(value)
.Equals(_fizzBuzzer.Translate(value)))
.QuickCheckThrowOnFailure();
}
Ok, passed 100 tests.
H M M M M
W E C O U L D U S E A 

S Y S T E M T O G E N E R AT E 

D E G E N E R AT I V E T E S T D ATA 

T O D I S P L AY C O R R E C T N E S S
M A K E I T S O .
T E S T I N G N E G AT I O N
F S C H E C K WAY
[TestCase]
public void Numbers_Not_Divisible_By_3_Do_Not_Fizz()
{
var noThrees =
from number in Any.OfType<int>()
where number%3 != 0
select number;
Spec.For(noThrees, x => _fizzBuzzer.Translate(x)
.Contains("Fizz") == false)
.QuickCheckThrowOnFailure();
}
Ok, passed 100 tests.
[TestCase]
public void Numbers_Not_Divisible_By_5_Do_Not_Buzz()
{
var noFives =
from number in Any.OfType<int>()
where number%5 != 0
select number;
Spec.For(noFives, x => _fizzBuzzer.Translate(x)
.Contains("Buzz") == false)
.QuickCheckThrowOnFailure();
}
Ok, passed 100 tests.
H M M M M
[TestCase]
public void Numbers_Divisible_By_15_Must_FizzBuzz()
{
var onlyFifteens =
from number in Any.OfType<int>()
where number%15 == 0
select number;
Spec.For(onlyFifteens, x => _fizzBuzzer.Translate(x)
.Equals("FizzBuzz"))
.QuickCheckThrowOnFailure();
}
Ok, passed 100 tests.
H M M M M
[TestCase]
public void Classify_Values()
{
Spec.ForAny<int>(x => true)
.Classify(

x => _fizzBuzzer.Translate(x).Equals("Fizz"), "Fizz")
.Classify(
x => _fizzBuzzer.Translate(x).Equals("Buzz"), "Buzz")
.Classify(x =>
_fizzBuzzer.Translate(x).Equals("FizzBuzz"), "FizzBuzz")
.Classify(x =>
_fizzBuzzer.Translate(x) != string.Empty, "Other")
.QuickCheckThrowOnFailure();
}
Ok, passed 100 tests.
55% Other.
22% Fizz, Other.
13% FizzBuzz, Other.
9% Buzz, Other.
H M M M M
[TestCase]
public void Collect_Values_For_Negatives()
{
Spec.ForAny<int>(x => true)
.When(x => x < 0)
.Collect(x => _fizzBuzzer.Translate(x))
.QuickCheckThrowOnFailure();
}
Ok, passed 100 tests.
G R E AT !
http://www.specflow.org/
specflow
https://github.com/fsharp/FsCheck
fscheck
T H A N K Y O U
M I K E H A R R I S 



@ M I K E M K H 

H T T P : / / C O M P - P H I L . B L O G S P O T. C O M /

More Related Content

What's hot

Tong Hop Bai Tap C
Tong Hop Bai Tap CTong Hop Bai Tap C
Tong Hop Bai Tap CSamQuiDaiBo
 
Beware: Sharp Tools
Beware: Sharp ToolsBeware: Sharp Tools
Beware: Sharp Toolschrismdp
 
R で解く FizzBuzz 問題
R で解く FizzBuzz 問題R で解く FizzBuzz 問題
R で解く FizzBuzz 問題Kosei ABE
 
5. php bangla tutorial php basic
5. php bangla tutorial php basic5. php bangla tutorial php basic
5. php bangla tutorial php basicSamimKhan19
 

What's hot (6)

Tong Hop Bai Tap C
Tong Hop Bai Tap CTong Hop Bai Tap C
Tong Hop Bai Tap C
 
Geb for browser automation
Geb for browser automationGeb for browser automation
Geb for browser automation
 
Beware: Sharp Tools
Beware: Sharp ToolsBeware: Sharp Tools
Beware: Sharp Tools
 
R で解く FizzBuzz 問題
R で解く FizzBuzz 問題R で解く FizzBuzz 問題
R で解く FizzBuzz 問題
 
Alias
AliasAlias
Alias
 
5. php bangla tutorial php basic
5. php bangla tutorial php basic5. php bangla tutorial php basic
5. php bangla tutorial php basic
 

Similar to Testing FizzBuzz Translations

FizzBuzz Guided Kata
FizzBuzz Guided KataFizzBuzz Guided Kata
FizzBuzz Guided KataMike Clement
 
ATS language overview
ATS language overviewATS language overview
ATS language overviewKiwamu Okabe
 
λ | Lenses
λ | Lensesλ | Lenses
λ | LensesOpen-IT
 
Bdd: Tdd and beyond the infinite
Bdd: Tdd and beyond the infiniteBdd: Tdd and beyond the infinite
Bdd: Tdd and beyond the infiniteGiordano Scalzo
 
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 designMassimo Iacolare
 
ScotRuby - Dark side of ruby
ScotRuby - Dark side of rubyScotRuby - Dark side of ruby
ScotRuby - Dark side of rubyGautam Rege
 
The Ring programming language version 1.5.3 book - Part 69 of 184
The Ring programming language version 1.5.3 book - Part 69 of 184The Ring programming language version 1.5.3 book - Part 69 of 184
The Ring programming language version 1.5.3 book - Part 69 of 184Mahmoud Samir Fayed
 

Similar to Testing FizzBuzz Translations (9)

FizzBuzz Guided Kata
FizzBuzz Guided KataFizzBuzz Guided Kata
FizzBuzz Guided Kata
 
FizzBuzz Trek
FizzBuzz TrekFizzBuzz Trek
FizzBuzz Trek
 
ATS language overview
ATS language overviewATS language overview
ATS language overview
 
λ | Lenses
λ | Lensesλ | Lenses
λ | Lenses
 
Bdd: Tdd and beyond the infinite
Bdd: Tdd and beyond the infiniteBdd: Tdd and beyond the infinite
Bdd: Tdd and beyond the infinite
 
Graph Algebra
Graph AlgebraGraph Algebra
Graph Algebra
 
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
 
ScotRuby - Dark side of ruby
ScotRuby - Dark side of rubyScotRuby - Dark side of ruby
ScotRuby - Dark side of ruby
 
The Ring programming language version 1.5.3 book - Part 69 of 184
The Ring programming language version 1.5.3 book - Part 69 of 184The Ring programming language version 1.5.3 book - Part 69 of 184
The Ring programming language version 1.5.3 book - Part 69 of 184
 

More from Mike Harris

A Divine Data Comedy
A Divine Data ComedyA Divine Data Comedy
A Divine Data ComedyMike Harris
 
Combinators - Lightning Talk
Combinators - Lightning TalkCombinators - Lightning Talk
Combinators - Lightning TalkMike Harris
 
Hiking through the Functional Forest with Fizz Buzz
Hiking through the Functional Forest with Fizz BuzzHiking through the Functional Forest with Fizz Buzz
Hiking through the Functional Forest with Fizz BuzzMike Harris
 
All You Need is Fold in the Key of C#
All You Need is Fold in the Key of C#All You Need is Fold in the Key of C#
All You Need is Fold in the Key of C#Mike Harris
 
All You Need is Fold
All You Need is FoldAll You Need is Fold
All You Need is FoldMike Harris
 
There and Back Again
There and Back AgainThere and Back Again
There and Back AgainMike Harris
 
The Marvelous Land of Higher Order Functions
The Marvelous Land of Higher Order FunctionsThe Marvelous Land of Higher Order Functions
The Marvelous Land of Higher Order FunctionsMike Harris
 
Learn You a Functional JavaScript for Great Good
Learn You a Functional JavaScript for Great GoodLearn You a Functional JavaScript for Great Good
Learn You a Functional JavaScript for Great GoodMike Harris
 

More from Mike Harris (10)

A Divine Data Comedy
A Divine Data ComedyA Divine Data Comedy
A Divine Data Comedy
 
Combinators - Lightning Talk
Combinators - Lightning TalkCombinators - Lightning Talk
Combinators - Lightning Talk
 
C# 7
C# 7C# 7
C# 7
 
Hiking through the Functional Forest with Fizz Buzz
Hiking through the Functional Forest with Fizz BuzzHiking through the Functional Forest with Fizz Buzz
Hiking through the Functional Forest with Fizz Buzz
 
Coding f#un
Coding f#unCoding f#un
Coding f#un
 
All You Need is Fold in the Key of C#
All You Need is Fold in the Key of C#All You Need is Fold in the Key of C#
All You Need is Fold in the Key of C#
 
All You Need is Fold
All You Need is FoldAll You Need is Fold
All You Need is Fold
 
There and Back Again
There and Back AgainThere and Back Again
There and Back Again
 
The Marvelous Land of Higher Order Functions
The Marvelous Land of Higher Order FunctionsThe Marvelous Land of Higher Order Functions
The Marvelous Land of Higher Order Functions
 
Learn You a Functional JavaScript for Great Good
Learn You a Functional JavaScript for Great GoodLearn You a Functional JavaScript for Great Good
Learn You a Functional JavaScript for Great Good
 

Recently uploaded

Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
Test Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendTest Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendArshad QA
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationkaushalgiri8080
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfCionsystems
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 

Recently uploaded (20)

Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
Test Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendTest Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and Backend
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanation
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdf
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 

Testing FizzBuzz Translations

  • 1. T E S T I N G 
 T H E N E X T G E N E R AT I O N M I K E H A R R I S
  • 2.
  • 6.
  • 7. B E I N G
  • 8.
  • 9.
  • 10.
  • 11.
  • 12. B E I N G
  • 13. B E I N G T H I N G S
  • 14. B E I N G T H I N G S 
 A S M A R T I N H E I D E G G E R S P E A K S O F T H E M I N “ T H E O R I G I N O F T H E W O R K O F A R T "
  • 15. I N T E R P R E TAT I O N S O F T H I N G S • substances with properties or as bearers of traits • sense perceptions • formed stuff
  • 16. S U B S TA N C E S W I T H P R O P E R T I E S 
 O R A S B E A R E R S O F T R A I T S
  • 17.
  • 21. S U B S TA N C E S W I T H P R O P E R T I E S 
 O R A S B E A R E R S O F T R A I T S
  • 22.
  • 25.
  • 26. I N E E D A 
 F I Z Z B U Z Z T R A N S L AT O R
  • 27. C H E C K P O I N T 
 1 ) N O B M I ' D I V I S I B L E P O N G 3 F I Z Z J I C H E G H ' O H . N O B M I ' D I V I S I B L E P O N G 5 B U Z Z J I C H E G H ' O H . L AT L H S O ' M E H J I C H E G H ‘ O H . ! 2 ) ⎕ I O ← 0 ( L , ' F I Z Z ' ' B U Z Z ' ' F I Z Z B U Z Z ' ) [ ¯ 1 + ( L × W = 0 ) + W ← ( 1 0 0 × ~ 0 = W ) + W ← ⊃ + / 1 2 × 0 = 3 5 | ⊂ L ← 1 + ⍳ 1 0 0 ]
  • 28. S A M E PA G E !
  • 29. C H E C K P O I N T 
 2 - > 2 3 - > F I Z Z 4 - > 4 5 - > B U Z Z 6 - > F I Z Z
  • 30. M A K E I T S O .
  • 31.
  • 32. F I Z Z B U Z Z
  • 33. FizzBuzz(1 ) => “1”
 FizzBuzz(2 ) => “2” FizzBuzz(3 ) => “Fizz” FizzBuzz(4 ) => “4” FizzBuzz(5 ) => “Buzz” FizzBuzz(6 ) => “Fizz” … FizzBuzz(15) => “FizzBuzz”
  • 34. namespace FizzBuzz { public class FizzBuzzer { public string Translate(int value) { var result = string.Empty; if (value % 3 == 0) result += "Fizz"; if (value % 5 == 0) result += "Buzz"; return string.IsNullOrEmpty(result) ? value.ToString() : result; } } }
  • 35. T E S T I N G T R A I T S
  • 36. T H E N U N I T WAY
  • 37. [TestCase( 2, Result = "2")] [TestCase( 3, Result = "Fizz")] [TestCase( 4, Result = "4")] [TestCase( 5, Result = "Buzz")] [TestCase( 6, Result = "Fizz")] [TestCase(10, Result = "Buzz")] [TestCase(15, Result = "FizzBuzz")] [TestCase(45, Result = "FizzBuzz")] public string FizzBuzz_Tests(int value) { return fizzbuzzer.Translate(value); }
  • 38. S P E C F L O W WAY
  • 39. Feature: FizzBuzzerSpec In order to be able to communicate with the FizzBuzzons As a Starfleet Captain I want to be able to translate numbers to their FizzBuzz value
  • 40. Scenario: 2 must translate to the string 2 Given a FizzBuzzer And the value of '2' When translate is invoked Then the result should be '2'
  • 41. Scenario: 3 must translate to the string Fizz Given a FizzBuzzer And the value of '3' When translate is invoked Then the result should be 'Fizz'
  • 42. Scenario: 5 must translate to the string Buzz Given a FizzBuzzer And the value of '5' When translate is invoked Then the result should be 'Buzz'
  • 43. Scenario: 15 must translate to the string FizzBuzz Given a FizzBuzzer And the value of '15' When translate is invoked Then the result should be 'FizzBuzz'
  • 44. Feature: FizzBuzzerSpec In order to be able to communicate with the FizzBuzzons As a Starfleet Captain I want to be able to translate numbers to their FizzBuzz value Scenario: 2 must translate to the string 2 Given a FizzBuzzer And the value of '2' When translate is invoked Then the result should be '2' Scenario: 3 must translate to the string Fizz Given a FizzBuzzer And the value of '3' When translate is invoked Then the result should be 'Fizz' Scenario: 5 must translate to the string Buzz Given a FizzBuzzer And the value of '5' When translate is invoked Then the result should be 'Buzz' Scenario: 15 must translate to the string FizzBuzz Given a FizzBuzzer And the value of '15' When translate is invoked Then the result should be 'FizzBuzz'
  • 45.
  • 46. Feature: FizzBuzzerSpec In order to be able to communicate with the FizzBuzzons As a Starfleet Captain I want to be able to translate numbers to their FizzBuzz value
  • 47. Scenario: 2 must translate to the string 2 Given a FizzBuzzer And the value of '2' When translate is invoked Then the result should be '2'
  • 48. using FizzBuzz; using TechTalk.SpecFlow; using NUnit.Framework; namespace FizzBuzzSpec { [Binding] public class FizzBuzzerSpecSteps { [Given(@"a FizzBuzzer")] public void GivenAFizzBuzzer() { ScenarioContext.Current.Add("FizzBuzzer", new FizzBuzzer()); } [Given(@"the value of '(.*)'")] public void GivenTheValueOf(int value) { ScenarioContext.Current.Add("value", value); } [When(@"translate is invoked")] public void WhenTranslateIsInvoked() { var fizzbuzzer = ScenarioContext.Current.Get<FizzBuzzer>("FizzBuzzer"); var value = ScenarioContext.Current.Get<int>("value"); ScenarioContext.Current.Add("actual", fizzbuzzer.Translate(value)); } [Then(@"the result should be '(.*)'")] public void ThenTheResultShouldBe(string expected) { var actual = ScenarioContext.Current.Get<string>("actual"); Assert.That(expected, Is.EqualTo(actual)); } } }
  • 49. Given a FizzBuzzer ! [Given(@"a FizzBuzzer")] public void GivenAFizzBuzzer() { ScenarioContext.Current.Add( "FizzBuzzer", new FizzBuzzer()); }
  • 50. And the value of '2' ! [Given(@"the value of '(.*)'")] public void GivenTheValueOf(int value) { ScenarioContext.Current.Add("value", value); }
  • 51. When translate is invoked [When(@"translate is invoked")] public void WhenTranslateIsInvoked() { var fizzbuzzer = ScenarioContext .Current.Get<FizzBuzzer>("FizzBuzzer"); var value = ScenarioContext .Current.Get<int>("value"); ScenarioContext .Current.Add( "actual", fizzbuzzer.Translate(value)); }
  • 52. Then the result should be '2' [Then(@"the result should be '(.*)'")] public void ThenTheResultShouldBe( string expected) { var actual = ScenarioContext .Current.Get<string>("actual"); Assert.That(expected, Is.EqualTo(actual)); }
  • 53. Scenario: 2 must translate to the string 2 Given a FizzBuzzer And the value of '2' When translate is invoked Then the result should be '2'
  • 54. Scenario: 5 must translate to the string Buzz Given a FizzBuzzer And the value of '5' When translate is invoked Then the result should be 'Buzz'
  • 55. Given a FizzBuzzer ! [Given(@"a FizzBuzzer")] public void GivenAFizzBuzzer() { ScenarioContext.Current.Add( "FizzBuzzer", new FizzBuzzer()); }
  • 56. And the value of '5' ! [Given(@"the value of '(.*)'")] public void GivenTheValueOf(int value) { ScenarioContext.Current.Add("value", value); }
  • 57. When translate is invoked [When(@"translate is invoked")] public void WhenTranslateIsInvoked() { var fizzbuzzer = ScenarioContext .Current.Get<FizzBuzzer>("FizzBuzzer"); var value = ScenarioContext .Current.Get<int>("value"); ScenarioContext .Current.Add( "actual", fizzbuzzer.Translate(value)); }
  • 58. Then the result should be 'Buzz' [Then(@"the result should be '(.*)'")] public void ThenTheResultShouldBe( string expected) { var actual = ScenarioContext .Current.Get<string>("actual"); Assert.That(expected, Is.EqualTo(actual)); }
  • 59.
  • 60.
  • 61.
  • 62. Scenario: 2 must translate to the string 2 Given a FizzBuzzer And the value of '2' When translate is invoked Then the result should be '2'
  • 63. [NUnit.Framework.TestAttribute()] [NUnit.Framework.DescriptionAttribute("2 must translate to the string 2")] public virtual void _2MustTranslateToTheString2() { TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo( "2 must translate to the string 2", ((string[])(null))); #line 6 this.ScenarioSetup(scenarioInfo); #line 7 testRunner.Given("a FizzBuzzer", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Given "); #line 8 testRunner.And("the value of '2'", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); #line 9 testRunner.When("translate is invoked", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "When "); #line 10 testRunner.Then("the result should be '2'", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); #line hidden this.ScenarioCleanup(); }
  • 64. G O O D , B U T N O T G R E AT.
  • 65.
  • 66. Examples: | value | expected value | | 2 | 2 | | 4 | 4 | | 3 | Fizz | | 9 | Fizz | | 5 | Buzz | | 25 | Buzz | | 15 | FizzBuzz | | 30 | FizzBuzz |
  • 67. Scenario Outline: FizzBuzz translation Given a FizzBuzzer And the value of '<value>' When translate is invoked Then the result should be '<expected value>' Examples: | value | expected value | | 2 | 2 | | 4 | 4 | | 3 | Fizz | | 9 | Fizz | | 5 | Buzz | | 25 | Buzz | | 15 | FizzBuzz | | 30 | FizzBuzz |
  • 68. [Given(@"a FizzBuzzer")] public void GivenAFizzBuzzer() { ScenarioContext.Current.Add( "FizzBuzzer", new FizzBuzzer()); }
  • 69. [Given(@"the value of '(.*)'")] public void GivenTheValueOf(int value) { ScenarioContext.Current.Add("value", value); }
  • 70. [When(@"translate is invoked")] public void WhenTranslateIsInvoked() { var fizzbuzzer = ScenarioContext .Current.Get<FizzBuzzer>("FizzBuzzer"); var value = ScenarioContext .Current.Get<int>("value"); ScenarioContext .Current.Add( "actual", fizzbuzzer.Translate(value)); }
  • 71. [Then(@"the result should be '(.*)'")] public void ThenTheResultShouldBe( string expected) { var actual = ScenarioContext .Current.Get<string>("actual"); Assert.That(expected, Is.EqualTo(actual)); }
  • 72. Examples: | value | expected value | | 2 | 2 | | 4 | 4 | | 3 | Fizz | | 9 | Fizz | | 5 | Buzz | | 25 | Buzz | | 15 | FizzBuzz | | 30 | FizzBuzz |
  • 73. [TestCase( 2, Result = "2")] [TestCase( 3, Result = "Fizz")] [TestCase( 4, Result = "4")] [TestCase( 5, Result = "Buzz")] [TestCase( 6, Result = "Fizz")] [TestCase(10, Result = "Buzz")] [TestCase(15, Result = "FizzBuzz")] [TestCase(45, Result = "FizzBuzz")] public string FizzBuzz_Tests(int value) { return fizzbuzzer.Translate(value); }
  • 74. Examples: | value | expected value | | 2 | 2 | | 4 | 4 | | 3 | Fizz | | 9 | Fizz | | 5 | Buzz | | 25 | Buzz | | 15 | FizzBuzz | | 30 | FizzBuzz |
  • 75. G R E AT.
  • 76.
  • 77.
  • 78.
  • 79.
  • 80.
  • 81.
  • 82. "FizzBuzzSpecFizzBuzzSpecFizzBuzzerSpecFeature _15MustTranslateToTheStringFizzBuzz","Passed","00:00:00.183","(loc al)" Given a FizzBuzzer -> done: FizzBuzzerSpecSteps.GivenAFizzBuzzer() (0.0s) And the value of '15' -> done: FizzBuzzerSpecSteps.GivenTheValueOf(15) (0.0s) When translate is invoked -> done: FizzBuzzerSpecSteps.WhenTranslateIsInvoked() (0.0s) Then the result should be 'FizzBuzz' -> done: FizzBuzzerSpecSteps.ThenTheResultShouldBe("FizzBuzz") (0.0s)
  • 83.
  • 84.
  • 85.
  • 86.
  • 87.
  • 88. D O E S T H I S R E A L LY W O R K ? ! ?
  • 89. W E C O U L D H AV E T H E 
 S Y S T E M G E N E R AT E D ATA F O R U S 
 T O I L L U S T R AT E T H E A D H E R E N C E O F P R O P E R T I E S
  • 90. M A K E I T S O .
  • 91.
  • 94. T E S T I N G P R O P E R T I E S
  • 95. T H E N U N I T WAY
  • 96. [Test] public void Divisible_By_3_Is_Fizz( [Range(3, 300, 3)] int value) { var removeBuzz = (value % 5 == 0) ? 3 : value; Assert.That(FizzBuzz(removeBuzz), Is.EqualTo("Fizz")); }
  • 97. [Test] public void Divisible_By_5_Is_Buzz( [Random(1, 10000, 100)] int value) { var removeFizz = (value % 3 == 0) ? 5 : value * 5; Assert.That(FizzBuzz(removeFizz), Is.EqualTo("Buzz")); }
  • 98. F S C H E C K WAY
  • 99. [TestCase] public void Number_Divisible_By_3_Will_Return_Fizz() { Spec.ForAny<int>(value => _fizzBuzzer.Translate(value).Equals("Fizz")) .When(value => value % 3 == 0 && value % 5 != 0) .QuickCheckThrowOnFailure(); }
  • 100. Ok, passed 100 tests.
  • 101. [TestCase] public void Number_Divisible_By_5_Will_Return_Buzz() { Spec.ForAny<int>(value => _fizzBuzzer.Translate(value).Equals("Buzz")) .When(value => value % 3 != 0 && value % 5 == 0) .QuickCheckThrowOnFailure(); }
  • 102. Ok, passed 100 tests.
  • 103. [TestCase] public void Number_Divisible_By_15_Returns_FizzBuzz() { Spec.ForAny<int>(value => _fizzBuzzer.Translate(value).Equals("FizzBuzz")) .Or(value => value % 15 != 0) .QuickCheckThrowOnFailure(); }
  • 104. Ok, passed 100 tests.
  • 105. H M M M M
  • 106. W E C O U L D C R E AT E A 
 M O D E L T O D E M O N S T R AT E T H E 
 R O B U S T N E S S O F T H E S O L U T I O N
  • 107. M A K E I T S O .
  • 108. T E S T I N G A G A I N S T 
 A M O D E L
  • 109. F S C H E C K WAY
  • 110. class FizzBuzzModel { public static string Translate(int value) { if (value % 15 == 0) return "FizzBuzz"; if (value % 3 == 0) return "Fizz"; if (value % 5 == 0) return "Buzz"; return value.ToString(CultureInfo.InvariantCulture); } } [TestCase] public void Will_Match_Model() { Spec.ForAny<int>(value => FizzBuzzModel.Translate(value).Equals(_fizzBuzzer.Translate(value))) .QuickCheckThrowOnFailure(); }
  • 111. class FizzBuzzModel { public static string Translate(int value) { if (value % 15 == 0) return "FizzBuzz"; if (value % 3 == 0) return "Fizz"; if (value % 5 == 0) return "Buzz"; return value.ToString(CultureInfo.InvariantCulture); } }
  • 112. [TestCase] public void Will_Match_Model() { Spec.ForAny<int>(value => FizzBuzzModel.Translate(value) .Equals(_fizzBuzzer.Translate(value))) .QuickCheckThrowOnFailure(); }
  • 113. Ok, passed 100 tests.
  • 114. H M M M M
  • 115. W E C O U L D U S E A 
 S Y S T E M T O G E N E R AT E 
 D E G E N E R AT I V E T E S T D ATA 
 T O D I S P L AY C O R R E C T N E S S
  • 116. M A K E I T S O .
  • 117. T E S T I N G N E G AT I O N
  • 118. F S C H E C K WAY
  • 119. [TestCase] public void Numbers_Not_Divisible_By_3_Do_Not_Fizz() { var noThrees = from number in Any.OfType<int>() where number%3 != 0 select number; Spec.For(noThrees, x => _fizzBuzzer.Translate(x) .Contains("Fizz") == false) .QuickCheckThrowOnFailure(); }
  • 120. Ok, passed 100 tests.
  • 121. [TestCase] public void Numbers_Not_Divisible_By_5_Do_Not_Buzz() { var noFives = from number in Any.OfType<int>() where number%5 != 0 select number; Spec.For(noFives, x => _fizzBuzzer.Translate(x) .Contains("Buzz") == false) .QuickCheckThrowOnFailure(); }
  • 122. Ok, passed 100 tests.
  • 123. H M M M M
  • 124. [TestCase] public void Numbers_Divisible_By_15_Must_FizzBuzz() { var onlyFifteens = from number in Any.OfType<int>() where number%15 == 0 select number; Spec.For(onlyFifteens, x => _fizzBuzzer.Translate(x) .Equals("FizzBuzz")) .QuickCheckThrowOnFailure(); }
  • 125. Ok, passed 100 tests.
  • 126. H M M M M
  • 127. [TestCase] public void Classify_Values() { Spec.ForAny<int>(x => true) .Classify(
 x => _fizzBuzzer.Translate(x).Equals("Fizz"), "Fizz") .Classify( x => _fizzBuzzer.Translate(x).Equals("Buzz"), "Buzz") .Classify(x => _fizzBuzzer.Translate(x).Equals("FizzBuzz"), "FizzBuzz") .Classify(x => _fizzBuzzer.Translate(x) != string.Empty, "Other") .QuickCheckThrowOnFailure(); }
  • 128. Ok, passed 100 tests. 55% Other. 22% Fizz, Other. 13% FizzBuzz, Other. 9% Buzz, Other.
  • 129. H M M M M
  • 130. [TestCase] public void Collect_Values_For_Negatives() { Spec.ForAny<int>(x => true) .When(x => x < 0) .Collect(x => _fizzBuzzer.Translate(x)) .QuickCheckThrowOnFailure(); }
  • 131. Ok, passed 100 tests.
  • 132. G R E AT !
  • 133.
  • 134.
  • 135.
  • 136.
  • 137.
  • 138.
  • 141.
  • 142. T H A N K Y O U
  • 143. M I K E H A R R I S 
 
 @ M I K E M K H 
 H T T P : / / C O M P - P H I L . B L O G S P O T. C O M /