Skip to content

Commit

Permalink
Fixes stack overflow in AED data generator
Browse files Browse the repository at this point in the history
Work done for #196
  • Loading branch information
atruskie committed Mar 27, 2020
1 parent 7a5a13e commit 6673ed4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
4 changes: 3 additions & 1 deletion tests/AED.Test/AcousticEventDetectionTest.fs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ let testJoinVerticalLines () =
testAll f

[<Fact>]
let aeToMatrixBounds () = chk (fun ae -> let m = aeToMatrix ae in m.NumRows = (height ae.Bounds) && m.NumCols = (width ae.Bounds))
let aeToMatrixBounds () =
chk (
fun ae -> let m = aeToMatrix ae in m.NumRows = (height ae.Bounds) && m.NumCols = (width ae.Bounds))

[<Fact>]
let aeToMatrixElements () =
Expand Down
18 changes: 10 additions & 8 deletions tests/AED.Test/FsCheckArbs.fs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
module FsCheckArbs
module FsCheckArbs

open FsCheck
open Acoustics.AED.GetAcousticEvents
open Acoustics.AED.Util

let nonNeg = Arb.generate<int>|> Gen.map abs
let nonNeg = Arb.generate<int> |> Gen.map abs

let pos = nonNeg |> Gen.map ((+) 1)

Expand All @@ -25,12 +25,14 @@ type ArbitraryModifiers =
override x.Generator = Gen.map4 (fun l t w h -> lengthsToRect l t w h) nonNeg nonNeg pos pos
}
static member AcousticEvent () =
{ new Arbitrary<AcousticEvent>()with
override x.Generator = gen { let! rect = Arb.generate
let r, b = right rect, bottom rect
let! c = Gen.choose (1, (height rect) * (width rect))
let! elms = pairGen (Gen.choose (rect.Top, b)) (Gen.choose (rect.Left, r)) |> replicateGenM c
return {Bounds=rect;Elements=Set.ofList elms}}}
{ new Arbitrary<AcousticEvent>() with
override x.Generator = gen { let! l = nonNeg
let! t = nonNeg
let! w = nonNeg
let! h = nonNeg
let! c = Gen.choose (1, w * h)
let! elms = pairGen (Gen.choose (t, t + h)) (Gen.choose (l, l + w)) |> replicateGenM c
return {Bounds=(lengthsToRect l t w h);Elements=Set.ofList elms}}}

let chk f =
Arb.register<ArbitraryModifiers>() |> ignore
Expand Down

0 comments on commit 6673ed4

Please sign in to comment.