Skip to content

Instantly share code, notes, and snippets.

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

smallgeek smallgeek

🤔
Now thinking...
View GitHub Profile
using System;
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
namespace FsAndroid1
@smallgeek
smallgeek / NaturalSpec_Tutorial_6_4.fs
Created August 26, 2012 08:06
NaturalSpec_Tutorial_6_4
Scenario: When sorting empty list
- Given []
– When sorting with QuickSort
=> It should be sorted
=> It should contain all elements from []
=> It should contain no other elements than []
==> Result is: []
==> OK
==> Time: 0.0355s
@smallgeek
smallgeek / NaturalSpec_Tutorial_6_3.fs
Created August 26, 2012 08:04
NaturalSpec_Tutorial_6_3
/// クイックソートの単純な実装 – 真似しないように
let rec quicksort = function
| [] -> []
| pivot :: rest ->
let small,big = List.partition ((>) pivot) rest
quicksort small @ [pivot] @ quicksort big
let QuickSort x =
printMethod ""
quicksort x
@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
@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_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_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_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_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_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