From 50e5209e644a1a5eb75f575b66f7f1ffce39ccf5 Mon Sep 17 00:00:00 2001 From: Michael Ficarra Date: Fri, 6 Sep 2024 10:23:38 -0700 Subject: [PATCH] Fixes #6: don't default chunk/window size to 2 (#9) --- spec.emu | 6 ++---- src/index.ts | 4 ++-- test/index.mjs | 12 +++++++++--- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/spec.emu b/spec.emu index ed3a95f..4d0f43c 100644 --- a/spec.emu +++ b/spec.emu @@ -10,12 +10,11 @@ copyright: false -

Iterator.prototype.chunks ( [ _chunkSize_ ] )

+

Iterator.prototype.chunks ( _chunkSize_ )

This method performs the following steps when called:

1. Let _O_ be the *this* value. 1. If _O_ is not an Object, throw a *TypeError* exception. - 1. If _chunkSize_ is not present, set _chunkSize_ to *2*𝔽. 1. If _chunkSize_ is not an integral Number in the inclusive interval from *1*𝔽 to 𝔽(232 - 1), throw a *RangeError* exception. 1. Let _iterated_ be ? GetIteratorDirect(_O_). 1. Let _closure_ be a new Abstract Closure with no parameters that captures _iterated_ and _chunkSize_ and performs the following steps when called: @@ -35,12 +34,11 @@ copyright: false
-

Iterator.prototype.windows ( [ _windowSize_ ] )

+

Iterator.prototype.windows ( _windowSize_ )

This method performs the following steps when called:

1. Let _O_ be the *this* value. 1. If _O_ is not an Object, throw a *TypeError* exception. - 1. If _windowSize_ is not present, set _windowSize_ to *2*𝔽. 1. If _windowSize_ is not an integral Number in the inclusive interval from *1*𝔽 to 𝔽(232 - 1), throw a *RangeError* exception. 1. Let _iterated_ be ? GetIteratorDirect(_O_). 1. Let _closure_ be a new Abstract Closure with no parameters that captures _iterated_ and _windowSize_ and performs the following steps when called: diff --git a/src/index.ts b/src/index.ts index c16e584..b4f6a97 100644 --- a/src/index.ts +++ b/src/index.ts @@ -19,7 +19,7 @@ function* chunksImpl(iter: Iterator, chunkSize: number): Generator(this: Iterator, chunkSize: number): Generator> -function chunks(this: unknown, chunkSize: unknown = 2): Generator { +function chunks(this: unknown, chunkSize: unknown): Generator { if ( typeof chunkSize !== 'number' || chunkSize <= 0 @@ -45,7 +45,7 @@ function* windowsImpl(iter: Iterator, windowSize: number): Generator(this: Iterator, windowSize: number): Generator> -function windows(this: unknown, windowSize: unknown = 2): Generator { +function windows(this: unknown, windowSize: unknown): Generator { if ( typeof windowSize !== 'number' || windowSize <= 0 diff --git a/test/index.mjs b/test/index.mjs index 20d5534..a7b31fa 100644 --- a/test/index.mjs +++ b/test/index.mjs @@ -12,7 +12,7 @@ function* nats(limit) { test('chunks', async t => { assert.deepEqual( - Array.from(nats(5).chunks()), + Array.from(nats(5).chunks(2)), [[0, 1], [2, 3], [4]], ); assert.deepEqual( @@ -36,6 +36,9 @@ test('chunks', async t => { [], ); + assert.throws(() => { + nats(1).chunks(); + }, RangeError) assert.throws(() => { nats(1).chunks([2]); }, RangeError) @@ -55,7 +58,7 @@ test('chunks', async t => { test('windows', async t => { assert.deepEqual( - Array.from(nats(5).windows()), + Array.from(nats(5).windows(2)), [[0, 1], [1, 2], [2, 3], [3, 4]], ); assert.deepEqual( @@ -75,6 +78,9 @@ test('windows', async t => { [], ); + assert.throws(() => { + nats(1).windows() + }, RangeError) assert.throws(() => { nats(1).windows([2]); }, RangeError) @@ -90,4 +96,4 @@ test('windows', async t => { assert.throws(() => { nats(1).windows(Math.pow(2, 53)); }, RangeError) -}); \ No newline at end of file +});