Skip to content
This repository has been archived by the owner on Jan 2, 2024. It is now read-only.

Commit

Permalink
fix: randomize NonEmptyArray elements independently
Browse files Browse the repository at this point in the history
  • Loading branch information
holvonixAdvay committed Aug 10, 2019
1 parent 7e01e15 commit 818a366
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/experimental.ts
@@ -1,6 +1,7 @@
import { Fuzzer } from './fuzzer';
import * as t from 'io-ts';
import { NonEmptyArray, cons } from 'fp-ts/lib/NonEmptyArray';
import { rng } from './rng';

/**
* @experimental 4.1.0 This will be superseded by a generic handler for NonEmptyArrays in io-ts-types when https://github.com/gcanti/io-ts-types/issues/102 is fixed.
Expand All @@ -14,7 +15,11 @@ export const nonEmptyArrayFuzzer = <T>(
type: 'fuzzer',
children: [c, t.array(c)],
func: (ctx, n0, hc, ha) => {
return cons(hc.encode([n0, ctx]) as T, ha.encode([n0, ctx]) as T[]);
const r = rng(n0);
return cons(
hc.encode([r.int32(), ctx]) as T,
ha.encode([r.int32(), ctx]) as T[]
);
},
},
});

0 comments on commit 818a366

Please sign in to comment.