You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
By comparison, replacing oneOf with the following:
def frequency' (default: Gen α) (xs: List (Nat × Gen α)) : Gen α := do
let n ← choose Nat 0 total
pick n xs
where
total := List.sum (Prod.fst <$> xs)
pick n xs := match xs with
| [] => default
| (k, x) :: xs => if n <= k then x else pick (n - k) xs
def frequency [Inhabited α] (xs: List (Nat × Gen α)) : Gen α :=
frequency' xs.head!.snd xs
def testGen : Gen Nat :=
frequency [ (100, pure 1), (100, pure 2)]
We should remove potentially unsafe operations like get! from LSpec
The text was updated successfully, but these errors were encountered:
LSpec/LSpec/SlimCheck/Gen.lean
Line 69 in 8ff5984
Array.get! in
oneOf
and similar functions can runtime-errorthrows
at runtime when running a Slimcheck property test. Furthermore
Worse, this error is not detected by default
lspecIO
hooks and reports a passing test, only shows up when running:By comparison, replacing
oneOf
with the following:We should remove potentially unsafe operations like
get!
from LSpecThe text was updated successfully, but these errors were encountered: