Repository: dubzzz/fast-check
Pull request #1761 (2021-04-17 17:46:13)

🚚 Move stream arbitraries into /arbitrary
<!-- Why is this PR for? -->
<!-- Describe the reason why you opened this PR or give a link towards the associated issue. -->

## In a nutshell

❌ New feature
❌ Fix an issue
❌ Documentation improvement
✔️ Other: *moving code*

(✔️: yes, ❌: no)

## Potential impacts

None expected.


codesandbox[bot]: This pull request is automatically built and testable in [CodeSandbox](https://codesandbox.io).

  To see build info of the built libraries, click [here](https://ci.codesandbox.io/status/dubzzz/fast-check/pr/1761/builds/120839) or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 3517f8d9764d745e9a7d5c417bfc1614b5ffeed5:

|Sandbox| Source |
|--|--|
|[Vanilla](https://codesandbox.io/s/vanilla-8gedh)| Configuration |
|[fast-check-examples](https://codesandbox.io/s/fast-check-examples-fbzdb)| Configuration |

codecov[bot]: # [Codecov](https://codecov.io/gh/dubzzz/fast-check/pull/1761?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Nicolas+DUBIEN) Report
> Merging [#1761](https://codecov.io/gh/dubzzz/fast-check/pull/1761?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Nicolas+DUBIEN) (3517f8d) into [main](https://codecov.io/gh/dubzzz/fast-check/commit/553988194dcb366a1d12091f8df3602be6d38a55?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Nicolas+DUBIEN) (5539881) will **increase** coverage by `0.00%`.
> The diff coverage is `100.00%`.

[![Impacted file tree graph](https://codecov.io/gh/dubzzz/fast-check/pull/1761/graphs/tree.svg?width=650&height=150&src=pr&token=fRi2fJN730&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Nicolas+DUBIEN)](https://codecov.io/gh/dubzzz/fast-check/pull/1761?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Nicolas+DUBIEN)

```diff
@@           Coverage Diff           @@
##             main    #1761   +/-   ##
=======================================
  Coverage   96.90%   96.90%           
=======================================
  Files         115      116    +1     
  Lines        3620     3622    +2     
  Branches      715      715           
=======================================
+ Hits         3508     3510    +2     
  Misses        108      108           
  Partials        4        4           
```

| Flag | Coverage Δ | |
|---|---|---|
| unit-tests | `96.90% <100.00%> (+<0.01%)` | :arrow_up: |
| unit-tests-10.x-Linux | `?` | |
| unit-tests-12.x-Linux | `96.90% <100.00%> (+<0.01%)` | :arrow_up: |
| unit-tests-14.x-Linux | `?` | |

Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Nicolas+DUBIEN#carryforward-flags-in-the-pull-request-comment) to find out more.

| [Impacted Files](https://codecov.io/gh/dubzzz/fast-check/pull/1761?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Nicolas+DUBIEN) | Coverage Δ | |
|---|---|---|
| [src/arbitrary/\_internals/StreamArbitrary.ts](https://codecov.io/gh/dubzzz/fast-check/pull/1761/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Nicolas+DUBIEN#diff-c3JjL2FyYml0cmFyeS9faW50ZXJuYWxzL1N0cmVhbUFyYml0cmFyeS50cw==) | `92.00% <100.00%> (ø)` | |
| [src/arbitrary/infiniteStream.ts](https://codecov.io/gh/dubzzz/fast-check/pull/1761/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Nicolas+DUBIEN#diff-c3JjL2FyYml0cmFyeS9pbmZpbml0ZVN0cmVhbS50cw==) | `100.00% <100.00%> (ø)` | |
| [src/fast-check-default.ts](https://codecov.io/gh/dubzzz/fast-check/pull/1761/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Nicolas+DUBIEN#diff-c3JjL2Zhc3QtY2hlY2stZGVmYXVsdC50cw==) | `100.00% <100.00%> (ø)` | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/dubzzz/fast-check/pull/1761?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Nicolas+DUBIEN).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Nicolas+DUBIEN)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/dubzzz/fast-check/pull/1761?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Nicolas+DUBIEN). Last update [5539881...3517f8d](https://codecov.io/gh/dubzzz/fast-check/pull/1761?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Nicolas+DUBIEN). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Nicolas+DUBIEN).


Patch:
diff --git a/src/check/arbitrary/CloneArbitrary.ts b/src/arbitrary/_internals/CloneArbitrary.ts
similarity index 70%
rename from src/check/arbitrary/CloneArbitrary.ts
rename to src/arbitrary/_internals/CloneArbitrary.ts
index 03a90c65..d07a97ad 100644
--- a/src/check/arbitrary/CloneArbitrary.ts
+++ b/src/arbitrary/_internals/CloneArbitrary.ts
@@ -1,13 +1,11 @@
+import { NextArbitrary } from '../../check/arbitrary/definition/NextArbitrary';
+import { NextValue } from '../../check/arbitrary/definition/NextValue';
+import { cloneMethod } from '../../check/symbols';
 import { Random } from '../../random/generator/Random';
 import { Stream } from '../../stream/Stream';
-import { cloneMethod } from '../symbols';
-import { Arbitrary } from './definition/Arbitrary';
-import { convertFromNext, convertToNext } from './definition/Converters';
-import { NextArbitrary } from './definition/NextArbitrary';
-import { NextValue } from './definition/NextValue';
 
 /** @internal */
-class CloneArbitrary<T> extends NextArbitrary<T[]> {
+export class CloneArbitrary<T> extends NextArbitrary<T[]> {
   constructor(readonly arb: NextArbitrary<T>, readonly numValues: number) {
     super();
   }
@@ -86,35 +84,3 @@ class CloneArbitrary<T> extends NextArbitrary<T[]> {
     return new NextValue(vs, contexts);
   }
 }
-
-/**
- * Type of the value produced by {@link clone}
- * @remarks Since 2.5.0
- * @public
- */
-export type CloneValue<T, N extends number> = N extends 0
-  ? []
-  : N extends 1
-  ? [T]
-  : N extends 2
-  ? [T, T]
-  : N extends 3
-  ? [T, T, T]
-  : N extends 4
-  ? [T, T, T, T]
-  : T[];
-
-/**
- * Clone the values generated by `arb` in order to produce fully equal values (might not be equal in terms of === or ==)
- *
- * @param arb - Source arbitrary
- * @param numValues - Number of values to produce
- *
- * @remarks Since 2.5.0
- * @public
- */
-function clone<T, N extends number>(arb: Arbitrary<T>, numValues: N): Arbitrary<CloneValue<T, N>>;
-function clone<T>(arb: Arbitrary<T>, numValues: number): Arbitrary<T[]> {
-  return convertFromNext(new CloneArbitrary(convertToNext(arb), numValues));
-}
-export { clone };
diff --git a/src/check/arbitrary/StreamArbitrary.ts b/src/arbitrary/_internals/StreamArbitrary.ts
similarity index 66%
rename from src/check/arbitrary/StreamArbitrary.ts
rename to src/arbitrary/_internals/StreamArbitrary.ts
index bd8fead3..2d7e296c 100644
--- a/src/check/arbitrary/StreamArbitrary.ts
+++ b/src/arbitrary/_internals/StreamArbitrary.ts
@@ -1,14 +1,12 @@
+import { NextArbitrary } from '../../check/arbitrary/definition/NextArbitrary';
+import { NextValue } from '../../check/arbitrary/definition/NextValue';
+import { cloneMethod } from '../../check/symbols';
 import { Random } from '../../random/generator/Random';
 import { Stream } from '../../stream/Stream';
 import { stringify } from '../../utils/stringify';
-import { cloneMethod } from '../symbols';
-import { Arbitrary } from './definition/Arbitrary';
-import { convertFromNext, convertToNext } from './definition/Converters';
-import { NextArbitrary } from './definition/NextArbitrary';
-import { NextValue } from './definition/NextValue';
 
 /** @internal */
-class StreamArbitrary<T> extends NextArbitrary<Stream<T>> {
+export class StreamArbitrary<T> extends NextArbitrary<Stream<T>> {
   constructor(readonly arb: NextArbitrary<T>) {
     super();
   }
@@ -42,19 +40,3 @@ class StreamArbitrary<T> extends NextArbitrary<Stream<T>> {
     return Stream.nil();
   }
 }
-
-/**
- * Produce an infinite stream of values
- *
- * WARNING: Requires Object.assign
- *
- * @param arb - Arbitrary used to generate the values
- *
- * @remarks Since 1.8.0
- * @public
- */
-function infiniteStream<T>(arb: Arbitrary<T>): Arbitrary<Stream<T>> {
-  return convertFromNext(new StreamArbitrary(convertToNext(arb)));
-}
-
-export { infiniteStream };
diff --git a/src/arbitrary/clone.ts b/src/arbitrary/clone.ts
new file mode 100644
index 00000000..a423aae7
--- /dev/null
+++ b/src/arbitrary/clone.ts
@@ -0,0 +1,35 @@
+import { Arbitrary } from '../check/arbitrary/definition/Arbitrary';
+import { convertFromNext, convertToNext } from '../check/arbitrary/definition/Converters';
+import { CloneArbitrary } from './_internals/CloneArbitrary';
+
+/**
+ * Type of the value produced by {@link clone}
+ * @remarks Since 2.5.0
+ * @public
+ */
+export type CloneValue<T, N extends number> = N extends 0
+  ? []
+  : N extends 1
+  ? [T]
+  : N extends 2
+  ? [T, T]
+  : N extends 3
+  ? [T, T, T]
+  : N extends 4
+  ? [T, T, T, T]
+  : T[];
+
+/**
+ * Clone the values generated by `arb` in order to produce fully equal values (might not be equal in terms of === or ==)
+ *
+ * @param arb - Source arbitrary
+ * @param numValues - Number of values to produce
+ *
+ * @remarks Since 2.5.0
+ * @public
+ */
+function clone<T, N extends number>(arb: Arbitrary<T>, numValues: N): Arbitrary<CloneValue<T, N>>;
+function clone<T>(arb: Arbitrary<T>, numValues: number): Arbitrary<T[]> {
+  return convertFromNext(new CloneArbitrary(convertToNext(arb), numValues));
+}
+export { clone };
diff --git a/src/check/arbitrary/DedupArbitrary.ts b/src/arbitrary/dedup.ts
similarity index 83%
rename from src/check/arbitrary/DedupArbitrary.ts
rename to src/arbitrary/dedup.ts
index 5f76836d..71e60c4d 100644
--- a/src/check/arbitrary/DedupArbitrary.ts
+++ b/src/arbitrary/dedup.ts
@@ -1,4 +1,4 @@
-import { clone, CloneValue } from './CloneArbitrary';
+import { clone, CloneValue } from './clone';
 
 /**
  * @deprecated Switch to {@link CloneValue} instead
diff --git a/src/check/arbitrary/AsyncSchedulerArbitrary.ts b/src/check/arbitrary/AsyncSchedulerArbitrary.ts
index 9b223d26..08fde94c 100644
--- a/src/check/arbitrary/AsyncSchedulerArbitrary.ts
+++ b/src/check/arbitrary/AsyncSchedulerArbitrary.ts
@@ -1,9 +1,12 @@
 import { cloneMethod } from '../symbols';
 import { Random } from '../../random/generator/Random';
 import { Arbitrary } from './definition/Arbitrary';
-import { Shrinkable } from './definition/Shrinkable';
 import { stringify } from '../../utils/stringify';
 import { escapeForTemplateString } from './helpers/TextEscaper';
+import { NextArbitrary } from './definition/NextArbitrary';
+import { convertFromNext } from './definition/Converters';
+import { Stream } from '../../fast-check-default';
+import { NextValue } from './definition/NextValue';
 
 /**
  * Define an item to be passed to `scheduleSequence`
@@ -391,12 +394,12 @@ class SchedulerImplem<TMetaData> implements Scheduler<TMetaData> {
 }
 
 /** @internal */
-class SchedulerArbitrary<TMetaData> extends Arbitrary<Scheduler<TMetaData>> {
+class SchedulerArbitrary<TMetaData> extends NextArbitrary<Scheduler<TMetaData>> {
   constructor(readonly act: (f: () => Promise<void>) => Promise<unknown>) {
     super();
   }
 
-  generate(mrng: Random) {
+  generate(mrng: Random, _biasFactor: number | undefined): NextValue<Scheduler<TMetaData>> {
     const buildNextTaskIndex = (r: Random) => {
       return {
         clone: () => buildNextTaskIndex(r.clone()),
@@ -405,7 +408,17 @@ class SchedulerArbitrary<TMetaData> extends Arbitrary<Scheduler<TMetaData>> {
         },
       };
     };
-    return new Shrinkable(new SchedulerImplem<TMetaData>(this.act, buildNextTaskIndex(mrng.clone())));
+    return new NextValue(new SchedulerImplem<TMetaData>(this.act, buildNextTaskIndex(mrng.clone())));
+  }
+
+  canGenerate(value: unknown): value is Scheduler<TMetaData> {
+    // Not supported yet
+    return false;
+  }
+
+  shrink(_value: Scheduler<TMetaData>, _context?: unknown): Stream<NextValue<Scheduler<TMetaData>>> {
+    // Not supported yet
+    return Stream.nil();
   }
 }
 
@@ -416,7 +429,7 @@ class SchedulerArbitrary<TMetaData> extends Arbitrary<Scheduler<TMetaData>> {
  */
 function scheduler<TMetaData = unknown>(constraints?: SchedulerConstraints): Arbitrary<Scheduler<TMetaData>> {
   const { act = (f: () => Promise<void>) => f() } = constraints || {};
-  return new SchedulerArbitrary<TMetaData>(act);
+  return convertFromNext(new SchedulerArbitrary<TMetaData>(act));
 }
 
 /**
diff --git a/src/fast-check-default.ts b/src/fast-check-default.ts
index 48c40f0e..dfefbfaf 100644
--- a/src/fast-check-default.ts
+++ b/src/fast-check-default.ts
@@ -32,8 +32,8 @@ import { constant } from './arbitrary/constant';
 import { constantFrom } from './arbitrary/constantFrom';
 import { context, ContextValue } from './arbitrary/context';
 import { date } from './check/arbitrary/DateArbitrary';
-import { clone, CloneValue } from './check/arbitrary/CloneArbitrary';
-import { dedup, DedupValue } from './check/arbitrary/DedupArbitrary';
+import { clone, CloneValue } from './arbitrary/clone';
+import { dedup, DedupValue } from './arbitrary/dedup';
 import { Arbitrary } from './check/arbitrary/definition/Arbitrary';
 import { Shrinkable } from './check/arbitrary/definition/Shrinkable';
 import { dictionary } from './check/arbitrary/DictionaryArbitrary';
@@ -66,7 +66,7 @@ import { oneof, OneOfValue, OneOfConstraints } from './arbitrary/oneof';
 import { option, OptionConstraints } from './arbitrary/option';
 import { record, RecordConstraints, RecordValue } from './check/arbitrary/RecordArbitrary';
 import { set, SetConstraints } from './arbitrary/set';
-import { infiniteStream } from './check/arbitrary/StreamArbitrary';
+import { infiniteStream } from './arbitrary/infiniteStream';
 import {
   asciiString,
   base64String,


Test patch:
diff --git a/src/arbitrary/infiniteStream.ts b/src/arbitrary/infiniteStream.ts
new file mode 100644
index 00000000..2fa4d2a2
--- /dev/null
+++ b/src/arbitrary/infiniteStream.ts
@@ -0,0 +1,20 @@
+import { Stream } from '../stream/Stream';
+import { Arbitrary } from '../check/arbitrary/definition/Arbitrary';
+import { convertFromNext, convertToNext } from '../check/arbitrary/definition/Converters';
+import { StreamArbitrary } from './_internals/StreamArbitrary';
+
+/**
+ * Produce an infinite stream of values
+ *
+ * WARNING: Requires Object.assign
+ *
+ * @param arb - Arbitrary used to generate the values
+ *
+ * @remarks Since 1.8.0
+ * @public
+ */
+function infiniteStream<T>(arb: Arbitrary<T>): Arbitrary<Stream<T>> {
+  return convertFromNext(new StreamArbitrary(convertToNext(arb)));
+}
+
+export { infiniteStream };
diff --git a/test/unit/check/arbitrary/CloneArbitrary.spec.ts b/test/unit/arbitrary/CloneArbitrary.spec.ts
similarity index 77%
rename from test/unit/check/arbitrary/CloneArbitrary.spec.ts
rename to test/unit/arbitrary/CloneArbitrary.spec.ts
index a1c08070..8112b6fb 100644
--- a/test/unit/check/arbitrary/CloneArbitrary.spec.ts
+++ b/test/unit/arbitrary/CloneArbitrary.spec.ts
@@ -1,16 +1,16 @@
-import * as fc from '../../../../lib/fast-check';
+import * as fc from '../../../lib/fast-check';
 
-import { clone } from '../../../../src/check/arbitrary/CloneArbitrary';
-import { nat } from '../../../../src/arbitrary/nat';
+import { clone } from '../../../src/arbitrary/clone';
+import { nat } from '../../../src/arbitrary/nat';
 
-import * as genericHelper from './generic/GenericArbitraryHelper';
+import * as genericHelper from '../check/arbitrary/generic/GenericArbitraryHelper';
 
-import * as stubRng from '../../stubs/generators';
-import { hasCloneMethod } from '../../../../src/check/symbols';
-import { context } from '../../../../src/arbitrary/context';
-import { cloneMethod } from '../../../../lib/fast-check';
-import { Arbitrary } from '../../../../src/check/arbitrary/definition/Arbitrary';
-import { Shrinkable } from '../../../../src/check/arbitrary/definition/Shrinkable';
+import * as stubRng from '../stubs/generators';
+import { hasCloneMethod } from '../../../src/check/symbols';
+import { context } from '../../../src/arbitrary/context';
+import { cloneMethod } from '../../../lib/fast-check';
+import { Arbitrary } from '../../../src/check/arbitrary/definition/Arbitrary';
+import { Shrinkable } from '../../../src/check/arbitrary/definition/Shrinkable';
 
 export const isStrictlySmaller = (arr1: number[], arr2: number[]): boolean => {
   for (let idx = 0; idx !== arr1.length; ++idx) {
diff --git a/test/unit/check/arbitrary/StreamArbitrary.spec.ts b/test/unit/arbitrary/StreamArbitrary.spec.ts
similarity index 88%
rename from test/unit/check/arbitrary/StreamArbitrary.spec.ts
rename to test/unit/arbitrary/StreamArbitrary.spec.ts
index 43bd6c27..c4fa0597 100644
--- a/test/unit/check/arbitrary/StreamArbitrary.spec.ts
+++ b/test/unit/arbitrary/StreamArbitrary.spec.ts
@@ -1,14 +1,14 @@
-import * as fc from '../../../../lib/fast-check';
+import * as fc from '../../../lib/fast-check';
 
-import { context } from '../../../../src/arbitrary/context';
-import { nat } from '../../../../src/arbitrary/nat';
-import { infiniteStream } from '../../../../src/check/arbitrary/StreamArbitrary';
-import { Stream } from '../../../../src/stream/Stream';
+import { context } from '../../../src/arbitrary/context';
+import { nat } from '../../../src/arbitrary/nat';
+import { infiniteStream } from '../../../src/arbitrary/infiniteStream';
+import { Stream } from '../../../src/stream/Stream';
 
-import * as genericHelper from './generic/GenericArbitraryHelper';
+import * as genericHelper from '../check/arbitrary/generic/GenericArbitraryHelper';
 
-import * as stubRng from '../../stubs/generators';
-import { hasCloneMethod, cloneMethod, WithCloneMethod } from '../../../../src/check/symbols';
+import * as stubRng from '../stubs/generators';
+import { hasCloneMethod, cloneMethod, WithCloneMethod } from '../../../src/check/symbols';
 
 describe('StreamArbitrary', () => {
   describe('infiniteStream', () => {