1

我尝试在 f#hedgehog 中创建一个整数列表。该列表应包含 10 到 20 个元素,并包含 0 到 5 之间的整数。

Gen.list (Range.linear 10 20) (Gen.int <| Range.constant 0 5) |> Gen.printSample

抛出异常:

=== Outcome ===
[5; 5; 2; 2; 0; 2; 3; 1; 1; 4]
=== Shrinks ===
> System.ArgumentException: The index is outside the legal range.
count = 9, distance past the list = 9
Parameter name: count
   at Microsoft.FSharp.Core.DetailedExceptions.invalidArgOutOfRange[?](String arg, Int32 index, String text, Int32 bound) in F:\workspace\_work\1\s\src\fsharp\FSharp.Core\local.fs:line 57
   at Microsoft.FSharp.Collections.ListModule.loop@474-29[a](Int32 count, Int32 i, FSharpList`1 lst) in F:\workspace\_work\1\s\src\fsharp\FSharp.Core\list.fs:line 477
   at Hedgehog.Gen.atLeast[a](Int32 n, FSharpList`1 xs)
   at Microsoft.FSharp.Collections.Internal.IEnumerator.next@193[T](FSharpFunc`2 f, IEnumerator`1 e, FSharpRef`1 started, Unit unitVar0) in F:\workspace\_work\1\s\src\fsharp\FSharp.Core\seq.fs:line 194
   at Microsoft.FSharp.Collections.Internal.IEnumerator.filter@188.System-Collections-IEnumerator-MoveNext() in F:\workspace\_work\1\s\src\fsharp\FSharp.Core\seq.fs:line 196
   at Microsoft.FSharp.Collections.Internal.IEnumerator.map@75.DoMoveNext(b& curr) in F:\workspace\_work\1\s\src\fsharp\FSharp.Core\seq.fs:line 77
   at Microsoft.FSharp.Collections.Internal.IEnumerator.MapEnumerator`1.System-Collections-IEnumerator-MoveNext() in F:\workspace\_work\1\s\src\fsharp\FSharp.Core\seq.fs:line 64
   at Hedgehog.Gen.PrintSample[a](Gen`1 g)
   at <StartupCode$FSI_0044>.$FSI_0044.main@()

因此,通常生成器会产生正确的结果,但收缩逻辑会出现问题。这是一个错误吗?我做错了吗?我是否错过了解释这一点的文档?

4

0 回答 0