Skip to content

Commit

Permalink
Fix: shrink an array with minimal length lead to infinite loop
Browse files Browse the repository at this point in the history
Fix #76
  • Loading branch information
dubzzz committed Apr 22, 2018
1 parent 3187813 commit d6468dc
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/check/arbitrary/ArrayArbitrary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class ArrayArbitrary<T> extends Arbitrary<T[]> {
constructor(
readonly arb: Arbitrary<T>,
readonly minLength: number,
maxLength: number,
readonly maxLength: number,
readonly preFilter: (tab: Shrinkable<T>[]) => Shrinkable<T>[] = tab => tab
) {
super();
Expand Down Expand Up @@ -39,9 +39,11 @@ class ArrayArbitrary<T> extends Arbitrary<T[]> {
.map(l => items.slice(items.length - l.value))
.join(items[0].shrink().map(v => [v].concat(items.slice(1))))
.join(
this.shrinkImpl(items.slice(1), false)
.filter(vs => this.minLength <= vs.length + 1)
.map(vs => [items[0]].concat(vs))
items.length > this.minLength
? this.shrinkImpl(items.slice(1), false)
.filter(vs => this.minLength <= vs.length + 1)
.map(vs => [items[0]].concat(vs))
: Stream.nil<Shrinkable<T>[]>()
);
}
}
Expand Down

0 comments on commit d6468dc

Please sign in to comment.