mirror of
https://github.com/github/semantic.git
synced 2024-12-26 08:25:19 +03:00
Choose from a strictly smaller k.
This commit is contained in:
parent
6627d40bf9
commit
2aed2e3d51
@ -78,20 +78,16 @@ extension UnannotatedTerm: Arbitrary {
|
||||
static func arbitrary(k: Int) -> Gen<UnannotatedTerm> {
|
||||
let symbol: Gen<String> = Gen<Int>.choose((0, 15)).fmap { "_\($0)" }
|
||||
let leaf: Gen<Term> = symbol.fmap { Term((), .Leaf($0)) }
|
||||
let indexed: Gen<Term> = Gen.sized { n in
|
||||
Gen<Int>.choose((0, n)).bind { n in
|
||||
let indexed: Gen<Term> = Gen<Int>.choose((0, k)).bind { n in
|
||||
sequence((0..<n).map { _ in arbitrary(k - 1) }).fmap {
|
||||
Term((), .Indexed($0.map { $0.term }))
|
||||
}
|
||||
}
|
||||
}
|
||||
let keyed: Gen<Term> = Gen.sized { n in
|
||||
Gen<Int>.choose((0, n)).bind { n in
|
||||
let keyed: Gen<Term> = Gen<Int>.choose((0, k)).bind { n in
|
||||
sequence((0..<n).map { _ in symbol.bind { key in Gen.pure(()).bind { arbitrary(k - 1) }.fmap { (key, $0.term) } } }).fmap {
|
||||
Term((), .Keyed(Dictionary(elements: $0)))
|
||||
}
|
||||
}
|
||||
}
|
||||
return Gen.oneOf([
|
||||
leaf,
|
||||
indexed,
|
||||
|
Loading…
Reference in New Issue
Block a user