Repository: dubzzz/fast-check
Pull request #1715 (2021-04-09 18:40:17)

🚚 Move bigint 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: *please explain*

(✔️: yes, ❌: no)

## Potential impacts

No impact is expected as IDE fail to import the right paths with auto-imports different from root.
Non-root import changed for `bigInt`, `bigUint`, `bigIntN`, `bigUintN`


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/1715/builds/118109) or the icon next to each commit SHA.

Latest deployment of this branch, based on commit a605edb4ca09d85920ccd42395a1b6a1b274daa0:

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

codecov[bot]: # [Codecov](https://codecov.io/gh/dubzzz/fast-check/pull/1715?src=pr&el=h1) Report
> Merging [#1715](https://codecov.io/gh/dubzzz/fast-check/pull/1715?src=pr&el=desc) (a605edb) into [main](https://codecov.io/gh/dubzzz/fast-check/commit/95c7f156e889cb808bfe8ee9575f5f2e69424259?el=desc) (95c7f15) will **increase** coverage by `0.12%`.
> The diff coverage is `94.00%`.

[![Impacted file tree graph](https://codecov.io/gh/dubzzz/fast-check/pull/1715/graphs/tree.svg?width=650&height=150&src=pr&token=fRi2fJN730)](https://codecov.io/gh/dubzzz/fast-check/pull/1715?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##             main    #1715      +/-   ##
==========================================
+ Coverage   96.38%   96.50%   +0.12%     
==========================================
  Files         102      106       +4     
  Lines        3567     3580      +13     
  Branches      710      710              
==========================================
+ Hits         3438     3455      +17     
+ Misses        125      121       -4     
  Partials        4        4              
```

| Flag | Coverage Δ | |
|---|---|---|
| unit-tests | `96.50% <94.00%> (+0.12%)` | :arrow_up: |
| unit-tests-10.x-Linux | `96.50% <94.00%> (+0.12%)` | :arrow_up: |
| unit-tests-12.x-Linux | `?` | |
| unit-tests-14.x-Linux | `?` | |

Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags#carryforward-flags-in-the-pull-request-comment) to find out more.

| [Impacted Files](https://codecov.io/gh/dubzzz/fast-check/pull/1715?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [src/arbitrary/\_internals/BigIntArbitrary.ts](https://codecov.io/gh/dubzzz/fast-check/pull/1715/diff?src=pr&el=tree#diff-c3JjL2FyYml0cmFyeS9faW50ZXJuYWxzL0JpZ0ludEFyYml0cmFyeS50cw==) | `87.23% <87.23%> (ø)` | |
| [src/arbitrary/\_internals/helpers/ShrinkBigInt.ts](https://codecov.io/gh/dubzzz/fast-check/pull/1715/diff?src=pr&el=tree#diff-c3JjL2FyYml0cmFyeS9faW50ZXJuYWxzL2hlbHBlcnMvU2hyaW5rQmlnSW50LnRz) | `100.00% <100.00%> (ø)` | |
| [src/arbitrary/bigInt.ts](https://codecov.io/gh/dubzzz/fast-check/pull/1715/diff?src=pr&el=tree#diff-c3JjL2FyYml0cmFyeS9iaWdJbnQudHM=) | `100.00% <100.00%> (ø)` | |
| [src/arbitrary/bigIntN.ts](https://codecov.io/gh/dubzzz/fast-check/pull/1715/diff?src=pr&el=tree#diff-c3JjL2FyYml0cmFyeS9iaWdJbnROLnRz) | `100.00% <100.00%> (ø)` | |
| [src/arbitrary/bigUint.ts](https://codecov.io/gh/dubzzz/fast-check/pull/1715/diff?src=pr&el=tree#diff-c3JjL2FyYml0cmFyeS9iaWdVaW50LnRz) | `100.00% <100.00%> (ø)` | |
| [src/arbitrary/bigUintN.ts](https://codecov.io/gh/dubzzz/fast-check/pull/1715/diff?src=pr&el=tree#diff-c3JjL2FyYml0cmFyeS9iaWdVaW50Ti50cw==) | `100.00% <100.00%> (ø)` | |
| [src/check/arbitrary/MixedCaseArbitrary.ts](https://codecov.io/gh/dubzzz/fast-check/pull/1715/diff?src=pr&el=tree#diff-c3JjL2NoZWNrL2FyYml0cmFyeS9NaXhlZENhc2VBcmJpdHJhcnkudHM=) | `98.24% <100.00%> (ø)` | |
| [src/check/arbitrary/ObjectArbitrary.ts](https://codecov.io/gh/dubzzz/fast-check/pull/1715/diff?src=pr&el=tree#diff-c3JjL2NoZWNrL2FyYml0cmFyeS9PYmplY3RBcmJpdHJhcnkudHM=) | `97.34% <100.00%> (ø)` | |
| [src/fast-check-default.ts](https://codecov.io/gh/dubzzz/fast-check/pull/1715/diff?src=pr&el=tree#diff-c3JjL2Zhc3QtY2hlY2stZGVmYXVsdC50cw==) | `100.00% <100.00%> (ø)` | |
| [...rc/check/arbitrary/definition/ConverterFromNext.ts](https://codecov.io/gh/dubzzz/fast-check/pull/1715/diff?src=pr&el=tree#diff-c3JjL2NoZWNrL2FyYml0cmFyeS9kZWZpbml0aW9uL0NvbnZlcnRlckZyb21OZXh0LnRz) | `92.85% <0.00%> (-4.77%)` | :arrow_down: |
| ... and [6 more](https://codecov.io/gh/dubzzz/fast-check/pull/1715/diff?src=pr&el=tree-more) | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/dubzzz/fast-check/pull/1715?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/dubzzz/fast-check/pull/1715?src=pr&el=footer). Last update [95c7f15...a605edb](https://codecov.io/gh/dubzzz/fast-check/pull/1715?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/src/arbitrary/_internals/BigIntArbitrary.ts b/src/arbitrary/_internals/BigIntArbitrary.ts
new file mode 100644
index 00000000..21fc9775
--- /dev/null
+++ b/src/arbitrary/_internals/BigIntArbitrary.ts
@@ -0,0 +1,89 @@
+import { Random } from '../../random/generator/Random';
+import { Stream } from '../../stream/Stream';
+import { NextArbitrary } from '../../check/arbitrary/definition/NextArbitrary';
+import { NextValue } from '../../check/arbitrary/definition/NextValue';
+import { biasNumericRange, bigIntLogLike } from './helpers/BiasNumericRange';
+import { shrinkBigInt } from './helpers/ShrinkBigInt';
+
+/** @internal */
+export class BigIntArbitrary extends NextArbitrary<bigint> {
+  constructor(readonly min: bigint, readonly max: bigint) {
+    super();
+  }
+
+  generate(mrng: Random, biasFactor: number | undefined): NextValue<bigint> {
+    const range = this.computeGenerateRange(mrng, biasFactor);
+    return new NextValue(mrng.nextBigInt(range.min, range.max), undefined);
+  }
+  private computeGenerateRange(mrng: Random, biasFactor: number | undefined): { min: bigint; max: bigint } {
+    if (biasFactor === undefined || mrng.nextInt(1, biasFactor) !== 1) {
+      return { min: this.min, max: this.max };
+    }
+    const ranges = biasNumericRange(this.min, this.max, bigIntLogLike);
+    if (ranges.length === 1) {
+      return ranges[0];
+    }
+    const id = mrng.nextInt(-2 * (ranges.length - 1), ranges.length - 2); // 1st range has the highest priority
+    return id < 0 ? ranges[0] : ranges[id + 1];
+  }
+
+  canGenerate(value: unknown): value is bigint {
+    return typeof value === 'bigint' && this.min <= value && value <= this.max;
+  }
+
+  shrink(current: bigint, context?: unknown): Stream<NextValue<bigint>> {
+    if (current === BigInt(0)) {
+      return Stream.nil();
+    }
+    if (!BigIntArbitrary.isValidContext(current, context)) {
+      // No context:
+      //   Take default target and shrink towards it
+      //   Try the target on first try
+      const target = this.defaultTarget();
+      return shrinkBigInt(current, target, true);
+    }
+    if (this.isLastChanceTry(current, context)) {
+      // Last chance try...
+      // context is set to undefined, so that shrink will restart
+      // without any assumptions in case our try find yet another bug
+      return Stream.of(new NextValue(context, undefined));
+    }
+    // Normal shrink process
+    return shrinkBigInt(current, context, false);
+  }
+
+  defaultTarget(): bigint {
+    // min <= 0 && max >= 0   => shrink towards zero
+    if (this.min <= 0 && this.max >= 0) {
+      return BigInt(0);
+    }
+    // min < 0                => shrink towards max (closer to zero)
+    // otherwise              => shrink towards min (closer to zero)
+    return this.min < 0 ? this.max : this.min;
+  }
+
+  private isLastChanceTry(current: bigint, context: bigint): boolean {
+    // Last chance corresponds to scenario where shrink should be empty
+    // But we try a last thing just in case it can work
+    if (current > 0) return current === context + BigInt(1) && current > this.min;
+    if (current < 0) return current === context - BigInt(1) && current < this.max;
+    return false;
+  }
+
+  private static isValidContext(current: bigint, context?: unknown): context is bigint {
+    // Context contains a value between zero and current that is known to be
+    // the closer to zero passing value*.
+    // *More precisely: our shrinker will not try something closer to zero
+    if (context === undefined) {
+      return false;
+    }
+    if (typeof context !== 'bigint') {
+      throw new Error(`Invalid context type passed to BigIntArbitrary (#1)`);
+    }
+    const differentSigns = (current > 0 && context < 0) || (current < 0 && context > 0);
+    if (context !== BigInt(0) && differentSigns) {
+      throw new Error(`Invalid context value passed to BigIntArbitrary (#2)`);
+    }
+    return true;
+  }
+}
diff --git a/src/check/arbitrary/helpers/ShrinkBigInt.ts b/src/arbitrary/_internals/helpers/ShrinkBigInt.ts
similarity index 94%
rename from src/check/arbitrary/helpers/ShrinkBigInt.ts
rename to src/arbitrary/_internals/helpers/ShrinkBigInt.ts
index 9302f742..bf6d678f 100644
--- a/src/check/arbitrary/helpers/ShrinkBigInt.ts
+++ b/src/arbitrary/_internals/helpers/ShrinkBigInt.ts
@@ -1,5 +1,5 @@
 import { Stream, stream } from '../../../stream/Stream';
-import { NextValue } from '../definition/NextValue';
+import { NextValue } from '../../../check/arbitrary/definition/NextValue';
 
 /**
  * Halve towards zero
diff --git a/src/arbitrary/bigInt.ts b/src/arbitrary/bigInt.ts
new file mode 100644
index 00000000..01c96eda
--- /dev/null
+++ b/src/arbitrary/bigInt.ts
@@ -0,0 +1,89 @@
+import { ArbitraryWithContextualShrink } from '../check/arbitrary/definition/ArbitraryWithContextualShrink';
+import { convertFromNextWithShrunkOnce } from '../check/arbitrary/definition/Converters';
+import { BigIntArbitrary } from './_internals/BigIntArbitrary';
+
+/**
+ * Constraints to be applied on {@link bigInt}
+ * @remarks Since 2.6.0
+ * @public
+ */
+export interface BigIntConstraints {
+  /**
+   * Lower bound for the generated bigints (eg.: -5n, 0n, BigInt(Number.MIN_SAFE_INTEGER))
+   * @remarks Since 2.6.0
+   */
+  min?: bigint;
+  /**
+   * Upper bound for the generated bigints (eg.: -2n, 2147483647n, BigInt(Number.MAX_SAFE_INTEGER))
+   * @remarks Since 2.6.0
+   */
+  max?: bigint;
+}
+
+/**
+ * Build fully set BigIntConstraints from a partial data
+ * @internal
+ */
+function buildCompleteBigIntConstraints(constraints: BigIntConstraints): Required<BigIntConstraints> {
+  const DefaultPow = 256;
+  const DefaultMin = BigInt(-1) << BigInt(DefaultPow - 1);
+  const DefaultMax = (BigInt(1) << BigInt(DefaultPow - 1)) - BigInt(1);
+
+  const min = constraints.min;
+  const max = constraints.max;
+  return {
+    min: min !== undefined ? min : DefaultMin - (max !== undefined && max < BigInt(0) ? max * max : BigInt(0)),
+    max: max !== undefined ? max : DefaultMax + (min !== undefined && min > BigInt(0) ? min * min : BigInt(0)),
+  };
+}
+
+/**
+ * Extract constraints from args received by bigint
+ * @internal
+ */
+function extractBigIntConstraints(args: [] | [bigint, bigint] | [BigIntConstraints]): BigIntConstraints {
+  if (args[0] === undefined) {
+    // bigInt()
+    return {};
+  } // args.length > 0
+
+  if (args[1] === undefined) {
+    // bigInt(constraints)
+    const constraints = args[0] as BigIntConstraints;
+    return constraints;
+  } // args.length > 1
+
+  return { min: args[0] as bigint, max: args[1] as bigint }; // bigInt(min, max)
+}
+
+/**
+ * For bigint
+ * @remarks Since 1.9.0
+ * @public
+ */
+function bigInt(): ArbitraryWithContextualShrink<bigint>;
+/**
+ * For bigint between min (included) and max (included)
+ *
+ * @param min - Lower bound for the generated bigints (eg.: -5n, 0n, BigInt(Number.MIN_SAFE_INTEGER))
+ * @param max - Upper bound for the generated bigints (eg.: -2n, 2147483647n, BigInt(Number.MAX_SAFE_INTEGER))
+ *
+ * @remarks Since 1.9.0
+ * @public
+ */
+function bigInt(min: bigint, max: bigint): ArbitraryWithContextualShrink<bigint>;
+/**
+ * For bigint between min (included) and max (included)
+ *
+ * @param constraints - Constraints to apply when building instances
+ *
+ * @remarks Since 2.6.0
+ * @public
+ */
+function bigInt(constraints: BigIntConstraints): ArbitraryWithContextualShrink<bigint>;
+function bigInt(...args: [] | [bigint, bigint] | [BigIntConstraints]): ArbitraryWithContextualShrink<bigint> {
+  const constraints = buildCompleteBigIntConstraints(extractBigIntConstraints(args));
+  const arb = new BigIntArbitrary(constraints.min, constraints.max);
+  return convertFromNextWithShrunkOnce(arb, arb.defaultTarget());
+}
+export { bigInt };
diff --git a/src/arbitrary/bigIntN.ts b/src/arbitrary/bigIntN.ts
new file mode 100644
index 00000000..053a7d29
--- /dev/null
+++ b/src/arbitrary/bigIntN.ts
@@ -0,0 +1,20 @@
+import { ArbitraryWithContextualShrink } from '../check/arbitrary/definition/ArbitraryWithContextualShrink';
+import { convertFromNextWithShrunkOnce } from '../check/arbitrary/definition/Converters';
+import { BigIntArbitrary } from './_internals/BigIntArbitrary';
+
+/**
+ * For signed bigint of n bits
+ *
+ * Generated values will be between -2^(n-1) (included) and 2^(n-1) (excluded)
+ *
+ * @param n - Maximal number of bits of the generated bigint
+ *
+ * @remarks Since 1.9.0
+ * @public
+ */
+export function bigIntN(n: number): ArbitraryWithContextualShrink<bigint> {
+  const min = BigInt(-1) << BigInt(n - 1);
+  const max = (BigInt(1) << BigInt(n - 1)) - BigInt(1);
+  const arb = new BigIntArbitrary(min, max);
+  return convertFromNextWithShrunkOnce(arb, arb.defaultTarget());
+}
diff --git a/src/arbitrary/bigUint.ts b/src/arbitrary/bigUint.ts
new file mode 100644
index 00000000..73900c62
--- /dev/null
+++ b/src/arbitrary/bigUint.ts
@@ -0,0 +1,52 @@
+import { ArbitraryWithContextualShrink } from '../check/arbitrary/definition/ArbitraryWithContextualShrink';
+import { convertFromNextWithShrunkOnce } from '../check/arbitrary/definition/Converters';
+import { BigIntArbitrary } from './_internals/BigIntArbitrary';
+
+/**
+ * Constraints to be applied on {@link bigUint}
+ * @remarks Since 2.6.0
+ * @public
+ */
+export interface BigUintConstraints {
+  /**
+   * Upper bound for the generated bigints (eg.: 2147483647n, BigInt(Number.MAX_SAFE_INTEGER))
+   * @remarks Since 2.6.0
+   */
+  max?: bigint;
+}
+
+/** @internal */
+function computeDefaultMax(): bigint {
+  return (BigInt(1) << BigInt(256)) - BigInt(1);
+}
+
+/**
+ * For positive bigint
+ * @remarks Since 1.9.0
+ * @public
+ */
+function bigUint(): ArbitraryWithContextualShrink<bigint>;
+/**
+ * For positive bigint between 0 (included) and max (included)
+ *
+ * @param max - Upper bound for the generated bigint
+ *
+ * @remarks Since 1.9.0
+ * @public
+ */
+function bigUint(max: bigint): ArbitraryWithContextualShrink<bigint>;
+/**
+ * For positive bigint between 0 (included) and max (included)
+ *
+ * @param constraints - Constraints to apply when building instances
+ *
+ * @remarks Since 2.6.0
+ * @public
+ */
+function bigUint(constraints: BigUintConstraints): ArbitraryWithContextualShrink<bigint>;
+function bigUint(constraints?: bigint | BigUintConstraints): ArbitraryWithContextualShrink<bigint> {
+  const max = constraints === undefined ? undefined : typeof constraints === 'object' ? constraints.max : constraints;
+  const arb = new BigIntArbitrary(BigInt(0), max !== undefined ? max : computeDefaultMax());
+  return convertFromNextWithShrunkOnce(arb, arb.defaultTarget());
+}
+export { bigUint };
diff --git a/src/arbitrary/bigUintN.ts b/src/arbitrary/bigUintN.ts
new file mode 100644
index 00000000..202408eb
--- /dev/null
+++ b/src/arbitrary/bigUintN.ts
@@ -0,0 +1,20 @@
+import { ArbitraryWithContextualShrink } from '../check/arbitrary/definition/ArbitraryWithContextualShrink';
+import { convertFromNextWithShrunkOnce } from '../check/arbitrary/definition/Converters';
+import { BigIntArbitrary } from './_internals/BigIntArbitrary';
+
+/**
+ * For unsigned bigint of n bits
+ *
+ * Generated values will be between 0 (included) and 2^n (excluded)
+ *
+ * @param n - Maximal number of bits of the generated bigint
+ *
+ * @remarks Since 1.9.0
+ * @public
+ */
+export function bigUintN(n: number): ArbitraryWithContextualShrink<bigint> {
+  const min = BigInt(0);
+  const max = (BigInt(1) << BigInt(n)) - BigInt(1);
+  const arb = new BigIntArbitrary(min, max);
+  return convertFromNextWithShrunkOnce(arb, arb.defaultTarget());
+}
diff --git a/src/check/arbitrary/BigIntArbitrary.ts b/src/check/arbitrary/BigIntArbitrary.ts
deleted file mode 100644
index 9e552116..00000000
--- a/src/check/arbitrary/BigIntArbitrary.ts
+++ /dev/null
@@ -1,257 +0,0 @@
-import { Random } from '../../random/generator/Random';
-import { Stream } from '../../stream/Stream';
-import { ArbitraryWithContextualShrink } from './definition/ArbitraryWithContextualShrink';
-import { convertFromNextWithShrunkOnce } from './definition/Converters';
-import { NextArbitrary } from './definition/NextArbitrary';
-import { NextValue } from './definition/NextValue';
-import { biasNumericRange, bigIntLogLike } from '../../arbitrary/_internals/helpers/BiasNumericRange';
-import { shrinkBigInt } from './helpers/ShrinkBigInt';
-
-/** @internal */
-class BigIntArbitrary extends NextArbitrary<bigint> {
-  constructor(readonly min: bigint, readonly max: bigint) {
-    super();
-  }
-
-  generate(mrng: Random, biasFactor: number | undefined): NextValue<bigint> {
-    const range = this.computeGenerateRange(mrng, biasFactor);
-    return new NextValue(mrng.nextBigInt(range.min, range.max), undefined);
-  }
-  private computeGenerateRange(mrng: Random, biasFactor: number | undefined): { min: bigint; max: bigint } {
-    if (biasFactor === undefined || mrng.nextInt(1, biasFactor) !== 1) {
-      return { min: this.min, max: this.max };
-    }
-    const ranges = biasNumericRange(this.min, this.max, bigIntLogLike);
-    if (ranges.length === 1) {
-      return ranges[0];
-    }
-    const id = mrng.nextInt(-2 * (ranges.length - 1), ranges.length - 2); // 1st range has the highest priority
-    return id < 0 ? ranges[0] : ranges[id + 1];
-  }
-
-  canGenerate(value: unknown): value is bigint {
-    return typeof value === 'bigint' && this.min <= value && value <= this.max;
-  }
-
-  shrink(current: bigint, context?: unknown): Stream<NextValue<bigint>> {
-    if (current === BigInt(0)) {
-      return Stream.nil();
-    }
-    if (!BigIntArbitrary.isValidContext(current, context)) {
-      // No context:
-      //   Take default target and shrink towards it
-      //   Try the target on first try
-      const target = this.defaultTarget();
-      return shrinkBigInt(current, target, true);
-    }
-    if (this.isLastChanceTry(current, context)) {
-      // Last chance try...
-      // context is set to undefined, so that shrink will restart
-      // without any assumptions in case our try find yet another bug
-      return Stream.of(new NextValue(context, undefined));
-    }
-    // Normal shrink process
-    return shrinkBigInt(current, context, false);
-  }
-
-  defaultTarget(): bigint {
-    // min <= 0 && max >= 0   => shrink towards zero
-    if (this.min <= 0 && this.max >= 0) {
-      return BigInt(0);
-    }
-    // min < 0                => shrink towards max (closer to zero)
-    // otherwise              => shrink towards min (closer to zero)
-    return this.min < 0 ? this.max : this.min;
-  }
-
-  private isLastChanceTry(current: bigint, context: bigint): boolean {
-    // Last chance corresponds to scenario where shrink should be empty
-    // But we try a last thing just in case it can work
-    if (current > 0) return current === context + BigInt(1) && current > this.min;
-    if (current < 0) return current === context - BigInt(1) && current < this.max;
-    return false;
-  }
-
-  private static isValidContext(current: bigint, context?: unknown): context is bigint {
-    // Context contains a value between zero and current that is known to be
-    // the closer to zero passing value*.
-    // *More precisely: our shrinker will not try something closer to zero
-    if (context === undefined) {
-      return false;
-    }
-    if (typeof context !== 'bigint') {
-      throw new Error(`Invalid context type passed to BigIntArbitrary (#1)`);
-    }
-    const differentSigns = (current > 0 && context < 0) || (current < 0 && context > 0);
-    if (context !== BigInt(0) && differentSigns) {
-      throw new Error(`Invalid context value passed to BigIntArbitrary (#2)`);
-    }
-    return true;
-  }
-}
-
-/** @internal */
-function buildBigIntArbitrary(min: bigint, max: bigint): ArbitraryWithContextualShrink<bigint> {
-  const arb = new BigIntArbitrary(min, max);
-  return convertFromNextWithShrunkOnce(arb, arb.defaultTarget());
-}
-
-/**
- * For signed bigint of n bits
- *
- * Generated values will be between -2^(n-1) (included) and 2^(n-1) (excluded)
- *
- * @param n - Maximal number of bits of the generated bigint
- *
- * @remarks Since 1.9.0
- * @public
- */
-function bigIntN(n: number): ArbitraryWithContextualShrink<bigint> {
-  const min = BigInt(-1) << BigInt(n - 1);
-  const max = (BigInt(1) << BigInt(n - 1)) - BigInt(1);
-  return buildBigIntArbitrary(min, max);
-}
-
-/**
- * For unsigned bigint of n bits
- *
- * Generated values will be between 0 (included) and 2^n (excluded)
- *
- * @param n - Maximal number of bits of the generated bigint
- *
- * @remarks Since 1.9.0
- * @public
- */
-function bigUintN(n: number): ArbitraryWithContextualShrink<bigint> {
-  const min = BigInt(0);
-  const max = (BigInt(1) << BigInt(n)) - BigInt(1);
-  return buildBigIntArbitrary(min, max);
-}
-
-/**
- * Constraints to be applied on {@link bigInt}
- * @remarks Since 2.6.0
- * @public
- */
-export interface BigIntConstraints {
-  /**
-   * Lower bound for the generated bigints (eg.: -5n, 0n, BigInt(Number.MIN_SAFE_INTEGER))
-   * @remarks Since 2.6.0
-   */
-  min?: bigint;
-  /**
-   * Upper bound for the generated bigints (eg.: -2n, 2147483647n, BigInt(Number.MAX_SAFE_INTEGER))
-   * @remarks Since 2.6.0
-   */
-  max?: bigint;
-}
-
-/**
- * Build fully set BigIntConstraints from a partial data
- * @internal
- */
-function buildCompleteBigIntConstraints(constraints: BigIntConstraints): Required<BigIntConstraints> {
-  const DefaultPow = 256;
-  const DefaultMin = BigInt(-1) << BigInt(DefaultPow - 1);
-  const DefaultMax = (BigInt(1) << BigInt(DefaultPow - 1)) - BigInt(1);
-
-  const min = constraints.min;
-  const max = constraints.max;
-  return {
-    min: min !== undefined ? min : DefaultMin - (max !== undefined && max < BigInt(0) ? max * max : BigInt(0)),
-    max: max !== undefined ? max : DefaultMax + (min !== undefined && min > BigInt(0) ? min * min : BigInt(0)),
-  };
-}
-
-/**
- * Extract constraints from args received by bigint
- * @internal
- */
-function extractBigIntConstraints(args: [] | [bigint, bigint] | [BigIntConstraints]): BigIntConstraints {
-  if (args[0] === undefined) {
-    // bigInt()
-    return {};
-  } // args.length > 0
-
-  if (args[1] === undefined) {
-    // bigInt(constraints)
-    const constraints = args[0] as BigIntConstraints;
-    return constraints;
-  } // args.length > 1
-
-  return { min: args[0] as bigint, max: args[1] as bigint }; // bigInt(min, max)
-}
-
-/**
- * For bigint
- * @remarks Since 1.9.0
- * @public
- */
-function bigInt(): ArbitraryWithContextualShrink<bigint>;
-/**
- * For bigint between min (included) and max (included)
- *
- * @param min - Lower bound for the generated bigints (eg.: -5n, 0n, BigInt(Number.MIN_SAFE_INTEGER))
- * @param max - Upper bound for the generated bigints (eg.: -2n, 2147483647n, BigInt(Number.MAX_SAFE_INTEGER))
- *
- * @remarks Since 1.9.0
- * @public
- */
-function bigInt(min: bigint, max: bigint): ArbitraryWithContextualShrink<bigint>;
-/**
- * For bigint between min (included) and max (included)
- *
- * @param constraints - Constraints to apply when building instances
- *
- * @remarks Since 2.6.0
- * @public
- */
-function bigInt(constraints: BigIntConstraints): ArbitraryWithContextualShrink<bigint>;
-function bigInt(...args: [] | [bigint, bigint] | [BigIntConstraints]): ArbitraryWithContextualShrink<bigint> {
-  const constraints = buildCompleteBigIntConstraints(extractBigIntConstraints(args));
-  return buildBigIntArbitrary(constraints.min, constraints.max);
-}
-
-/**
- * Constraints to be applied on {@link bigUint}
- * @remarks Since 2.6.0
- * @public
- */
-export interface BigUintConstraints {
-  /**
-   * Upper bound for the generated bigints (eg.: 2147483647n, BigInt(Number.MAX_SAFE_INTEGER))
-   * @remarks Since 2.6.0
-   */
-  max?: bigint;
-}
-
-/**
- * For positive bigint
- * @remarks Since 1.9.0
- * @public
- */
-function bigUint(): ArbitraryWithContextualShrink<bigint>;
-/**
- * For positive bigint between 0 (included) and max (included)
- *
- * @param max - Upper bound for the generated bigint
- *
- * @remarks Since 1.9.0
- * @public
- */
-function bigUint(max: bigint): ArbitraryWithContextualShrink<bigint>;
-/**
- * For positive bigint between 0 (included) and max (included)
- *
- * @param constraints - Constraints to apply when building instances
- *
- * @remarks Since 2.6.0
- * @public
- */
-function bigUint(constraints: BigUintConstraints): ArbitraryWithContextualShrink<bigint>;
-function bigUint(constraints?: bigint | BigUintConstraints): ArbitraryWithContextualShrink<bigint> {
-  const max = constraints === undefined ? undefined : typeof constraints === 'object' ? constraints.max : constraints;
-  return max === undefined ? bigUintN(256) : buildBigIntArbitrary(BigInt(0), max);
-}
-
-export { bigIntN, bigUintN, bigInt, bigUint };
diff --git a/src/check/arbitrary/MixedCaseArbitrary.ts b/src/check/arbitrary/MixedCaseArbitrary.ts
index 83cee09a..e6688baa 100644
--- a/src/check/arbitrary/MixedCaseArbitrary.ts
+++ b/src/check/arbitrary/MixedCaseArbitrary.ts
@@ -1,6 +1,6 @@
 import { Random } from '../../random/generator/Random';
 import { Stream } from '../../stream/Stream';
-import { bigUintN } from './BigIntArbitrary';
+import { bigUintN } from '../../arbitrary/bigUintN';
 import { Arbitrary } from './definition/Arbitrary';
 import { Shrinkable } from './definition/Shrinkable';
 
diff --git a/src/check/arbitrary/ObjectArbitrary.ts b/src/check/arbitrary/ObjectArbitrary.ts
index 4c6aeb25..2a0ac5e7 100644
--- a/src/check/arbitrary/ObjectArbitrary.ts
+++ b/src/check/arbitrary/ObjectArbitrary.ts
@@ -13,7 +13,7 @@ import { oneof } from './OneOfArbitrary';
 import { set } from './SetArbitrary';
 import { string, unicodeString } from './StringArbitrary';
 import { tuple } from './TupleArbitrary';
-import { bigInt } from './BigIntArbitrary';
+import { bigInt } from '../../arbitrary/bigInt';
 import { date } from './DateArbitrary';
 import {
   float32Array,
diff --git a/src/fast-check-default.ts b/src/fast-check-default.ts
index 8a707a2a..2161ed77 100644
--- a/src/fast-check-default.ts
+++ b/src/fast-check-default.ts
@@ -20,14 +20,10 @@ import { assert, check } from './check/runner/Runner';
 import { sample, statistics } from './check/runner/Sampler';
 
 import { array, ArrayConstraints } from './check/arbitrary/ArrayArbitrary';
-import {
-  bigInt,
-  bigIntN,
-  bigUint,
-  bigUintN,
-  BigIntConstraints,
-  BigUintConstraints,
-} from './check/arbitrary/BigIntArbitrary';
+import { bigInt, BigIntConstraints } from './arbitrary/bigInt';
+import { bigIntN } from './arbitrary/bigIntN';
+import { bigUint, BigUintConstraints } from './arbitrary/bigUint';
+import { bigUintN } from './arbitrary/bigUintN';
 import { boolean } from './check/arbitrary/BooleanArbitrary';
 import { falsy, FalsyContraints, FalsyValue } from './check/arbitrary/FalsyArbitrary';
 import { ascii, base64, char, char16bits, fullUnicode, hexa, unicode } from './check/arbitrary/CharacterArbitrary';


Test patch:
diff --git a/test/unit/check/arbitrary/BigIntArbitrary.spec.ts b/test/unit/arbitrary/BigIntArbitrary.spec.ts
similarity index 94%
rename from test/unit/check/arbitrary/BigIntArbitrary.spec.ts
rename to test/unit/arbitrary/BigIntArbitrary.spec.ts
index 7f652aa5..6b6c241b 100644
--- a/test/unit/check/arbitrary/BigIntArbitrary.spec.ts
+++ b/test/unit/arbitrary/BigIntArbitrary.spec.ts
@@ -1,10 +1,13 @@
-import * as fc from '../../../../lib/fast-check';
+import * as fc from '../../../lib/fast-check';
 
-import { bigIntN, bigUintN, bigInt, bigUint } from '../../../../src/check/arbitrary/BigIntArbitrary';
-import { generateOneValue } from './generic/GenerateOneValue';
+import { bigInt } from '../../../src/arbitrary/bigInt';
+import { bigIntN } from '../../../src/arbitrary/bigIntN';
+import { bigUint } from '../../../src/arbitrary/bigUint';
+import { bigUintN } from '../../../src/arbitrary/bigUintN';
+import { generateOneValue } from '../check/arbitrary/generic/GenerateOneValue';
 
-import * as genericHelper from './generic/GenericArbitraryHelper';
-import { buildShrinkTree, renderTree } from './generic/ShrinkTree';
+import * as genericHelper from '../check/arbitrary/generic/GenericArbitraryHelper';
+import { buildShrinkTree, renderTree } from '../check/arbitrary/generic/ShrinkTree';
 
 declare function BigInt(n: number | bigint | string): bigint;
 
diff --git a/test/unit/check/arbitrary/MixedCaseArbitrary.utest.spec.ts b/test/unit/check/arbitrary/MixedCaseArbitrary.utest.spec.ts
index 77a7b33c..80ff126e 100644
--- a/test/unit/check/arbitrary/MixedCaseArbitrary.utest.spec.ts
+++ b/test/unit/check/arbitrary/MixedCaseArbitrary.utest.spec.ts
@@ -2,8 +2,8 @@ import * as fc from '../../../../lib/fast-check';
 
 import { mixedCase, countToggledBits, computeNextFlags } from '../../../../src/check/arbitrary/MixedCaseArbitrary';
 
-jest.mock('../../../../src/check/arbitrary/BigIntArbitrary');
-import * as BigIntArbitraryMock from '../../../../src/check/arbitrary/BigIntArbitrary';
+jest.mock('../../../../src/arbitrary/bigUintN');
+import * as BigUintNMock from '../../../../src/arbitrary/bigUintN';
 import * as stubRng from '../../stubs/generators';
 import { mocked } from 'ts-jest/utils';
 import { arbitraryFor } from './generic/ArbitraryBuilder';
@@ -25,7 +25,7 @@ describe('MixedCaseArbitrary', () => {
     });
     it('should not toggle any character if flags are null', () => {
       // Arrange
-      const { bigUintN } = mocked(BigIntArbitraryMock);
+      const { bigUintN } = mocked(BigUintNMock);
       bigUintN.mockImplementationOnce((_n) => arbitraryFor([{ value: BigInt(0) }]));
       const stringArb = arbitraryFor([{ value: 'azerty' }]);
 
@@ -39,7 +39,7 @@ describe('MixedCaseArbitrary', () => {
     });
     it('should toggle characters according to flags', () => {
       // Arrange
-      const { bigUintN } = mocked(BigIntArbitraryMock);
+      const { bigUintN } = mocked(BigUintNMock);
       bigUintN.mockImplementationOnce((_n) => arbitraryFor([{ value: BigInt(9) /* 001001 */ }]));
       const stringArb = arbitraryFor([{ value: 'azerty' }]);
 
@@ -53,7 +53,7 @@ describe('MixedCaseArbitrary', () => {
     });
     it('should toggle both lower and upper characters', () => {
       // Arrange
-      const { bigUintN } = mocked(BigIntArbitraryMock);
+      const { bigUintN } = mocked(BigUintNMock);
       bigUintN.mockImplementationOnce((_n) => arbitraryFor([{ value: BigInt(9) /* 001001 */ }]));
       const stringArb = arbitraryFor([{ value: 'azERty' }]);
 
@@ -67,7 +67,7 @@ describe('MixedCaseArbitrary', () => {
     });
     it('should not try to toggle characters that do not have lower/upper versions', () => {
       // Arrange
-      const { bigUintN } = mocked(BigIntArbitraryMock);
+      const { bigUintN } = mocked(BigUintNMock);
       bigUintN.mockImplementationOnce((_n) => arbitraryFor([{ value: BigInt(0) }]));
       const stringArb = arbitraryFor([{ value: 'az01ty' }]); // 01 upper version is the same
 
@@ -81,7 +81,7 @@ describe('MixedCaseArbitrary', () => {
     });
     it('should shrink by merging string and flags shrinkers', () => {
       // Arrange
-      const { bigUintN } = mocked(BigIntArbitraryMock);
+      const { bigUintN } = mocked(BigUintNMock);
       bigUintN.mockImplementation((n) => {
         switch (n) {
           case 6: // azerty
@@ -148,7 +148,7 @@ describe('MixedCaseArbitrary', () => {
     });
     it('should use toggle function when provided to check what can be toggled or not', () => {
       // Arrange
-      const { bigUintN } = mocked(BigIntArbitraryMock);
+      const { bigUintN } = mocked(BigUintNMock);
       bigUintN.mockImplementationOnce((_n) => arbitraryFor([{ value: BigInt(63) /* 111111 */ }]));
       const stringArb = arbitraryFor([{ value: 'azerty' }]);
       const customToggle = jest.fn();