|
| 1 | +import { test } from "@cross/test"; |
1 | 2 | import { assertEquals, assertThrows } from "@std/assert"; |
2 | 3 | import { assertType, type IsExact } from "@std/testing/types"; |
3 | 4 | import { toAsyncIterable } from "./to_async_iterable.ts"; |
4 | 5 | import { chunked } from "./chunked.ts"; |
5 | 6 |
|
6 | | -Deno.test("chunked", async (t) => { |
7 | | - await t.step("with async iterable", async (t) => { |
8 | | - await t.step("the length is divisible by the size", async () => { |
9 | | - const result = chunked(toAsyncIterable([1, 2, 3, 4, 5, 6]), 2); |
10 | | - const expected = [[1, 2], [3, 4], [5, 6]]; |
11 | | - assertEquals(await Array.fromAsync(result), expected); |
12 | | - assertType<IsExact<typeof result, AsyncIterable<number[]>>>(true); |
13 | | - }); |
| 7 | +await test("chunked with async iterable the length is divisible by the size", async () => { |
| 8 | + const result = chunked(toAsyncIterable([1, 2, 3, 4, 5, 6]), 2); |
| 9 | + const expected = [[1, 2], [3, 4], [5, 6]]; |
| 10 | + assertEquals(await Array.fromAsync(result), expected); |
| 11 | + assertType<IsExact<typeof result, AsyncIterable<number[]>>>(true); |
| 12 | +}); |
14 | 13 |
|
15 | | - await t.step("the length is not divisible by the size", async () => { |
16 | | - const result = chunked(toAsyncIterable([1, 2, 3, 4, 5]), 2); |
17 | | - const expected = [[1, 2], [3, 4], [5]]; |
18 | | - assertEquals(await Array.fromAsync(result), expected); |
19 | | - assertType<IsExact<typeof result, AsyncIterable<number[]>>>(true); |
20 | | - }); |
| 14 | +await test("chunked with async iterable the length is not divisible by the size", async () => { |
| 15 | + const result = chunked(toAsyncIterable([1, 2, 3, 4, 5]), 2); |
| 16 | + const expected = [[1, 2], [3, 4], [5]]; |
| 17 | + assertEquals(await Array.fromAsync(result), expected); |
| 18 | + assertType<IsExact<typeof result, AsyncIterable<number[]>>>(true); |
| 19 | +}); |
21 | 20 |
|
22 | | - await t.step("the length is equal to the size", async () => { |
23 | | - const result = chunked(toAsyncIterable([1, 2, 3, 4, 5]), 5); |
24 | | - const expected = [[1, 2, 3, 4, 5]]; |
25 | | - assertEquals(await Array.fromAsync(result), expected); |
26 | | - assertType<IsExact<typeof result, AsyncIterable<number[]>>>(true); |
27 | | - }); |
| 21 | +await test("chunked with async iterable the length is equal to the size", async () => { |
| 22 | + const result = chunked(toAsyncIterable([1, 2, 3, 4, 5]), 5); |
| 23 | + const expected = [[1, 2, 3, 4, 5]]; |
| 24 | + assertEquals(await Array.fromAsync(result), expected); |
| 25 | + assertType<IsExact<typeof result, AsyncIterable<number[]>>>(true); |
| 26 | +}); |
28 | 27 |
|
29 | | - await t.step("the length is less than the size", async () => { |
30 | | - const result = chunked(toAsyncIterable([1, 2, 3, 4, 5]), 6); |
31 | | - const expected = [[1, 2, 3, 4, 5]]; |
32 | | - assertEquals(await Array.fromAsync(result), expected); |
33 | | - assertType<IsExact<typeof result, AsyncIterable<number[]>>>(true); |
34 | | - }); |
| 28 | +await test("chunked with async iterable the length is less than the size", async () => { |
| 29 | + const result = chunked(toAsyncIterable([1, 2, 3, 4, 5]), 6); |
| 30 | + const expected = [[1, 2, 3, 4, 5]]; |
| 31 | + assertEquals(await Array.fromAsync(result), expected); |
| 32 | + assertType<IsExact<typeof result, AsyncIterable<number[]>>>(true); |
| 33 | +}); |
35 | 34 |
|
36 | | - await t.step("throws RangeError", async (t) => { |
37 | | - await t.step("if the length is not positive safe integer", () => { |
38 | | - assertThrows(() => chunked([], NaN), RangeError); |
39 | | - assertThrows(() => chunked([], Infinity), RangeError); |
40 | | - assertThrows(() => chunked([], -Infinity), RangeError); |
41 | | - assertThrows(() => chunked([], -1), RangeError); |
42 | | - assertThrows(() => chunked([], 1.1), RangeError); |
43 | | - assertThrows(() => chunked([], 0), RangeError); |
44 | | - }); |
45 | | - }); |
46 | | - }); |
| 35 | +await test("chunked with async iterable throws RangeError", () => { |
| 36 | + assertThrows(() => chunked([], NaN), RangeError); |
| 37 | + assertThrows(() => chunked([], Infinity), RangeError); |
| 38 | + assertThrows(() => chunked([], -Infinity), RangeError); |
| 39 | + assertThrows(() => chunked([], -1), RangeError); |
| 40 | + assertThrows(() => chunked([], 1.1), RangeError); |
| 41 | + assertThrows(() => chunked([], 0), RangeError); |
| 42 | +}); |
47 | 43 |
|
48 | | - await t.step("with iterable", async (t) => { |
49 | | - await t.step("the length is divisible by the size", async () => { |
50 | | - const result = chunked([1, 2, 3, 4, 5, 6], 2); |
51 | | - const expected = [[1, 2], [3, 4], [5, 6]]; |
52 | | - assertEquals(await Array.fromAsync(result), expected); |
53 | | - assertType<IsExact<typeof result, AsyncIterable<number[]>>>(true); |
54 | | - }); |
| 44 | +await test("chunked with iterable the length is divisible by the size", async () => { |
| 45 | + const result = chunked([1, 2, 3, 4, 5, 6], 2); |
| 46 | + const expected = [[1, 2], [3, 4], [5, 6]]; |
| 47 | + assertEquals(await Array.fromAsync(result), expected); |
| 48 | + assertType<IsExact<typeof result, AsyncIterable<number[]>>>(true); |
| 49 | +}); |
55 | 50 |
|
56 | | - await t.step("the length is not divisible by the size", async () => { |
57 | | - const result = chunked([1, 2, 3, 4, 5], 2); |
58 | | - const expected = [[1, 2], [3, 4], [5]]; |
59 | | - assertEquals(await Array.fromAsync(result), expected); |
60 | | - assertType<IsExact<typeof result, AsyncIterable<number[]>>>(true); |
61 | | - }); |
| 51 | +await test("chunked with iterable the length is not divisible by the size", async () => { |
| 52 | + const result = chunked([1, 2, 3, 4, 5], 2); |
| 53 | + const expected = [[1, 2], [3, 4], [5]]; |
| 54 | + assertEquals(await Array.fromAsync(result), expected); |
| 55 | + assertType<IsExact<typeof result, AsyncIterable<number[]>>>(true); |
| 56 | +}); |
62 | 57 |
|
63 | | - await t.step("the length is equal to the size", async () => { |
64 | | - const result = chunked([1, 2, 3, 4, 5], 5); |
65 | | - const expected = [[1, 2, 3, 4, 5]]; |
66 | | - assertEquals(await Array.fromAsync(result), expected); |
67 | | - assertType<IsExact<typeof result, AsyncIterable<number[]>>>(true); |
68 | | - }); |
| 58 | +await test("chunked with iterable the length is equal to the size", async () => { |
| 59 | + const result = chunked([1, 2, 3, 4, 5], 5); |
| 60 | + const expected = [[1, 2, 3, 4, 5]]; |
| 61 | + assertEquals(await Array.fromAsync(result), expected); |
| 62 | + assertType<IsExact<typeof result, AsyncIterable<number[]>>>(true); |
| 63 | +}); |
69 | 64 |
|
70 | | - await t.step("the length is less than the size", async () => { |
71 | | - const result = chunked([1, 2, 3, 4, 5], 6); |
72 | | - const expected = [[1, 2, 3, 4, 5]]; |
73 | | - assertEquals(await Array.fromAsync(result), expected); |
74 | | - assertType<IsExact<typeof result, AsyncIterable<number[]>>>(true); |
75 | | - }); |
| 65 | +await test("chunked with iterable the length is less than the size", async () => { |
| 66 | + const result = chunked([1, 2, 3, 4, 5], 6); |
| 67 | + const expected = [[1, 2, 3, 4, 5]]; |
| 68 | + assertEquals(await Array.fromAsync(result), expected); |
| 69 | + assertType<IsExact<typeof result, AsyncIterable<number[]>>>(true); |
| 70 | +}); |
76 | 71 |
|
77 | | - await t.step("throws RangeError", async (t) => { |
78 | | - await t.step("if the length is not positive safe integer", () => { |
79 | | - assertThrows(() => chunked([], NaN), RangeError); |
80 | | - assertThrows(() => chunked([], Infinity), RangeError); |
81 | | - assertThrows(() => chunked([], -Infinity), RangeError); |
82 | | - assertThrows(() => chunked([], -1), RangeError); |
83 | | - assertThrows(() => chunked([], 1.1), RangeError); |
84 | | - assertThrows(() => chunked([], 0), RangeError); |
85 | | - }); |
86 | | - }); |
87 | | - }); |
| 72 | +await test("chunked with iterable throws RangeError", () => { |
| 73 | + assertThrows(() => chunked([], NaN), RangeError); |
| 74 | + assertThrows(() => chunked([], Infinity), RangeError); |
| 75 | + assertThrows(() => chunked([], -Infinity), RangeError); |
| 76 | + assertThrows(() => chunked([], -1), RangeError); |
| 77 | + assertThrows(() => chunked([], 1.1), RangeError); |
| 78 | + assertThrows(() => chunked([], 0), RangeError); |
88 | 79 | }); |
0 commit comments