-
Notifications
You must be signed in to change notification settings - Fork 18
/
AllAsync.ts
86 lines (67 loc) · 3.02 KB
/
AllAsync.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
import { asAsync, expectAsync, itAsync, itEnumerableAsync, itParallel } from "./../TestHelpers"
describe("allAsync", () => {
itAsync("String", async () => {
const ans1 = await "abc".allAsync(async x => x !== "d")
expect(ans1).toBe(true)
const ans2 = await "abc".allAsync(async x => x !== "c")
expect(ans2).toBe(false)
})
itEnumerableAsync<{ Age: number, Name: string}>("Basic", async (asEnumerable) => {
// Create an array of Pets.
const pets = asEnumerable([
{ Age: 10, Name: "Barley" },
{ Age: 4, Name: "Boots" },
{ Age: 6, Name: "Whiskers" } ])
// Determine whether all pet names
// in the array start with 'B'.
const allStartWithB = pets.allAsync(async (pet) => pet.Name.startsWith("B"))
expect(await allStartWithB).toBe(false)
})
itAsync("Basic", async () => {
// Create an array of Pets.
const pets = asAsync([
{ Age: 10, Name: "Barley" },
{ Age: 4, Name: "Boots" },
{ Age: 6, Name: "Whiskers" } ])
// Determine whether all pet names
// in the array start with 'B'.
const allStartWithB = await pets.allAsync(async (pet) => pet.Name.startsWith("B"))
expect(allStartWithB).toBe(false)
})
itParallel<{ Age: number, Name: string }>("Basic", async (asParallel) => {
// Create an array of Pets.
const pets = asParallel([
{ Age: 10, Name: "Barley" },
{ Age: 4, Name: "Boots" },
{ Age: 6, Name: "Whiskers" } ])
// Determine whether all pet names
// in the array start with 'B'.
const allStartWithB = await pets.allAsync(async (pet) => pet.Name.startsWith("B"))
expect(allStartWithB).toBe(false)
})
itEnumerableAsync("ManyElements", async (asEnumerable) => {
const allTrue = expect(await asEnumerable([1, 2, 3]).allAsync(async (x) => x !== 0))
allTrue.toBe(true)
const allFalse = expect(await asEnumerable([0, 1, 2]).allAsync(async (x) => x > 5))
allFalse.toBe(false)
})
itAsync("ManyElements", async () => {
expect(await asAsync([1, 2, 3]).allAsync(async (x) => x !== 0)).toBe(true)
expect(await asAsync([0, 1, 2]).allAsync(async (x) => x > 5)).toBe(false)
})
itParallel("ManyElements", async (asParallel) => {
expect(await asParallel([1, 2, 3]).allAsync(async (x) => x !== 0)).toBe(true)
expect(await asParallel([0, 1, 2]).allAsync(async (x) => x > 5)).toBe(false)
})
itEnumerableAsync("EmptyElementTrue", async (asEnumerable) => {
expect(await asEnumerable([]).allAsync(async (x) => x === 1)).toBe(true)
})
itAsync("EmptyElementTrue", async () => {
const expect = await expectAsync(asAsync([]).allAsync(async (x) => x === 1))
expect.toBe(true)
})
itParallel("EmptyElementTrue", async (asParallel) => {
const expect = await expectAsync(asParallel([]).allAsync(async (x) => x === 1))
expect.toBe(true)
})
})