Skip to content

Instantly share code, notes, and snippets.

View smallgeek's full-sized avatar
🤔
Now thinking...

smallgeek smallgeek

🤔
Now thinking...
View GitHub Profile
@smallgeek
smallgeek / NaturalSpec_Tutorial_4_1.cs
Created August 26, 2012 06:49
NaturalSpec_Tutorial_4_1
namespace CarSellingLib
{
public interface IDealer
{
Car SellCar(int amount);
}
}
@smallgeek
smallgeek / NaturalSpec_Tutorial_4_2.fs
Created August 26, 2012 07:02
NaturalSpec_Tutorial_4_2
// 1. モジュールを定義する
module CarSpec
// 2. NaturalSpec 名前空間を開く
open NaturalSpec
// 3. プロジェクトの名前空間を開く
open CarSellingLib
// 再利用可能な値を定義する
@smallgeek
smallgeek / NaturalSpec_Tutorial_4_3.txt
Created August 26, 2012 07:03
NaturalSpec_Tutorial_4_3
Scenario: When selling a car for 30000 it should equal the DreamCar mocked
- As Bert
- With Mocking
- When selling a car for 30000
=> It should equal BMW (200 HP)
=> It should not equal Fiat (45 HP)
==> OK
@smallgeek
smallgeek / NaturalSpec_Tutorial_5_1.fs
Created August 26, 2012 07:23
NaturalSpec_Tutorial_5_1
// 定義済みのシナリオ
let factorialScenario x result =
Given x
|> When calculating factorial
|> It should equal result
[<Scenario>]
let When_calculation_factorial_of_1() =
factorialScenario 1 1
|> Verify
@smallgeek
smallgeek / NaturalSpec_Tutorial_5_2.txt
Created August 26, 2012 07:24
NaturalSpec_Tutorial_5_2
Scenario: When calculation factorial of 1 – Given 1
– When calculating factorial
=> It should equal 1
==> OK
==> Time: 0.0093s
@smallgeek
smallgeek / NaturalSpec_Tutorial_5_3.fs
Created August 26, 2012 07:26
NaturalSpec_Tutorial_5_3
// ScenarioTemplate 属性を使う
[<ScenarioTemplate(1, 1)>]
[<ScenarioTemplate(2, 2)>]
[<ScenarioTemplate(5, 120)>]
[<ScenarioTemplate(10, 3628800)>]
let When_calculating_fac_(x,result) =
Given x
|> When calculating factorial
|> It should equal result
|> Verify
@smallgeek
smallgeek / NaturalSpec_Tutorial_5_4.fs
Created August 26, 2012 07:27
NaturalSpec_Tutorial_5_4
/// シナリオのソースを使用する
let MyTestCases =
TestWith (tripleParam 12 3 4)
|> And (tripleParam 12 4 3)
|> And (tripleParam 12 6 2)
|> And (tripleParam 0 0 0)
|> ShouldFailWith (typeof<System.DivideByZeroException>)
|> And (tripleParam 1200 40 30)
@smallgeek
smallgeek / NaturalSpec_Tutorial_5_5.fs
Created August 26, 2012 07:31
NaturalSpec_Tutorial_5_5
let dividing_by a b = b / a
[<ScenarioSource "MyTestCases">]
let ``When dividing`` a b result =
Given a
|> When dividing_by b
|> It should equal result
|> Verify
@smallgeek
smallgeek / NaturalSpec_Tutorial_6_1.fs
Created August 26, 2012 08:02
NaturalSpec_Tutorial_6_1
/// 事前に定義されたソートのシナリオ
let sortingScenario f list =
Given list
|> When sorting_with f
|> It should be sorted
|> It should contain_all_elements_from list
|> It should contain_no_other_elements_than list
/// 事前に定義されたクイックソートのシナリオ
let quicksortScenario list = sortingScenario QuickSort list
@smallgeek
smallgeek / NaturalSpec_Tutorial_6_2.fs
Created August 26, 2012 08:03
NaturalSpec_Tutorial_6_2
[<Scenario>]
let When_sorting_empty_list() =
quicksortScenario []
|> Verify
[<Scenario>]
let When_sorting_small_list() =
quicksortScenario [2;1;8;15;5;22]
|> Verify