deno.land / std@0.166.0 / collections / take_while_test.ts

take_while_test.ts
نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
import { assertEquals } from "../testing/asserts.ts";import { takeWhile } from "./take_while.ts";
Deno.test("[collections/takeWhile] Num array", () => { const arr = [1, 2, 3, 4, 5, 6]; const actual = takeWhile(arr, (i) => i !== 4);
assertEquals(actual, [1, 2, 3]);});
Deno.test("[collections/takeWhile] Add two to each num in predicate", () => { const arr = [1, 2, 3, 4, 5, 6]; const actual = takeWhile(arr, (i) => i + 2 !== 6);
assertEquals(actual, [1, 2, 3]);});
Deno.test("[collections/takeWhile] Negatives", () => { const arr = [-1, -2, -3, -4, -5, -6];
const actual = takeWhile(arr, (i) => i > -4); assertEquals(actual, [-1, -2, -3]);});
Deno.test("[collections/takeWhile] No mutation", () => { const arr = [-1, -2, -3, -4, -5, -6];
const actual = takeWhile(arr, (i) => i > -4); assertEquals(actual, [-1, -2, -3]); assertEquals(arr, [-1, -2, -3, -4, -5, -6]);});
Deno.test("[collections/takeWhile] Empty input array returns empty array", () => { const arr: number[] = [];
const actual = takeWhile(arr, (i) => i > 4);
assertEquals(actual, []);});
Deno.test("[collections/takeWhile] Returns empty array when the first element doesn't match the predicate", () => { const arr = [1, 2, 3, 4];
const actual = takeWhile(arr, (i) => i !== 1);
assertEquals(actual, []);});
Deno.test("[collections/takeWhile] Returns the same array when all elements match the predicate", () => { const arr = [1, 2, 3, 4];
const actual = takeWhile(arr, (i) => i != 400);
assertEquals(actual, [1, 2, 3, 4]);});
std
Deno standard library
GitHub Repositorydenoland/deno_std
GitHub Stars
2458

Version Info

Tagged at
2 months ago