@ac-kit/test-util 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,65 @@
1
1
  # @ac-kit/test-util
2
2
 
3
+ ## 0.4.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 34e8cfa: `exactDot(a, b)` is a dot product rounded once from its exact value and
8
+ `exactDotSign(a, b)` the sign of that value, for any finite entries —
9
+ references computed in integers with no floating-point error-free
10
+ transformation, so a test never checks a kernel against the arithmetic it is
11
+ built on; `absoluteDot` is the scale such errors are measured against.
12
+ `defineOutFirstCase` and `expectAliasSafe` check functions that write their
13
+ result into a first `out` argument: with `out` as each input in turn, and as
14
+ every input at once, the result is the one a separate `out` gets, bit for bit,
15
+ and the function returns `out`. `samplerOf` replays fixed inputs. `vitest` is a
16
+ peer dependency, which the `expect…` assertions already needed.
17
+ - 34e8cfa: `@ac-kit/test-util/v8` exports `v8ElementsKind`, an array's V8 elements kind,
18
+ for tests run with `--allow-natives-syntax`; a proxy is `"other"` and a value
19
+ that is not an object throws a `TypeError`, where V8 itself would abort the
20
+ process.
21
+
22
+ ### Patch Changes
23
+
24
+ - 34e8cfa: An error message that quotes an argument of the wrong kind or value describes
25
+ it with `@ac-kit/core`'s `describeValue`, so building the message can no
26
+ longer throw on a symbol or run a hostile `toString`. The text changes: a
27
+ string is JSON-quoted (`got "sideways"`), `-0` keeps its sign, and an object is
28
+ named by its kind. Affected: `bitAddressFromBigInt`, `ipv4FromUint32`,
29
+ `toPortNumber`, `splitBitPrefixInto` and `printIpv6Address`' form, the HTTP
30
+ cookie jar's limits, the fetch, redirect and content-decoding limits and the
31
+ HTTP/1, HTTP/2 and HTTP/3 servers' response statuses, `OscPeer`'s
32
+ `maxPacketSize`, the QUIC `maxUdpPayloadSize`, `oshash`'s `size`,
33
+ `hammingDistancesInto`' query, the luma grid's `width` and `height`,
34
+ `phash`'s variant, `FakeWallClock`'s milliseconds, the piano partials, input-latency, chord-verifier and
35
+ tick-synthesis arguments of `@ac-kit/media-piano-audio`, and `@ac-kit/model-music`'s reference
36
+ pitch, tempo map and time signatures.
37
+ - Updated dependencies [34e8cfa]
38
+ - Updated dependencies [34e8cfa]
39
+ - Updated dependencies [34e8cfa]
40
+ - Updated dependencies [34e8cfa]
41
+ - Updated dependencies [34e8cfa]
42
+ - Updated dependencies [34e8cfa]
43
+ - Updated dependencies [34e8cfa]
44
+ - Updated dependencies [34e8cfa]
45
+ - Updated dependencies [34e8cfa]
46
+ - Updated dependencies [34e8cfa]
47
+ - Updated dependencies [34e8cfa]
48
+ - Updated dependencies [34e8cfa]
49
+ - Updated dependencies [34e8cfa]
50
+ - Updated dependencies [34e8cfa]
51
+ - Updated dependencies [34e8cfa]
52
+ - @ac-kit/core@0.12.0
53
+
54
+ ## 0.3.1
55
+
56
+ ### Patch Changes
57
+
58
+ - Updated dependencies [065cf8d]
59
+ - Updated dependencies [065cf8d]
60
+ - Updated dependencies [065cf8d]
61
+ - @ac-kit/core@0.11.0
62
+
3
63
  ## 0.3.0
4
64
 
5
65
  ### Minor Changes
package/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # @ac-kit/test-util
2
2
 
3
- Test-harness primitives with no dependency beyond `@ac-kit/core`.
3
+ Test-harness primitives with no dependency beyond `@ac-kit/core`. The
4
+ `expect…` assertions call Vitest's `expect`, so `vitest` is a peer dependency.
4
5
 
5
6
  Being dependency-free is the design constraint, not an accident: any package's
6
7
  test suite may need these, so pulling in a heavier dependency here would force
@@ -36,9 +37,123 @@ clock.set(1_000); // back in time
36
37
  now().epochMilliseconds; // 1000
