【问题标题】:FsCheck NUnit . Tests with conditionFsCheck NUnit 。有条件的测试
【发布时间】:2010-05-22 23:53:31
【问题描述】:

我正在尝试对此功能进行测试

let extract_one_rule (rule:Rule.t<'a,'b>) = 
    let rec expand = function
    |PAlt     (a,b) -> expand a  @ expand b
    |PSeq     (a,b) -> let wrap = List.map (fun x -> (x.rule, fun r -> {x with rule = r})) a
                                  |> List.unzip
                       in
                       let rec gen = function
                           | hd::tl -> [for x in hd -> x :: ( gen tl |> List.concat)]
                           | []     -> []
                       in 
                       fst wrap |> List.map expand |> gen 
                       |> List.map (fun x -> PSeq ((List.map2 ( |> ) x (snd wrap)),b))
    |PRef   _ 
    |PLiteral _
    |PToken   _ as t   -> [t]
    | _             -> (System.Console.WriteLine("incorrect tree for alternative expanding!")
                        ; failwith "incorrect tree for alternative expanding!")
    in 
    expand rule.body |> List.map (fun x -> {rule with body = x})

使用 FsCheck 所以我有这个

let ExpandAlterTest(t : Rule.t<Source.t,Source.t> ) = convertToMeta t |> List.forall (fun x -> ruleIsAfterEBNF x)

但我会看到异常“替代扩展的树不正确!” 但是当我像那样使用smth时

let ExpandAlterTest(t : Rule.t<Source.t,Source.t> ) = (correctForAlExp t.body) ==> lazy ( convertToMeta t |> List.forall (fun x -> ruleIsAfterEBNF x))

NUnit 不会停止工作 为什么会这样?

【问题讨论】:

    标签: f# nunit fscheck


    【解决方案1】:

    可能是您添加的前提条件非常严格,因此需要很长时间才能找到一个好的值(实际上通过前提条件的值)。 FsCheck 对此进行了强化 - 默认情况下,它会尝试查找 100 个值,但当它拒绝 1000 个时它会放弃,您应该会看到“在 x 测试后用尽参数”输出。但是,如果生成和检查值需要很长时间,这可能需要很长时间。

    也可能是您实际上在某处存在错误,例如无限循环。

    尝试更改 FsCheck 配置以运行更少的测试,执行详细运行 (verboseCheck),并在调试器似乎挂起时中断。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-24
      • 1970-01-01
      • 2011-04-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多