forked from arogozine/LinqToTypeScript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Any.ts
111 lines (85 loc) · 3.46 KB
/
Any.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import { asAsync, expectAsync, itAsync, itEnumerable, itParallel } from "./../TestHelpers"
describe("any", () => {
it("String", () => {
expect("".any()).toBe(false)
expect(" ".any()).toBe(true)
})
it("String Predicate", () => {
expect("aaa".any(x => x === "b")).toBe(false)
expect(" ".any(x => x === " ")).toBe(true)
})
itEnumerable("Empty", (asEnumerable) => {
const array = asEnumerable([])
expect(array.any()).toBe(false)
expect(array.any((_) => true)).toBe(false)
expect(array.any((_) => false)).toBe(false)
})
itAsync("Empty", async () => {
const array = asAsync([])
expect(await array.any()).toBe(false)
expect(await array.any((_) => true)).toBe(false)
expect(await array.any((_) => false)).toBe(false)
})
itParallel("Empty", async (asParallel) => {
const array = asParallel([])
expect(await array.any()).toBe(false)
expect(await array.any((_) => true)).toBe(false)
expect(await array.any((_) => false)).toBe(false)
})
itEnumerable("AnyExists", (asEnumerable) => {
const array = asEnumerable([1, 2])
expect(array.any()).toBe(true)
expect(array.any((_) => true)).toBe(true)
expect(array.any((_) => false)).toBe(false)
expect(array.any((x) => x === 1)).toBe(true)
expect(array.any((x) => x === 2)).toBe(true)
})
itAsync("AnyExists", async () => {
const array = asAsync([1, 2])
expect(await array.any()).toBe(true)
expect(await array.any((_) => true)).toBe(true)
expect(await array.any((_) => false)).toBe(false)
expect(await array.any((x) => x === 1)).toBe(true)
expect(await array.any((x) => x === 2)).toBe(true)
})
itParallel("AnyExists", async (asParallel) => {
const array = asParallel([1, 2])
expect(await array.any()).toBe(true)
expect(await array.any((_) => true)).toBe(true)
expect(await array.any((_) => false)).toBe(false)
expect(await array.any((x) => x === 1)).toBe(true)
expect(await array.any((x) => x === 2)).toBe(true)
})
itEnumerable("basic", (asEnumerable) => {
expect(asEnumerable([1]).any()).toBe(true)
})
itAsync("basic", async () => {
expect(await asAsync([1]).any()).toBe(true)
})
itParallel("basic", async (asParallel) => {
expect(await asParallel([1]).any()).toBe(true)
})
itEnumerable("EmptyPredicate", (asEnumerable) => {
expect(asEnumerable([]).any((x) => x === 0)).toBe(false)
})
itAsync("EmptyPredicate", async () => {
const expect = await expectAsync(asAsync([]).any((x) => x === 0))
expect.toBe(false)
})
itParallel("EmptyPredicate", async (asParallel) => {
const expect = await expectAsync(asParallel([]).any((x) => x === 0))
expect.toBe(false)
})
itEnumerable("BasicPredicate", (asEnumerable) => {
expect(asEnumerable([1]).any((x) => x === 1)).toBe(true)
expect(asEnumerable([1]).any((x) => x === 0)).toBe(false)
})
itAsync("BasicPredicate", async () => {
expect(await asAsync([1]).any((x) => x === 1)).toBe(true)
expect(await asAsync([1]).any((x) => x === 0)).toBe(false)
})
itParallel("BasicPredicate", async (asParallel) => {
expect(await asParallel([1]).any((x) => x === 1)).toBe(true)
expect(await asParallel([1]).any((x) => x === 0)).toBe(false)
})
})