37
38
  ```
38
39
 
39
- For helpers that drive and probe real external services (Docker containers,
40
- TCP/TLS endpoints), see `@ac-kit/integration-test-util` instead — that package
41
- is allowed heavier dependencies precisely because its own consumers are few.
40
+ For helpers that reach for the machine (Docker containers, TCP/TLS endpoints,
41
+ a temporary file tree, a loopback HTTP server), see
42
+ `@ac-kit/integration-test-util` instead — that package is Node only and allowed
43
+ heavier dependencies, precisely because its own consumers are few, while this
44
+ one stays portable.
45
+
46
+ ## Exact dot product
47
+
48
+ `exactDot(a, b)` is `Σ aᵢ·bᵢ` computed exactly in integers and rounded once to
49
+ the nearest binary64 (ties to even), `exactDotSign(a, b)` is the sign of that
50
+ exact value, and `absoluteDot(a, b)` is `Σ |aᵢ·bᵢ|` in plain arithmetic, the
51
+ scale an error bound is stated against. They are the references a dot product —
52
+ compensated, exactly signed, or the error of a product — is checked against,
53
+ for any finite entries: cancellation to nothing, subnormal results and ties,
54
+ overflow.
55
+
56
+ ```ts
57
+ import { absoluteDot, exactDot, exactDotSign } from "@ac-kit/test-util";
58
+
59
+ exactDot([1e17, 1, -1e17], [1, 1, 1]); // 1, where the plain sum is 0
60
+ exactDotSign([1e17, -1, -1e17], [1, 1, 1]); // -1
61
+ // The rounding error of a product, rounded once: a·b − product.
62
+ exactDot([a, product], [b, -1]);
63
+
64
+ // An error bound stated against the scale of the terms.
65
+ expect(Math.abs(result - exactDot(a, b))).toBeLessThanOrEqual(
66
+ 4 * Number.EPSILON * absoluteDot(a, b),
67
+ );
68
+ ```
69
+
70
+ An exact zero, or empty input, gives `+0`; a non-zero sum below half the
71
+ smallest subnormal gives a zero of its own sign; past `Number.MAX_VALUE` after
72
+ rounding, `±Infinity`. The functions throw a `RangeError` when the lengths
73
+ differ, and `exactDot` and `exactDotSign` when an entry is `NaN` or infinite: a
74
+ reference must not answer a mistake in the test with `NaN`. `absoluteDot` lets
75
+ non-finite values propagate, as the dot products it measures do.
76
+
77
+ They share no code with what they check. The decomposition is their own integer
78
+ code over `@ac-kit/core`'s `float64ToBits` and `bitsToFloat64`, which read and
79
+ write a bit pattern and compute nothing; nothing from `float64ToParts`,
80
+ `PreciseSum`, an error-free transformation or a `math-*` package is used, so a
81
+ defect in those cannot cancel against the same defect in the reference. They
82
+ allocate and cost O(n) `bigint` operations: a reference, not a kernel.
83
+
84
+ ## Alias safety
85
+
86
+ A function that writes its result into a first `out` argument must give the
87
+ same result whichever of its inputs `out` is, and when every input is `out` at
88
+ once. `defineOutFirstCase` describes such a function, `expectAliasSafe` runs it
89
+ with a fresh `out`, with `out` as each input in turn and as every input at
90
+ once, and fails unless each result matches the one a separate `out` gets, bit
91
+ for bit (`NaN` and `-0` count) and the function returns `out`.
92
+
93
+ ```ts
94
+ import {
95
+ defineOutFirstCase,
96
+ expectAliasSafe,
97
+ samplerOf,
98
+ } from "@ac-kit/test-util";
99
+
100
+ const vec2AddCase = defineOutFirstCase({
101
+ name: "vec2Add",
102
+ // A fresh `out` from the value's own creator, and the arguments after it.
103
+ create: () => vec2Create(),
104
+ aliasable: [0, 1], // the arguments `out` may be
105
+ makeArguments: (next) => [vec2Of(next(), next()), vec2Of(next(), next())],
106
+ call: (out, [a, b]) => vec2Add(out, a, b),
107
+ });
108
+
109
+ expectAliasSafe(vec2AddCase, samplerOf([1, 2, 3, 4]));
110
+ ```
111
+
112
+ A package keeps the table of its own functions — which take `out` first, and
113
+ which argument positions may be `out` — and loops `expectAliasSafe` over it.
114
+ `samplerOf(values)` replays fixed numbers on every pass; any
115
+ `() => () => number` (a seeded generator that restarts) serves as a
116
+ `NumberSampler`. A function that returns something other than `out` — a success
117
+ flag, nothing — is declared `returns: "value"`, and the check then requires
118
+ that value to be the same wherever `out` is. `case.run(placement, sampler)` and
119
+ `case.aliasable` serve other checks over the same table. The harness never
120
+ builds a value it passes to the function: `create` and `makeArguments` do, so a
121
+ branded value always comes from its own creator, and bulk kernels with a
122
+ `Float64Array` `out` work in place the same way.
123
+
124
+ ## `@ac-kit/test-util/v8`
125
+
126
+ `v8ElementsKind` reports the elements kind V8 holds for an array
127
+ (`"packed-smi"`, `"packed-double"`, `"holey-object"`, `"dictionary"`, …), to test
128
+ that a creator or a hot loop keeps a `number[]` on the compact kind its speed
129
+ depends on. It is behind a subpath because it belongs to one engine and needs a
130
+ runtime flag, `--allow-natives-syntax`; importing the subpath never throws, and
131
+ the call throws an `Error` naming the flag when V8 lacks it (or the engine is
132
+ not V8).
133
+
134
+ ```ts
135
+ import { v8ElementsKind } from "@ac-kit/test-util/v8";
136
+
137
+ v8ElementsKind([1.5, 2.5]); // "packed-double"
138
+ v8ElementsKind([1, 2]); // "packed-smi"
139
+ v8ElementsKind(new Array(3)); // "holey-smi"
140
+ ```
141
+
142
+ With Vitest, give the project forked workers with the flag, so that the arrays
143
+ a test provokes cannot reach another file's type feedback:
144
+
145
+ ```ts
146
+ // vitest.config.ts
147
+ import { defineProject } from "vitest/config";
148
+
149
+ export default defineProject({
150
+ test: {
151
+ pool: "forks",
152
+ isolate: true,
153
+ execArgv: ["--allow-natives-syntax"],
154
+ },
155
+ });
156
+ ```
42
157
 
43
158
  See the
44
159
  [generated API docs](https://anthochamp.pages.grenadine.io/node-essentials/api/test-util/)
@@ -0,0 +1,60 @@
1
+ /**
2
+ * `Σ aᵢ·bᵢ` computed exactly in integers and rounded once to the nearest
3
+ * binary64, ties to even: the reference a dot product, compensated or not, is
4
+ * checked against. An exact zero, or empty input, gives `+0`; a non-zero sum
5
+ * below half the smallest subnormal gives a zero of its own sign; a sum past
6
+ * `Number.MAX_VALUE` after rounding gives `±Infinity`.
7
+ *
8
+ * It shares no code with `@ac-kit/math-scalar`, `@ac-kit/core`'s `PreciseSum`
9
+ * or any error-free transformation, so a defect in those cannot cancel against
10
+ * the same defect here. The decomposition is its own integer code over core's
11
+ * bit-pattern conversions.
12
+ *
13
+ * Time complexity: O(n) `bigint` operations on integers of up to about 4,200
14
+ * bits, plus one rounding. It allocates: it is a reference, not a kernel.
15
+ *
16
+ * @example
17
+ * // 1e17 + 1 − 1e17: the plain sum loses the 1.
18
+ * exactDot([1e17, 1, -1e17], [1, 1, 1]); // 1
19
+ *
20
+ * @param a - Left factors.
21
+ * @param b - Right factors, paired by index.
22
+ * @returns The exact sum, rounded once.
23
+ * @throws {RangeError} When `a` and `b` differ in length, or an entry is `NaN`
24
+ * or infinite: a reference must not answer a test's mistake with `NaN`.
25
+ */
26
+ export declare function exactDot(a: ArrayLike<number>, b: ArrayLike<number>): number;
27
+ /**
28
+ * The sign of the exact `Σ aᵢ·bᵢ`: `-1`, `0` (only an exactly zero sum, which
29
+ * empty input is) or `1`. The reference `dotSign` is checked against, with the
30
+ * same independence as {@link exactDot}.
31
+ *
32
+ * Time complexity: O(n) `bigint` operations, as {@link exactDot}.
33
+ *
34
+ * @example
35
+ * exactDotSign([1e17, -1, -1e17], [1, 1, 1]); // -1
36
+ *
37
+ * @param a - Left factors.
38
+ * @param b - Right factors, paired by index.
39
+ * @returns The sign of the exact sum.
40
+ * @throws {RangeError} When `a` and `b` differ in length, or an entry is `NaN`
41
+ * or infinite.
42
+ */
43
+ export declare function exactDotSign(a: ArrayLike<number>, b: ArrayLike<number>): -1 | 0 | 1;
44
+ /**
45
+ * `Σ |aᵢ·bᵢ|` in plain arithmetic: the scale a dot product's error bound is
46
+ * stated against (`|computed − exact| ≤ k·ε·Σ|aᵢbᵢ|`). Non-finite entries
47
+ * propagate, as they do in the dot products it measures.
48
+ *
49
+ * Time complexity: O(n).
50
+ *
51
+ * @example
52
+ * absoluteDot([1, -2], [3, 4]); // 11
53
+ *
54
+ * @param a - Left factors.
55
+ * @param b - Right factors, paired by index.
56
+ * @returns The sum of the absolute products, rounded as it goes.
57
+ * @throws {RangeError} When `a` and `b` differ in length.
58
+ */
59
+ export declare function absoluteDot(a: ArrayLike<number>, b: ArrayLike<number>): number;
60
+ //# sourceMappingURL=exact-dot.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exact-dot.d.ts","sourceRoot":"","sources":["../src/exact-dot.ts"],"names":[],"mappings":"AA2FA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,SAAS,CAAC,MAAM,CAAC,GAAG,MAAM,CAoC3E;AA+BD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,YAAY,CAC3B,CAAC,EAAE,SAAS,CAAC,MAAM,CAAC,EACpB,CAAC,EAAE,SAAS,CAAC,MAAM,CAAC,GAClB,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAQZ;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,WAAW,CAC1B,CAAC,EAAE,SAAS,CAAC,MAAM,CAAC,EACpB,CAAC,EAAE,SAAS,CAAC,MAAM,CAAC,GAClB,MAAM,CAcR"}
@@ -0,0 +1,183 @@
1
+ import { bitsToFloat64, float64ToBits } from "@ac-kit/core";
2
+ /*
3
+ * Exact references for the dot product, computed in integers. A binary64 is
4
+ * `mantissa · 2^exponent`, so the product of two of them is an integer times a
5
+ * power of two, and any number of such products add exactly once they share the
6
+ * smallest exponent. The sum is rounded to binary64 once, at the end, in
7
+ * integer code.
8
+ *
9
+ * Independence is the point (CONVENTIONS §15): what these check is built on
10
+ * `twoSumError`, `twoProductError`, `PreciseSum` and `float64ToParts`, so they
11
+ * use none of them. The decomposition below duplicates core's on purpose, and
12
+ * the only core functions called are `float64ToBits` and `bitsToFloat64`,
13
+ * which read and write the IEEE 754 bit pattern and compute nothing. Never call
14
+ * `float64ToParts`, `partsToFloat64`, `scaleByPowerOfTwo`, `PreciseSum`,
15
+ * `sumPrecise` or anything from a `math-*` package here.
16
+ */
17
+ const FRACTION_BITS_ = 52n;
18
+ const FRACTION_MASK_ = (1n << FRACTION_BITS_) - 1n;
19
+ const HIDDEN_BIT_ = 1n << FRACTION_BITS_;
20
+ const SIGN_BIT_ = 1n << 63n;
21
+ /** The exponent of the unit in the last place of the smallest subnormal. */
22
+ const SUBNORMAL_EXPONENT_ = -1074;
23
+ /** The biased exponent field of the infinities and `NaN`. */
24
+ const SPECIAL_EXPONENT_ = 0x7ff;
25
+ /** A finite binary64 as `mantissa · 2^exponent`, with an integer mantissa. */
26
+ function decompose_(value, name) {
27
+ const bits = float64ToBits(value);
28
+ const biased = Number((bits >> FRACTION_BITS_) & 0x7ffn);
29
+ if (biased === SPECIAL_EXPONENT_) {
30
+ throw new RangeError(`${name} must be finite, got ${value}`);
31
+ }
32
+ const fraction = bits & FRACTION_MASK_;
33
+ const magnitude = biased === 0 ? fraction : fraction | HIDDEN_BIT_;
34
+ return {
35
+ mantissa: (bits & SIGN_BIT_) === 0n ? magnitude : -magnitude,
36
+ exponent: biased === 0 ? SUBNORMAL_EXPONENT_ : biased - 1075,
37
+ };
38
+ }
39
+ /** The exact sum `units · 2^exponent` of the products, of an integer `units`. */
40
+ function exactSum_(a, b, caller) {
41
+ if (a.length !== b.length) {
42
+ throw new RangeError(`${caller}: a and b must have the same length, got ${a.length} and ${b.length}`);
43
+ }
44
+ const terms = [];
45
+ for (let index = 0; index < a.length; index++) {
46
+ const left = decompose_(a[index], `${caller}: a[${index}]`);
47
+ const right = decompose_(b[index], `${caller}: b[${index}]`);
48
+ if (left.mantissa !== 0n && right.mantissa !== 0n) {
49
+ terms.push({
50
+ mantissa: left.mantissa * right.mantissa,
51
+ exponent: left.exponent + right.exponent,
52
+ });
53
+ }
54
+ }
55
+ let exponent = Number.POSITIVE_INFINITY;
56
+ for (const term of terms) {
57
+ exponent = Math.min(exponent, term.exponent);
58
+ }
59
+ let units = 0n;
60
+ for (const term of terms) {
61
+ units += term.mantissa << BigInt(term.exponent - exponent);
62
+ }
63
+ return { mantissa: units, exponent: terms.length === 0 ? 0 : exponent };
64
+ }
65
+ /**
66
+ * `Σ aᵢ·bᵢ` computed exactly in integers and rounded once to the nearest
67
+ * binary64, ties to even: the reference a dot product, compensated or not, is
68
+ * checked against. An exact zero, or empty input, gives `+0`; a non-zero sum
69
+ * below half the smallest subnormal gives a zero of its own sign; a sum past
70
+ * `Number.MAX_VALUE` after rounding gives `±Infinity`.
71
+ *
72
+ * It shares no code with `@ac-kit/math-scalar`, `@ac-kit/core`'s `PreciseSum`
73
+ * or any error-free transformation, so a defect in those cannot cancel against
74
+ * the same defect here. The decomposition is its own integer code over core's
75
+ * bit-pattern conversions.
76
+ *
77
+ * Time complexity: O(n) `bigint` operations on integers of up to about 4,200
78
+ * bits, plus one rounding. It allocates: it is a reference, not a kernel.
79
+ *
80
+ * @example
81
+ * // 1e17 + 1 − 1e17: the plain sum loses the 1.
82
+ * exactDot([1e17, 1, -1e17], [1, 1, 1]); // 1
83
+ *
84
+ * @param a - Left factors.
85
+ * @param b - Right factors, paired by index.
86
+ * @returns The exact sum, rounded once.
87
+ * @throws {RangeError} When `a` and `b` differ in length, or an entry is `NaN`
88
+ * or infinite: a reference must not answer a test's mistake with `NaN`.
89
+ */
90
+ export function exactDot(a, b) {
91
+ const { mantissa: units, exponent } = exactSum_(a, b, "exactDot");
92
+ if (units === 0n) {
93
+ return 0;
94
+ }
95
+ const isNegative = units < 0n;
96
+ const magnitude = isNegative ? -units : units;
97
+ // The unit of the last place of the result: 53 significant bits, but never
98
+ // finer than the smallest subnormal.
99
+ const bitLength = magnitude.toString(2).length;
100
+ const resultExponent = Math.max(bitLength - 53 + exponent, SUBNORMAL_EXPONENT_);
101
+ const dropped = resultExponent - exponent;
102
+ let kept;
103
+ if (dropped <= 0) {
104
+ kept = magnitude << BigInt(-dropped);
105
+ }
106
+ else {
107
+ const shift = BigInt(dropped);
108
+ kept = magnitude >> shift;
109
+ const remainder = magnitude - (kept << shift);
110
+ const half = 1n << (shift - 1n);
111
+ if (remainder > half || (remainder === half && (kept & 1n) === 1n)) {
112
+ kept += 1n;
113
+ }
114
+ }
115
+ return assemble_(isNegative, kept, resultExponent);
116
+ }
117
+ /** `kept · 2^exponent`, with `kept` at most `2⁵³`, as a binary64's bits. */
118
+ function assemble_(isNegative, kept, exponent) {
119
+ let significand = kept;
120
+ let unitExponent = exponent;
121
+ if (significand === HIDDEN_BIT_ << 1n) {
122
+ significand = HIDDEN_BIT_;
123
+ unitExponent += 1;
124
+ }
125
+ let bits = significand;
126
+ if (significand >= HIDDEN_BIT_) {
127
+ const biased = unitExponent + 1075;
128
+ if (biased >= SPECIAL_EXPONENT_) {
129
+ return isNegative ? Number.NEGATIVE_INFINITY : Number.POSITIVE_INFINITY;
130
+ }
131
+ bits = (BigInt(biased) << FRACTION_BITS_) | (significand & FRACTION_MASK_);
132
+ }
133
+ return bitsToFloat64(isNegative ? bits | SIGN_BIT_ : bits);
134
+ }
135
+ /**
136
+ * The sign of the exact `Σ aᵢ·bᵢ`: `-1`, `0` (only an exactly zero sum, which
137
+ * empty input is) or `1`. The reference `dotSign` is checked against, with the
138
+ * same independence as {@link exactDot}.
139
+ *
140
+ * Time complexity: O(n) `bigint` operations, as {@link exactDot}.
141
+ *
142
+ * @example
143
+ * exactDotSign([1e17, -1, -1e17], [1, 1, 1]); // -1
144
+ *
145
+ * @param a - Left factors.
146
+ * @param b - Right factors, paired by index.
147
+ * @returns The sign of the exact sum.
148
+ * @throws {RangeError} When `a` and `b` differ in length, or an entry is `NaN`
149
+ * or infinite.
150
+ */
151
+ export function exactDotSign(a, b) {
152
+ const { mantissa: units } = exactSum_(a, b, "exactDotSign");
153
+ if (units === 0n) {
154
+ return 0;
155
+ }
156
+ return units > 0n ? 1 : -1;
157
+ }
158
+ /**
159
+ * `Σ |aᵢ·bᵢ|` in plain arithmetic: the scale a dot product's error bound is
160
+ * stated against (`|computed − exact| ≤ k·ε·Σ|aᵢbᵢ|`). Non-finite entries
161
+ * propagate, as they do in the dot products it measures.
162
+ *
163
+ * Time complexity: O(n).
164
+ *
165
+ * @example
166
+ * absoluteDot([1, -2], [3, 4]); // 11
167
+ *
168
+ * @param a - Left factors.
169
+ * @param b - Right factors, paired by index.
170
+ * @returns The sum of the absolute products, rounded as it goes.
171
+ * @throws {RangeError} When `a` and `b` differ in length.
172
+ */
173
+ export function absoluteDot(a, b) {
174
+ if (a.length !== b.length) {
175
+ throw new RangeError(`absoluteDot: a and b must have the same length, got ${a.length} and ${b.length}`);
176
+ }
177
+ let total = 0;
178
+ for (let index = 0; index < a.length; index++) {
179
+ total += Math.abs(a[index] * b[index]);
180
+ }
181
+ return total;
182
+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AAM,UAAU,YAAY,CAC3B,CAAoB,EACpB,CAAoB;IAEpB,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,GAAG,SAAS,CAAC,CAAC,EAAE,CAAC,EAAE,cAAc,CAAC,CAAC;IAE5D,IAAI,KAAK,KAAK,EAAE,EAAE,CAAC;QAClB,OAAO,CAAC,CAAC;IACV,CAAC;IAED,OAAO,KAAK,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC5B,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,WAAW,CAC1B,CAAoB,EACpB,CAAoB;IAEpB,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,MAAM,EAAE,CAAC;QAC3B,MAAM,IAAI,UAAU,CACnB,uDAAuD,CAAC,CAAC,MAAM,QAAQ,CAAC,CAAC,MAAM,EAAE,CACjF,CAAC;IACH,CAAC;IAED,IAAI,KAAK,GAAG,CAAC,CAAC;IAEd,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,CAAC,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC;QAC/C,KAAK,IAAI,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAE,GAAG,CAAC,CAAC,KAAK,CAAE,CAAC,CAAC;IAC1C,CAAC;IAED,OAAO,KAAK,CAAC;AACd,CAAC"}
@@ -0,0 +1,31 @@
1
+ import type { NumberSampler, OutFirstCase } from "./out-first-case.js";
2
+ /**
3
+ * Asserts the alias rule of a function that writes into a first `out`:
4
+ * whichever input `out` is, and even when every input of its type is the same
5
+ * array, the result is the one a separate `out` gives, bit for bit, and the
6
+ * function returns `out` (or, for a case declared `returns: "value"`, the same
7
+ * value as with a separate `out`).
8
+ *
9
+ * It runs the case (see {@link defineOutFirstCase}) with:
10
+ *
11
+ * 1. A fresh `out`;
12
+ * 2. `out` set to each aliasable argument in turn;
13
+ * 3. When two or more arguments are aliasable, every one of them set to the same
14
+ * array, with `out` that array, against the same inputs with a fresh `out`.
15
+ *
16
+ * Every comparison uses `Object.is` per element, so `NaN` and `-0` count. A
17
+ * failure names the case, the placement and the first element that differs.
18
+ *
19
+ * Time complexity: 1 + k calls of the function, plus 2 more when k ≥ 2, each
20
+ * with an O(length) comparison, where k is the number of aliasable arguments.
21
+ *
22
+ * @example
23
+ * expectAliasSafe(vec2AddCase, samplerOf([1, 2, 3, 4]));
24
+ *
25
+ * @param testCase - The function's case.
26
+ * @param sampler - The numbers its arguments are built from; every run starts
27
+ * it again.
28
+ * @throws {AssertionError} On the first placement that differs.
29
+ */
30
+ export declare function expectAliasSafe(testCase: OutFirstCase, sampler: NumberSampler): void;
31
+ //# sourceMappingURL=expect-alias-safe.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"expect-alias-safe.d.ts","sourceRoot":"","sources":["../src/expect-alias-safe.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACX,aAAa,EACb,YAAY,EAGZ,MAAM,qBAAqB,CAAC;AAiD7B;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,eAAe,CAC9B,QAAQ,EAAE,YAAY,EACtB,OAAO,EAAE,aAAa,GACpB,IAAI,CAuCN"}
@@ -0,0 +1,80 @@
1
+ import { expect } from "vitest";
2
+ function describePlacement_(placement) {
3
+ const where = placement.out === "fresh"
4
+ ? "a fresh out"
5
+ : `out aliased to argument ${placement.out}`;
6
+ return placement.share ? `${where}, every aliasable input one array` : where;
7
+ }
8
+ function show_(value) {
9
+ return Object.is(value, -0) ? "-0" : String(value);
10
+ }
11
+ function expectSameNumbers_(label, actual, expected) {
12
+ expect(actual.length, `${label}: length of out`).toBe(expected.length);
13
+ for (let index = 0; index < expected.length; index++) {
14
+ if (!Object.is(actual[index], expected[index])) {
15
+ expect.fail(`${label}: out[${index}] is ${show_(actual[index])}, a separate out gives ${show_(expected[index])}`);
16
+ }
17
+ }
18
+ }
19
+ function expectReturn_(testCase, label, run, separate) {
20
+ if (testCase.returns === "out") {
21
+ expect(run.returned === run.out, `${label}: must return out itself`).toBe(true);
22
+ }
23
+ else {
24
+ expect(Object.is(run.returned, separate.returned), `${label}: returned ${show_(run.returned)}, a separate out gives ${show_(separate.returned)}`).toBe(true);
25
+ }
26
+ }
27
+ /**
28
+ * Asserts the alias rule of a function that writes into a first `out`:
29
+ * whichever input `out` is, and even when every input of its type is the same
30
+ * array, the result is the one a separate `out` gives, bit for bit, and the
31
+ * function returns `out` (or, for a case declared `returns: "value"`, the same
32
+ * value as with a separate `out`).
33
+ *
34
+ * It runs the case (see {@link defineOutFirstCase}) with:
35
+ *
36
+ * 1. A fresh `out`;
37
+ * 2. `out` set to each aliasable argument in turn;
38
+ * 3. When two or more arguments are aliasable, every one of them set to the same
39
+ * array, with `out` that array, against the same inputs with a fresh `out`.
40
+ *
41
+ * Every comparison uses `Object.is` per element, so `NaN` and `-0` count. A
42
+ * failure names the case, the placement and the first element that differs.
43
+ *
44
+ * Time complexity: 1 + k calls of the function, plus 2 more when k ≥ 2, each
45
+ * with an O(length) comparison, where k is the number of aliasable arguments.
46
+ *
47
+ * @example
48
+ * expectAliasSafe(vec2AddCase, samplerOf([1, 2, 3, 4]));
49
+ *
50
+ * @param testCase - The function's case.
51
+ * @param sampler - The numbers its arguments are built from; every run starts
52
+ * it again.
53
+ * @throws {AssertionError} On the first placement that differs.
54
+ */
55
+ export function expectAliasSafe(testCase, sampler) {
56
+ const fresh = { out: "fresh", share: false };
57
+ const separate = testCase.run(fresh, sampler);
58
+ expectReturn_(testCase, `${testCase.name}, ${describePlacement_(fresh)}`, separate, separate);
59
+ for (const index of testCase.aliasable) {
60
+ const placement = { out: index, share: false };
61
+ const label = `${testCase.name}, ${describePlacement_(placement)}`;
62
+ const aliased = testCase.run(placement, sampler);
63
+ expectReturn_(testCase, label, aliased, separate);
64
+ expectSameNumbers_(label, aliased.out, separate.out);
65
+ }
66
+ if (testCase.aliasable.length >= 2) {
67
+ const sharedFresh = { out: "fresh", share: true };
68
+ const sharedInPlace = {
69
+ out: testCase.aliasable[0],
70
+ share: true,
71
+ };
72
+ const label = `${testCase.name}, ${describePlacement_(sharedInPlace)}`;
73
+ const expected = testCase.run(sharedFresh, sampler);
74
+ const inPlace = testCase.run(sharedInPlace, sampler);
75
+ expectReturn_(testCase, `${testCase.name}, ${describePlacement_(sharedFresh)}`, expected, expected);
76
+ expectReturn_(testCase, label, inPlace, expected);
77
+ expectSameNumbers_(label, inPlace.out, expected.out);
78
+ }
79
+ }
80
+ //# sourceMappingURL=expect-alias-safe.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"expect-alias-safe.js","sourceRoot":"","sources":["../src/expect-alias-safe.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAShC,SAAS,kBAAkB,CAAC,SAAuB;IAClD,MAAM,KAAK,GACV,SAAS,CAAC,GAAG,KAAK,OAAO;QACxB,CAAC,CAAC,aAAa;QACf,CAAC,CAAC,2BAA2B,SAAS,CAAC,GAAG,EAAE,CAAC;IAE/C,OAAO,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,KAAK,mCAAmC,CAAC,CAAC,CAAC,KAAK,CAAC;AAC9E,CAAC;AAED,SAAS,KAAK,CAAC,KAAc;IAC5B,OAAO,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AACpD,CAAC;AAED,SAAS,kBAAkB,CAC1B,KAAa,EACb,MAAyB,EACzB,QAA2B;IAE3B,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,KAAK,iBAAiB,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IAEvE,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,QAAQ,CAAC,MAAM,EAAE,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AAK,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC;QAClD,kBAAkB,CAAC,KAAK,EAAE,OAAO,CAAC,GAAG,EAAE,QAAQ,CAAC,GAAG,CAAC,CAAC;IACtD,CAAC;AACF,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"fake-wall-clock.d.ts","sourceRoot":"","sources":["../src/fake-wall-clock.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,KAAK,aAAa,EAGlB,MAAM,cAAc,CAAC;AAgBtB;;;;;;;;;;;;;;;;GAgBG;AACH,qBAAa,aAAa;IACzB,OAAO,CAAC,YAAY,CAAS;IAE7B;;;OAGG;IACH,QAAQ,CAAC,OAAO,EAAE,aAAa,CAC4B;IAE3D;;;;;OAKG;IACH,YAAY,KAAK,SAAI,EAIpB;IAED,6DAA6D;IAC7D,IAAI,iBAAiB,IAAI,MAAM,CAE9B;IAED;;;;;OAKG;IACH,GAAG,CAAC,iBAAiB,EAAE,MAAM,GAAG,IAAI,CAInC;IAED;;;;;;OAMG;IACH,OAAO,CAAC,YAAY,EAAE,MAAM,GAAG,IAAI,CAQlC;CACD"}
1
+ {"version":3,"file":"fake-wall-clock.d.ts","sourceRoot":"","sources":["../src/fake-wall-clock.ts"],"names":[],"mappings":"AAAA,OAAO,EAEN,KAAK,aAAa,EAGlB,MAAM,cAAc,CAAC;AAgBtB;;;;;;;;;;;;;;;;GAgBG;AACH,qBAAa,aAAa;IACzB,OAAO,CAAC,YAAY,CAAS;IAE7B;;;OAGG;IACH,QAAQ,CAAC,OAAO,EAAE,aAAa,CAC4B;IAE3D;;;;;OAKG;IACH,YAAY,KAAK,SAAI,EAIpB;IAED,6DAA6D;IAC7D,IAAI,iBAAiB,IAAI,MAAM,CAE9B;IAED;;;;;OAKG;IACH,GAAG,CAAC,iBAAiB,EAAE,MAAM,GAAG,IAAI,CAInC;IAED;;;;;;OAMG;IACH,OAAO,CAAC,YAAY,EAAE,MAAM,GAAG,IAAI,CAQlC;CACD"}
@@ -1,7 +1,7 @@
1
- import { isIntegerInRange, MAX_INSTANT_EPOCH_MILLISECONDS, } from "@ac-kit/core";
1
+ import { describeValue, isIntegerInRange, MAX_INSTANT_EPOCH_MILLISECONDS, } from "@ac-kit/core";
2
2
  function assertEpochMilliseconds_(name, milliseconds) {
3
3
  if (!isIntegerInRange(milliseconds, -MAX_INSTANT_EPOCH_MILLISECONDS, MAX_INSTANT_EPOCH_MILLISECONDS + 1)) {
4
- throw new RangeError(`FakeWallClock: ${name} ${String(milliseconds)} is not an integer number of milliseconds a Temporal.Instant can hold`);
4
+ throw new RangeError(`FakeWallClock: ${name} ${describeValue(milliseconds)} is not an integer number of milliseconds a Temporal.Instant can hold`);
5
5
  }
6
6
  }
7
7
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"fake-wall-clock.js","sourceRoot":"","sources":["../src/fake-wall-clock.ts"],"names":[],"mappings":"AAAA,OAAO,EAEN,gBAAgB,EAChB,8BAA8B,GAC9B,MAAM,cAAc,CAAC;AAEtB,SAAS,wBAAwB,CAAC,IAAY,EAAE,YAAoB;IACnE,IACC,CAAC,gBAAgB,CAChB,YAAY,EACZ,CAAC,8BAA8B,EAC/B,8BAA8B,GAAG,CAAC,CAClC,EACA,CAAC;QACF,MAAM,IAAI,UAAU,CACnB,kBAAkB,IAAI,IAAI,MAAM,CAAC,YAAY,CAAC,uEAAuE,CACrH,CAAC;IACH,CAAC;AACF,CAAC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,OAAO,aAAa;IACjB,YAAY,CAAS;IAE7B;;;OAGG;IACM,OAAO,GAAkB,GAAG,EAAE,CACtC,QAAQ,CAAC,OAAO,CAAC,qBAAqB,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IAE3D;;;;;OAKG;IACH,YAAY,KAAK,GAAG,CAAC;QACpB,wBAAwB,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;QAEzC,IAAI,CAAC,YAAY,GAAG,KAAK,CAAC;IAC3B,CAAC;IAED,6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AAY,GAAG,KAAK,CAAC;IAC3B,CAAC;IAED,6DAA6D;IAC7D,IAAI,iBAAiB;QACpB,OAAO,IAAI,CAAC,YAAY,CAAC;IAC1B,CAAC;IAED;;;;;OAKG;IACH,GAAG,CAAC,iBAAyB;QAC5B,wBAAwB,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC;QAEpD,IAAI,CAAC,YAAY,GAAG,iBAAiB,CAAC;IACvC,CAAC;IAED;;;;;;OAMG;IACH,OAAO,CAAC,YAAoB;QAC3B,wBAAwB,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;QAE/C,MAAM,MAAM,GAAG,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QAEhD,wBAAwB,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAEzC,IAAI,CAAC,YAAY,GAAG,MAAM,CAAC;IAC5B,CAAC;CACD"}
package/dist/index.d.ts CHANGED
@@ -1,6 +1,9 @@
1
1
  export * from "./busy-wait.js";
2
+ export * from "./exact-dot.js";
3
+ export * from "./expect-alias-safe.js";
2
4
  export * from "./expect-close-relative.js";
3
5
  export * from "./expect-compare-agrees-with-equals.js";
4
6
  export * from "./fake-clock.js";
5
7
  export * from "./fake-wall-clock.js";
8
+ export * from "./out-first-case.js";
6
9
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,4BAA4B,CAAC;AAC3C,cAAc,wCAAwC,CAAC;AACvD,cAAc,iBAAiB,CAAC;AAChC,cAAc,sBAAsB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,wBAAwB,CAAC;AACvC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,wCAAwC,CAAC;AACvD,cAAc,iBAAiB,CAAC;AAChC,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC"}
package/dist/index.js CHANGED
@@ -1,6 +1,9 @@
1
1
  export * from "./busy-wait.js";
2
+ export * from "./exact-dot.js";
3
+ export * from "./expect-alias-safe.js";
2
4
  export * from "./expect-close-relative.js";
3
5
  export * from "./expect-compare-agrees-with-equals.js";
4
6
  export * from "./fake-clock.js";
5
7
  export * from "./fake-wall-clock.js";
8
+ export * from "./out-first-case.js";
6
9
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,4BAA4B,CAAC;AAC3C,cAAc,wCAAwC,CAAC;AACvD,cAAc,iBAAiB,CAAC;AAChC,cAAc,sBAAsB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,wBAAwB,CAAC;AACvC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,wCAAwC,CAAC;AACvD,cAAc,iBAAiB,CAAC;AAChC,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC"}
@@ -0,0 +1,116 @@
1
+ import { type Callable, type CallableNoArgs } from "@ac-kit/core";
2
+ /**
3
+ * A source of numbers that starts again: each call returns a fresh `next`
4
+ * yielding the same sequence, so every run of a case builds the same inputs.
5
+ */
6
+ export type NumberSampler = CallableNoArgs<CallableNoArgs<number>>;
7
+ /**
8
+ * A sampler that replays `values` in order on every pass. A pass asking for
9
+ * more numbers than `values` holds throws a `RangeError`: the case needs more
10
+ * inputs than it was given.
11
+ *
12
+ * Time complexity: O(1) per number.
13
+ *
14
+ * @example
15
+ * const sampler = samplerOf([1, 2, 3]);
16
+ * const next = sampler();
17
+ * next(); // 1
18
+ * sampler()(); // 1 again, from a fresh pass
19
+ *
20
+ * @param values - The numbers of one pass.
21
+ * @returns A sampler whose every pass yields `values`.
22
+ */
23
+ export declare function samplerOf(values: readonly number[]): NumberSampler;
24
+ /** What a function with an `out` first argument is run with. */
25
+ export interface OutFirstCaseDefinition<TOut extends ArrayLike<number>, TArgs extends readonly unknown[]> {
26
+ readonly name: string;
27
+ /**
28
+ * A fresh `out`, made by the value's own creator (never a literal or another
29
+ * container).
30
+ */
31
+ readonly create: CallableNoArgs<TOut>;
32
+ /**
33
+ * Indexes into the arguments of the inputs of `out`'s type: those `out` may
34
+ * be.
35
+ */
36
+ readonly aliasable: readonly number[];
37
+ /**
38
+ * The arguments after `out`, built from `next`; the same numbers must give
39
+ * equal arguments.
40
+ */
41
+ readonly makeArguments: Callable<[next: CallableNoArgs<number>], TArgs>;
42
+ readonly call: Callable<[out: TOut, args: TArgs], unknown>;
43
+ /**
44
+ * `"out"` (the default): the call returns `out`. `"value"`: it returns
45
+ * something else — a success flag, nothing — which must not depend on where
46
+ * `out` is.
47
+ */
48
+ readonly returns?: "out" | "value";
49
+ }
50
+ /** Where the `out` of a run comes from, and whether the inputs are one array. */
51
+ export interface OutPlacement {
52
+ /** `"fresh"`, or the index of the argument used as `out`. */
53
+ readonly out: "fresh" | number;
54
+ /** Every aliasable argument is the same array, the first one's. */
55
+ readonly share: boolean;
56
+ }
57
+ /** What one run of a case produced. */
58
+ export interface OutFirstRun {
59
+ readonly out: ArrayLike<number>;
60
+ readonly returned: unknown;
61
+ }
62
+ /** One out-first function with a generator of inputs, ready to be run. */
63
+ export interface OutFirstCase {
64
+ readonly name: string;
65
+ readonly aliasable: readonly number[];
66
+ readonly returns: "out" | "value";
67
+ /**
68
+ * Builds the arguments from `sampler`, places `out` and calls the function.
69
+ *
70
+ * @throws {RangeError} When an aliasable index is past the arguments, or
71
+ * `placement.out` is neither `"fresh"` nor an aliasable index.
72
+ * @throws {TypeError} When the argument at an aliasable index has a `length`
73
+ * different from `out`'s.
74
+ */
75
+ readonly run: Callable<[
76
+ placement: OutPlacement,
77
+ sampler: NumberSampler
78
+ ], OutFirstRun>;
79
+ }
80
+ /**
81
+ * Describes a function that writes its result into a first `out` argument, for
82
+ * {@link expectAliasSafe}: how to build an `out`, which of the other arguments
83
+ * are of the same type (so `out` may be one of them), how to build the
84
+ * arguments from numbers and how to call it.
85
+ *
86
+ * A package keeps the table of its own functions — which take `out` first and
87
+ * which positions may alias — and hands each case to {@link expectAliasSafe}.
88
+ * Cases also serve other checks over the same table: `run` is the building
89
+ * block, and `aliasable` lists the positions.
90
+ *
91
+ * The harness never builds a value it passes to the function under test:
92
+ * `create` and `makeArguments` do, so a branded vector is always made by its
93
+ * own creator. It covers bulk kernels too — a `Float64Array` `out`, in place.
94
+ *
95
+ * Time complexity: O(1) to define; each `run` costs one call plus building the
96
+ * arguments.
97
+ *
98
+ * @example
99
+ * const testCase = defineOutFirstCase({
100
+ * name: "vec2Add",
101
+ * create: () => vec2Create(),
102
+ * aliasable: [0, 1],
103
+ * makeArguments: (next) => [
104
+ * vec2Of(next(), next()),
105
+ * vec2Of(next(), next()),
106
+ * ],
107
+ * call: (out, [a, b]) => vec2Add(out, a, b),
108
+ * });
109
+ *
110
+ * @param definition - The function's table entry.
111
+ * @returns The case.
112
+ * @throws {RangeError} When an aliasable index is negative, fractional or
113
+ * repeated.
114
+ */
115
+ export declare function defineOutFirstCase<TOut extends ArrayLike<number>, const TArgs extends readonly unknown[]>(definition: OutFirstCaseDefinition<TOut, TArgs>): OutFirstCase;
116
+ //# sourceMappingURL=out-first-case.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"out-first-case.d.ts","sourceRoot":"","sources":["../src/out-first-case.ts"],"names":[],"mappings":"AAAA,OAAO,EAEN,KAAK,QAAQ,EACb,KAAK,cAAc,EACnB,MAAM,cAAc,CAAC;AAEtB;;;GAGG;AACH,MAAM,MAAM,aAAa,GAAG,cAAc,CAAC,cAAc,CAAC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CAAC;IACtC,QAAQ,CAAC,OAAO,EAAE,KAAK,GAAG,OAAO,CAAC;IAClC;;;;;;;OAOG;IACH,QAAQ,CAAC,GAAG,EAAE,QAAQ,CACrB;QAAC,SAAS,EAAE,YAAY;QAAE,OAAO,EAAE,aAAa;KAAC,EACjD,WAAW,CACX,CAAC;CACF;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,wBAAgB,kBAAkB,CACjC,IAAI,SAAS,SAAS,CAAC,MAAM,CAAC,EAC9B,KAAK,CAAC,KAAK,SAAS,SAAS,OAAO,EAAE,EACrC,UAAU,EAAE,sBAAsB,CAAC,IAAI,EAAE,KAAK,CAAC,GAAG,YAAY,CA0E/D"}
@@ -0,0 +1,117 @@
1
+ import { describeValue, } from "@ac-kit/core";
2
+ /**
3
+ * A sampler that replays `values` in order on every pass. A pass asking for
4
+ * more numbers than `values` holds throws a `RangeError`: the case needs more
5
+ * inputs than it was given.
6
+ *
7
+ * Time complexity: O(1) per number.
8
+ *
9
+ * @example
10
+ * const sampler = samplerOf([1, 2, 3]);
11
+ * const next = sampler();
12
+ * next(); // 1
13
+ * sampler()(); // 1 again, from a fresh pass
14
+ *
15
+ * @param values - The numbers of one pass.
16
+ * @returns A sampler whose every pass yields `values`.
17
+ */
18
+ export function samplerOf(values) {
19
+ // A copy: later changes to the caller's array must not change a later pass.
20
+ const snapshot = Array.from(values);
21
+ return () => {
22
+ let index = 0;
23
+ return () => {
24
+ if (index >= snapshot.length) {
25
+ throw new RangeError(`samplerOf: a case asked for number ${index + 1}, but only ${snapshot.length} were given`);
26
+ }
27
+ return snapshot[index++];
28
+ };
29
+ };
30
+ }
31
+ /**
32
+ * Describes a function that writes its result into a first `out` argument, for
33
+ * {@link expectAliasSafe}: how to build an `out`, which of the other arguments
34
+ * are of the same type (so `out` may be one of them), how to build the
35
+ * arguments from numbers and how to call it.
36
+ *
37
+ * A package keeps the table of its own functions — which take `out` first and
38
+ * which positions may alias — and hands each case to {@link expectAliasSafe}.
39
+ * Cases also serve other checks over the same table: `run` is the building
40
+ * block, and `aliasable` lists the positions.
41
+ *
42
+ * The harness never builds a value it passes to the function under test:
43
+ * `create` and `makeArguments` do, so a branded vector is always made by its
44
+ * own creator. It covers bulk kernels too — a `Float64Array` `out`, in place.
45
+ *
46
+ * Time complexity: O(1) to define; each `run` costs one call plus building the
47
+ * arguments.
48
+ *
49
+ * @example
50
+ * const testCase = defineOutFirstCase({
51
+ * name: "vec2Add",
52
+ * create: () => vec2Create(),
53
+ * aliasable: [0, 1],
54
+ * makeArguments: (next) => [
55
+ * vec2Of(next(), next()),
56
+ * vec2Of(next(), next()),
57
+ * ],
58
+ * call: (out, [a, b]) => vec2Add(out, a, b),
59
+ * });
60
+ *
61
+ * @param definition - The function's table entry.
62
+ * @returns The case.
63
+ * @throws {RangeError} When an aliasable index is negative, fractional or
64
+ * repeated.
65
+ */
66
+ export function defineOutFirstCase(definition) {
67
+ const { name, create, makeArguments, call } = definition;
68
+ const aliasable = [...definition.aliasable];
69
+ const returns = definition.returns ?? "out";
70
+ const seen = new Set();
71
+ for (const index of aliasable) {
72
+ if (!Number.isInteger(index) || index < 0 || seen.has(index)) {
73
+ throw new RangeError(`${name}: aliasable must be distinct non-negative integers, got ${describeValue(index)}`);
74
+ }
75
+ seen.add(index);
76
+ }
77
+ return {
78
+ name,
79
+ aliasable,
80
+ returns,
81
+ run(placement, sampler) {
82
+ const built = makeArguments(sampler());
83
+ for (const index of aliasable) {
84
+ if (index >= built.length) {
85
+ throw new RangeError(`${name}: aliasable index ${index} is past the ${built.length} arguments`);
86
+ }
87
+ }
88
+ if (placement.out !== "fresh" && !aliasable.includes(placement.out)) {
89
+ throw new RangeError(`${name}: out must be "fresh" or an aliasable index, got ${describeValue(placement.out)}`);
90
+ }
91
+ // The lengths are those of the arguments as built, before any sharing
92
+ // hides a difference between them.
93
+ const target = placement.out === "fresh"
94
+ ? create()
95
+ : built[placement.out];
96
+ for (const index of aliasable) {
97
+ const { length } = built[index];
98
+ if (length !== target.length) {
99
+ throw new TypeError(`${name}: argument ${index} has length ${length}, out has ${target.length}`);
100
+ }
101
+ }
102
+ let args = built;
103
+ if (placement.share && aliasable.length > 1) {
104
+ const shared = [...built];
105
+ for (const index of aliasable) {
106
+ shared[index] = built[aliasable[0]];
107
+ }
108
+ args = shared;
109
+ }
110
+ const out = placement.out === "fresh"
111
+ ? target
112
+ : args[placement.out];
113
+ return { out, returned: call(out, args) };
114
+ },
115
+ };
116
+ }
117
+ //# sourceMappingURL=out-first-case.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"out-first-case.js","sourceRoot":"","sources":["../src/out-first-case.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,aAAa,GAGb,MAAM,cAAc,CAAC;AAQtB;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,SAAS,CAAC,MAAyB;IAClD,4EAA4E;IAC5E,MAAM,QAAQ,GAAG,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAEpC,OAAO,GAAG,EAAE;QACX,IAAI,KAAK,GAAG,CAAC,CAAC;QAEd,OAAO,GAAG,EAAE;YACX,IAAI,KAAK,IAAI,QAAQ,CAAC,MAAM,EAAE,CAAC;gBAC9B,MAAM,IAAI,UAAU,CACnB,sCAAsC,KAAK,GAAG,CAAC,cAAc,QAAQ,CAAC,MAAM,aAAa,CACzF,CAAC;YACH,CAAC;YAED,OAAO,QAAQ,CAAC,KAAK,EAAE,CAAE,CAAC;QAC3B,CAAC,CAAC;IACH,CAAC,CAAC;AACH,CAAC;AAiED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,MAAM,UAAU,kBAAkB,CAGhC,UAA+C;IAChD,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,aAAa,EAAE,IAAI,EAAE,GAAG,UAAU,CAAC;IACzD,MAAM,SAAS,GAAG,CAAC,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC;IAC5C,MAAM,OAAO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M,KAAK,IAAI,SAAS,EAAE,CAAC;gBAC/B,MAAM,EAAE,MAAM,EAAE,GAAG,KAAK,CAAC,KAAK,CAAsB,CAAC;gBAErD,IAAI,MAAM,KAAK,MAAM,CAAC,MAAM,EAAE,CAAC;oBAC9B,MAAM,IAAI,SAAS,CAClB,GAAG,IAAI,cAAc,KAAK,eAAe,MAAM,aAAa,MAAM,CAAC,MAAM,EAAE,CAC3E,CAAC;gBACH,CAAC;YACF,CAAC;YAED,IAAI,IAAI,GAAG,KAAK,CAAC;YAEjB,IAAI,SAAS,CAAC,KAAK,IAAI,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBAC7C,MAAM,MAAM,GAAc,CAAC,GAAG,KAAK,CAAC,CAAC;gBAErC,KAAK,MAAM,KAAK,IAAI,SAAS,EAAE,CAAC;oBAC/B,MAAM,CAAC,KAAK,CAAC,GAAG,KAAK,CAAC,SAAS,CAAC,CAAC,CAAE,CAAC,CAAC;gBACtC,CAAC;gBAED,IAAI,GAAG,MAA0B,CAAC;YACnC,CAAC;YAED,MAAM,GAAG,GACR,SAAS,CAAC,GAAG,KAAK,OAAO;gBACxB,CAAC,CAAC,MAAM;gBACR,CAAC,CAAE,IAAI,CAAC,SAAS,CAAC,GAAG,CAAqB,CAAC;YAE7C,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,EAAE,CAAC;QAC3C,CAAC;KACD,CAAC;AACH,CAAC"}
@@ -0,0 +1,50 @@
1
+ /**
2
+ * The shapes V8 gives an array's elements, from the most to the least compact.
3
+ *
4
+ * - `"packed-smi"` and `"holey-smi"`: small integers only (31-bit on
5
+ * pointer-compressed builds).
6
+ * - `"packed-double"` and `"holey-double"`: numbers, stored as unboxed doubles.
7
+ * - `"packed-object"` and `"holey-object"`: any value.
8
+ * - `"dictionary"`: a sparse hash table, after a very large index or many
9
+ * deletions.
10
+ * - `"other"`: everything else — typed arrays, frozen or sealed arrays, an
11
+ * `arguments` object.
12
+ *
13
+ * A holey kind has a missing element that falls through to the prototype chain.
14
+ * V8 moves an array towards the more general kinds as it is written to (smi to
15
+ * double to object, packed to holey), and promises nothing about the way back:
16
+ * `new Array(5).fill(1)` is reported packed on current V8. Assert the kind a
17
+ * creator hands out, not the path an array took to it.
18
+ */
19
+ export type V8ElementsKind = "packed-smi" | "holey-smi" | "packed-double" | "holey-double" | "packed-object" | "holey-object" | "dictionary" | "other";
20
+ /**
21
+ * The elements kind V8 holds for `value` right now, to test that code keeps an
22
+ * array on the compact kind its speed depends on (a `number[]` that stays
23
+ * `"packed-double"`, not `"holey-smi"` or `"packed-object"`).
24
+ *
25
+ * It asks V8's own runtime (`%HasSmiElements` and its siblings), compiled on
26
+ * the first call, so it needs the flag `--allow-natives-syntax`; without it, or
27
+ * outside V8, the call throws an `Error` that names the flag. Importing this
28
+ * module never throws. The answer describes one engine version at one moment:
29
+ * assert the kinds a contract depends on, not every transition.
30
+ *
31
+ * Under Vitest, run each test file in its own process so that the kind a test
32
+ * provokes cannot reach another file's type feedback: `pool: "forks"`,
33
+ * `isolate: true` and `execArgv: ["--allow-natives-syntax"]` in the project's
34
+ * `test` options.
35
+ *
36
+ * @example
37
+ * v8ElementsKind([1.5, 2.5]); // "packed-double"
38
+ * v8ElementsKind([1, 2]); // "packed-smi"
39
+ * v8ElementsKind(new Array(3)); // "holey-smi"
40
+ *
41
+ * V8's intrinsics abort the whole process on what they refuse, so the call
42
+ * checks first: a `Proxy` has no elements of its own and answers `"other"`.
43
+ *
44
+ * @param value - An array, or any object that has elements.
45
+ * @returns The kind, `"other"` when it is none of the array kinds, or a proxy.
46
+ * @throws {TypeError} When `value` is not an object or a function.
47
+ * @throws {Error} When natives syntax is not available.
48
+ */
49
+ export declare function v8ElementsKind(value: object): V8ElementsKind;
50
+ //# sourceMappingURL=elements-kind.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"elements-kind.d.ts","sourceRoot":"","sources":["../../src/v8/elements-kind.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,MAAM,cAAc,GACvB,YAAY,GACZ,WAAW,GACX,eAAe,GACf,cAAc,GACd,eAAe,GACf,cAAc,GACd,YAAY,GACZ,OAAO,CAAC;AA+CX;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,cAAc,CAmC5D"}
@@ -0,0 +1,81 @@
1
+ let probes_;
2
+ // Natives syntax (`%HasSmiElements(value)`) is not JavaScript a module can
3
+ // contain, so each probe is compiled on first use from a fixed body; loading
4
+ // this module never needs the flag.
5
+ function compileProbe_(body) {
6
+ // oxlint-disable-next-line typescript/no-implied-eval -- natives syntax cannot be written in a module, only compiled
7
+ return new Function("value", body);
8
+ }
9
+ function getProbes_() {
10
+ if (probes_ !== undefined) {
11
+ return probes_;
12
+ }
13
+ try {
14
+ probes_ = {
15
+ isProxy: compileProbe_("return %IsJSProxy(value)"),
16
+ hasDictionary: compileProbe_("return %HasDictionaryElements(value)"),
17
+ hasSmi: compileProbe_("return %HasSmiElements(value)"),
18
+ hasDouble: compileProbe_("return %HasDoubleElements(value)"),
19
+ hasObject: compileProbe_("return %HasObjectElements(value)"),
20
+ hasHoley: compileProbe_("return %HasHoleyElements(value)"),
21
+ };
22
+ }
23
+ catch (cause) {
24
+ throw new Error("v8ElementsKind needs V8 started with --allow-natives-syntax; with Vitest, set `pool: 'forks'` and `execArgv: ['--allow-natives-syntax']` in the project's test options", { cause });
25
+ }
26
+ return probes_;
27
+ }
28
+ /**
29
+ * The elements kind V8 holds for `value` right now, to test that code keeps an
30
+ * array on the compact kind its speed depends on (a `number[]` that stays
31
+ * `"packed-double"`, not `"holey-smi"` or `"packed-object"`).
32
+ *
33
+ * It asks V8's own runtime (`%HasSmiElements` and its siblings), compiled on
34
+ * the first call, so it needs the flag `--allow-natives-syntax`; without it, or
35
+ * outside V8, the call throws an `Error` that names the flag. Importing this
36
+ * module never throws. The answer describes one engine version at one moment:
37
+ * assert the kinds a contract depends on, not every transition.
38
+ *
39
+ * Under Vitest, run each test file in its own process so that the kind a test
40
+ * provokes cannot reach another file's type feedback: `pool: "forks"`,
41
+ * `isolate: true` and `execArgv: ["--allow-natives-syntax"]` in the project's
42
+ * `test` options.
43
+ *
44
+ * @example
45
+ * v8ElementsKind([1.5, 2.5]); // "packed-double"
46
+ * v8ElementsKind([1, 2]); // "packed-smi"
47
+ * v8ElementsKind(new Array(3)); // "holey-smi"
48
+ *
49
+ * V8's intrinsics abort the whole process on what they refuse, so the call
50
+ * checks first: a `Proxy` has no elements of its own and answers `"other"`.
51
+ *
52
+ * @param value - An array, or any object that has elements.
53
+ * @returns The kind, `"other"` when it is none of the array kinds, or a proxy.
54
+ * @throws {TypeError} When `value` is not an object or a function.
55
+ * @throws {Error} When natives syntax is not available.
56
+ */
57
+ export function v8ElementsKind(value) {
58
+ if ((typeof value !== "object" && typeof value !== "function") ||
59
+ value === null) {
60
+ throw new TypeError(`v8ElementsKind needs an object, got ${value === null ? "null" : typeof value}`);
61
+ }
62
+ const probes = getProbes_();
63
+ if (probes.isProxy(value)) {
64
+ return "other";
65
+ }
66
+ if (probes.hasDictionary(value)) {
67
+ return "dictionary";
68
+ }
69
+ const holey = probes.hasHoley(value);
70
+ if (probes.hasSmi(value)) {
71
+ return holey ? "holey-smi" : "packed-smi";
72
+ }
73
+ if (probes.hasDouble(value)) {
74
+ return holey ? "holey-double" : "packed-double";
75
+ }
76
+ if (probes.hasObject(value)) {
77
+ return holey ? "holey-object" : "packed-object";
78
+ }
79
+ return "other";
80
+ }
81
+ //# sourceMappingURL=elements-kind.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"elements-kind.js","sourceRoot":"","sources":["../../src/v8/elements-kind.ts"],"names":[],"mappings":"AAuCA,IAAI,OAA4B,CAAC;AAEjC,2EAA2E;AAC3E,6EAA6E;AAC7E,oCAAoC;AACpC,SAAS,aAAa,CA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B,CAAC;IAED,MAAM,KAAK,GAAG,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAErC,IAAI,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;QAC1B,OAAO,KAAK,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,YAAY,CAAC;IAC3C,CAAC;IAED,IAAI,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC;QAC7B,OAAO,KAAK,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,eAAe,CAAC;IACjD,CAAC;IAED,IAAI,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC;QAC7B,OAAO,KAAK,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,eAAe,CAAC;IACjD,CAAC;IAED,OAAO,OAAO,CAAC;AAChB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from "./elements-kind.js";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/v8/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from "./elements-kind.js";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/v8/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ac-kit/test-util",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "Dependency-free test-harness primitives, such as a deterministic synchronous delay for timing-sensitive tests.",
5
5
  "keywords": [
6
6
  "test-utils",
@@ -24,8 +24,16 @@
24
24
  "type": "module",
25
25
  "sideEffects": false,
26
26
  "main": "./dist/index.js",
27
+ "exports": {
28
+ ".": "./dist/index.js",
29
+ "./v8": "./dist/v8/index.js"
30
+ },
27
31
  "publishConfig": {
28
32
  "main": "./dist/index.js",
33
+ "exports": {
34
+ ".": "./dist/index.js",
35
+ "./v8": "./dist/v8/index.js"
36
+ },
29
37
  "access": "public"
30
38
  },
31
39
  "scripts": {
@@ -37,19 +45,22 @@
37
45
  "prepack": "yarn build"
38
46
  },
39
47
  "dependencies": {
40
- "@ac-kit/core": "^0.10.0"
48
+ "@ac-kit/core": "^0.12.0"
41
49
  },
42
50
  "devDependencies": {
43
51
  "@ac-kit/tsconfig": "0.1.0",
44
52
  "@ac-kit/typedoc-config": "0.1.0",
45
- "@ac-kit/vitest-config": "0.1.1",
46
- "@types/node": "26.6.6",
53
+ "@ac-kit/vitest-config": "0.2.0",
54
+ "@types/node": "26.6.11",
47
55
  "@typescript/native": "typescript@7.0.2",
48
56
  "rimraf": "6.1.4",
49
57
  "typedoc": "0.28.20",
50
58
  "typescript": "@typescript/typescript6@6.0.2",
51
- "vite": "8.3.8",
52
- "vitest": "5.1.1"
59
+ "vite": "8.4.0",
60
+ "vitest": "5.1.2"
61
+ },
62
+ "peerDependencies": {
63
+ "vitest": ">=4.0.0"
53
64
  },
54
65
  "engines": {
55
66
  "node": ">=24"