Unit testing 我发现了一个bug,我使用reduce而不是reduceBack从函数列表中组合函数,我应该对此进行测试。 type Result = | Success of string let internal add5 x = x + 5 let intern

Unit testing 我发现了一个bug,我使用reduce而不是reduceBack从函数列表中组合函数,我应该对此进行测试。 type Result = | Success of string let internal add5 x = x + 5 let intern,unit-testing,f#,function-composition,Unit Testing,F#,Function Composition,我发现了一个bug,我使用reduce而不是reduceBack从函数列表中组合函数,我应该对此进行测试。 type Result = | Success of string let internal add5 x = x + 5 let internal mapResult number = Success (number.ToString()) type public InteropGuy internal (add, map) = member this.Add5A

我发现了一个bug,我使用
reduce
而不是
reduceBack
从函数列表中组合函数,我应该对此进行测试。
type Result =
| Success of string

let internal add5 x = x + 5

let internal mapResult number =
    Success (number.ToString())

type public InteropGuy internal (add, map) = 
    member this.Add5AndMap number =
        number |> (add >> map)

type InteropGuyFactory() =
    member this.CreateInteropGuy () =
        new InteropGuy(add5, mapResult)
[<TestClass>]
type InteropGuyTests() = 

    [<TestMethod>]
    member this.``Add5AndMap passes add5 result into map function``() = 

        let add5 _ = 13

        let tempResult = ref 0
        let mapResult result = 
            tempResult := result
            Success "unused result"

        let guy = new InteropGuy(add5, mapResult)

        guy.Add5AndMap 8 |> ignore

        Assert.AreEqual(13, !tempResult)
open Xunit
open Swensen.Unquote

[<Theory>]
[<InlineData(0, "5")>]
[<InlineData(1, "6")>]
[<InlineData(42, "47")>]
[<InlineData(1337, "1342")>]
let ``Add5AndMap returns expected result`` (number : int, expected : string) =
    let actual = InteropGuyFactory().CreateInteropGuy().Add5AndMap number
    Success expected =! actual
open FsCheck.Xunit
open Swensen.Unquote

[<Property>]
let ``Add5AndMap returns composed result`` (number : int) =
    let actual = InteropGuyFactory().CreateInteropGuy().Add5AndMap number

    let expected = number |> add5 |> mapResult
    expected =! actual