-
Notifications
You must be signed in to change notification settings - Fork 18
/
All.ts
83 lines (66 loc) · 2.75 KB
/
All.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
import { asAsync, expectAsync, itAsync, itEnumerable, itParallel } from "./../TestHelpers"
describe("all", () => {
it("String", () => {
expect("aaaa".all(x => x === "a")).toBe(true)
expect("aaab".all(x => x === "a")).toBe(false)
})
it("EmptyString", () => {
expect("".all(x => x === "a")).toBe(true)
})
itEnumerable<{ Age: number, Name: string}>("Basic", (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.all((pet) => pet.Name.startsWith("B"))
expect(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.all((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.all((pet) => pet.Name.startsWith("B"))
expect(allStartWithB).toBe(false)
})
itEnumerable("ManyElements", (asEnumerable) => {
expect(asEnumerable([1, 2, 3]).all((x) => x !== 0)).toBe(true)
expect(asEnumerable([0, 1, 2]).all((x) => x > 5)).toBe(false)
})
itAsync("ManyElements", async () => {
expect(await asAsync([1, 2, 3]).all((x) => x !== 0)).toBe(true)
expect(await asAsync([0, 1, 2]).all((x) => x > 5)).toBe(false)
})
itParallel("ManyElements", async (asParallel) => {
expect(await asParallel([1, 2, 3]).all((x) => x !== 0)).toBe(true)
expect(await asParallel([0, 1, 2]).all((x) => x > 5)).toBe(false)
})
itEnumerable("EmptyElementTrue", (asEnumerable) => {
expect(asEnumerable([]).all((x) => x === 1)).toBe(true)
})
itAsync("EmptyElementTrue", async () => {
const expect = await expectAsync(asAsync([]).all((x) => x === 1))
expect.toBe(true)
})
itParallel("EmptyElementTrue", async (asParallel) => {
const expect = await expectAsync(asParallel([]).all((x) => x === 1))
expect.toBe(true)
})
})