小编net*_*oid的帖子

如何使用 xUnit 测试 F# 选项类型

我想在 F# 中使用 xUnit 对这段代码进行单元测试。我如何处理这些选项?

来自 Scott Wlaschin 的书:Domain Modeling Made Functional

type UnitQuantity = private UnitQuantity of int
// ^ private constructor

// define a module with the same name as the type
module UnitQuantity =
    /// Define a "smart constructor" for UnitQuantity
    /// int -> Result<UnitQuantity,string>
    let create qty =
        if qty < 1 then
            // failure
            Error "UnitQuantity can not be negative"
        else if qty > 1000 then
            // failure
            Error "UnitQuantity can not be more than …
Run Code Online (Sandbox Code Playgroud)

f# xunit.net

5
推荐指数
2
解决办法
690
查看次数

标签 统计

f# ×1

xunit.net ×1