Skip to content

Commit 221f725

Browse files
committed
polish
1 parent c37332f commit 221f725

File tree

6 files changed

+9
-156
lines changed

6 files changed

+9
-156
lines changed

collections/chunk_test.ts

+1-89
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function chunkTest<I>(
1515
const testArray = [1, 2, 3, 4, 5, 6];
1616

1717
Deno.test({
18-
name: "chunk() handles no mutation",
18+
name: "chunk() does not mutate the input",
1919
fn() {
2020
const array = [1, 2, 3, 4];
2121
chunk(array, 2);
@@ -121,94 +121,6 @@ Deno.test({
121121
},
122122
});
123123

124-
Deno.test("chunk() does not mutate the input", () => {
125-
const array = [1, 2, 3, 4];
126-
chunk(array, 2);
127-
assertEquals(array, [1, 2, 3, 4], "Input array should not be mutated");
128-
});
129-
130-
Deno.test("chunk() throws on non naturals", () => {
131-
assertThrows(
132-
() => chunk([], +.5),
133-
RangeError,
134-
"Expected size to be an integer greater than 0 but found 0.5",
135-
);
136-
assertThrows(
137-
() => chunk([], -4.7),
138-
RangeError,
139-
"Expected size to be an integer greater than 0 but found -4.7",
140-
);
141-
assertThrows(
142-
() => chunk([], -2),
143-
RangeError,
144-
"Expected size to be an integer greater than 0 but found -2",
145-
);
146-
assertThrows(
147-
() => chunk([], +0),
148-
RangeError,
149-
"Expected size to be an integer greater than 0 but found 0",
150-
);
151-
assertThrows(
152-
() => chunk([], -0),
153-
RangeError,
154-
"Expected size to be an integer greater than 0 but found 0",
155-
);
156-
});
157-
158-
Deno.test("chunk() returns empty array when input is empty", () => {
159-
const actual = chunk([], 1);
160-
assertEquals(actual, [], "Empty input should return empty array");
161-
});
162-
163-
Deno.test({
164-
name: "chunk() handles single element chunks",
165-
fn() {
166-
assertEquals(chunk([1, 2, 3, 4, 5, 6], 1), [[1], [2], [3], [4], [5], [6]]);
167-
assertEquals(chunk(["foo"], 1), [["foo"]]);
168-
assertEquals(chunk([null], 1), [[null]]);
169-
assertEquals(chunk([undefined], 1), [[undefined]]);
170-
},
171-
});
172-
173-
Deno.test("chunk() handles n chunks fitting", () => {
174-
assertEquals(
175-
chunk([1, 2, 3, 4, 5, 6], 2),
176-
[[1, 2], [3, 4], [5, 6]],
177-
"size=2",
178-
);
179-
assertEquals(chunk([1, 2, 3, 4, 5, 6], 3), [[1, 2, 3], [4, 5, 6]], "size=3");
180-
});
181-
182-
Deno.test("handles n chunks not fitting", () => {
183-
assertEquals(
184-
chunk([1, 2, 3, 4, 5, 6], 4),
185-
[[1, 2, 3, 4], [5, 6]],
186-
"size 4 with 6 elements should return 2 chunks with 4 and 2 elements",
187-
);
188-
assertEquals(
189-
chunk([1, 2, 3, 4, 5, 6], 5),
190-
[[1, 2, 3, 4, 5], [6]],
191-
"size 5 with 6 elements should return 2 chunks with 5 and 1 elements",
192-
);
193-
});
194-
195-
Deno.test("chunk() handles n chunks larger than input length", () => {
196-
assertEquals(
197-
chunk([1, 2, 3, 4, 5, 6], 10),
198-
[[1, 2, 3, 4, 5, 6]],
199-
);
200-
});
201-
202-
Deno.test({
203-
name: "chunk() handles chunks equal to length",
204-
fn() {
205-
assertEquals(
206-
chunk([1, 2, 3, 4, 5, 6], 6),
207-
[[1, 2, 3, 4, 5, 6]],
208-
);
209-
},
210-
});
211-
212124
Deno.test("chunk() handles a generator", () => {
213125
function* gen() {
214126
yield "a";

collections/drop_while.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*
1616
* @example Basic usage
1717
* ```ts
18-
* import { dropWhile } from "@std/collections/unstable-drop-while";
18+
* import { dropWhile } from "@std/collections/drop-while";
1919
* import { assertEquals } from "@std/assert";
2020
*
2121
* const numbers = [3, 2, 5, 2, 5];

collections/drop_while_test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,13 @@ Deno.test("dropWhile() handles a generator", () => {
8484
assertEquals(actual, [4, 5, 6]);
8585
});
8686

87-
Deno.test("(unstable) dropWhile() handles a Set", () => {
87+
Deno.test("dropWhile() handles a Set", () => {
8888
const set = new Set([1, 2, 3, 4, 5, 6]);
8989
const actual = dropWhile(set, (i) => i !== 4);
9090
assertEquals(actual, [4, 5, 6]);
9191
});
9292

93-
Deno.test("(unstable) dropWhile() handles a Map", () => {
93+
Deno.test("dropWhile() handles a Map", () => {
9494
const map = new Map([
9595
["a", 1],
9696
["b", 2],

collections/intersect_test.ts

+1-59
Original file line numberDiff line numberDiff line change
@@ -142,64 +142,6 @@ Deno.test({
142142
},
143143
});
144144

145-
Deno.test("intersect() doesn't mutate the input", () => {
146-
const arrayA = [1, 2, 3];
147-
const arrayB = [3, 4, 5];
148-
intersect(arrayA, arrayB);
149-
assertEquals(arrayA, [1, 2, 3]);
150-
assertEquals(arrayB, [3, 4, 5]);
151-
});
152-
153-
Deno.test("intersect() returns empty array when one side is empty", () => {
154-
const firstEmpty = intersect([], [1, 2, 3]);
155-
const secondEmpty = intersect([1, 2, 3], []);
156-
assertEquals(firstEmpty, []);
157-
assertEquals(secondEmpty, []);
158-
});
159-
160-
Deno.test("intersect() handles one or more items in intersection", () => {
161-
const one = intersect(["a", "b"], ["b", "c"]);
162-
const two = intersect(["a", "b", "c", "d"], ["c", "d", "e", "f"]);
163-
assertEquals(one, ["b"]);
164-
assertEquals(two, ["c", "d"]);
165-
});
166-
167-
Deno.test("intersect() removes duplicates", () => {
168-
const duplicates = intersect(["a", "b", "c", "b"], ["b", "c"]);
169-
const moreDuplicates = intersect(["a", "b"], ["b", "b", "c", "c"]);
170-
assertEquals(duplicates, ["b", "c"]);
171-
assertEquals(moreDuplicates, ["b"]);
172-
});
173-
174-
Deno.test("intersect() handles more than two inputs", () => {
175-
assertEquals(
176-
intersect(
177-
["a", "b"],
178-
["b", "c"],
179-
["s", "b"],
180-
["b", "b"],
181-
),
182-
["b"],
183-
);
184-
assertEquals(
185-
intersect(
186-
[1],
187-
[1],
188-
[2],
189-
),
190-
[],
191-
);
192-
193-
assertEquals(
194-
intersect(
195-
[true, false],
196-
[true, false],
197-
[true],
198-
),
199-
[true],
200-
);
201-
});
202-
203145
// If you are using sets using {@linkcode Set.prototype.intersection} directly is more efficient.
204146
Deno.test("intersect() handles sets", () => {
205147
const a = new Set([1, 2, 3, 4]);
@@ -233,7 +175,7 @@ Deno.test("intersect() handles iterables with no mutation", () => {
233175
assert(b.has(3));
234176
});
235177

236-
Deno.test("(unstable) intersect() handles generators", () => {
178+
Deno.test("intersect() handles generators", () => {
237179
function* gen() {
238180
yield 1;
239181
yield 2;

collections/without_all.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
/**
55
* Returns an array excluding all given values from an iterable.
66
*
7+
* Note: If both inputs are {@linkcode Set}s, and you want the difference as a
8+
* {@linkcode Set}, you could use {@linkcode Set.prototype.difference} instead.
9+
*
710
* @typeParam T The type of the elements in the iterable.
811
*
912
* @param iterable The iterable to exclude values from.
@@ -12,10 +15,6 @@
1215
* @returns An array containing all elements from iterables except the
1316
* ones that are in the values iterable.
1417
*
15-
* @remarks
16-
* If both inputs are a {@linkcode Set}, and you want the difference as a
17-
* {@linkcode Set}, you could use {@linkcode Set.prototype.difference} instead.
18-
*
1918
* @example Basic usage
2019
* ```ts
2120
* import { withoutAll } from "@std/collections/without-all";

collections/without_all_test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ Deno.test({
6363
},
6464
});
6565

66-
Deno.test("(unstable) withoutAll() handles generators", () => {
66+
Deno.test("withoutAll() handles generators", () => {
6767
function* genInput() {
6868
yield 1;
6969
yield 2;

0 commit comments

Comments
 (0)