-
Notifications
You must be signed in to change notification settings - Fork 18
/
MinAsync.ts
76 lines (59 loc) · 2.59 KB
/
MinAsync.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
import { InvalidOperationException } from "linq-to-typescript"
import { asAsync, expectAsync, itAsync, itEnumerableAsync, itParallel, randomTimeOut } from "../TestHelpers"
describe("minAsync", () => {
itEnumerableAsync("MinPredicate Empty Error", async (asEnumerable) => {
const expect = await expectAsync(asEnumerable([]).minAsync(async (x) => x * x))
expect.toThrowError(InvalidOperationException)
})
itAsync("MinPredicate Empty Error", async () => {
const expectMin = await expectAsync(asAsync([]).minAsync(async (x) => x * x))
expectMin.toThrowError(InvalidOperationException)
})
itParallel("MinPredicate Empty Error", async (asParallel) => {
const expectMin = await expectAsync(asParallel([]).minAsync(async (x) => x * x))
expectMin.toThrowError(InvalidOperationException)
})
itEnumerableAsync("Min Predicate", async (asEnumerable) => {
const expect = await expectAsync(asEnumerable([1, 2, 3, -7]).minAsync(async (x) => Math.abs(x)))
expect.toBe(1)
})
itAsync("Min Predicate", async () => {
const expectMin = await expectAsync(asAsync([1, 2, 3, -7]).minAsync(async (x) => Math.abs(x)))
expectMin.toBe(1)
})
itParallel("Min Predicate", async (asParallel) => {
const expectMin = await expectAsync(asParallel([1, 2, 3, -7]).minAsync(async (x) => Math.abs(x)))
expectMin.toBe(1)
})
//#region Infinity Test
itEnumerableAsync("Infinity Test", async (asEnumerable) => {
const min = await asEnumerable([ Number.POSITIVE_INFINITY ])
.minAsync(async (x) => x)
expect(min).toBe(Number.POSITIVE_INFINITY)
})
itAsync("Infinity Test", async () => {
const min2 = await asAsync([ Number.POSITIVE_INFINITY ])
.minAsync(async (x) => x)
expect(min2).toBe(Number.POSITIVE_INFINITY)
})
itParallel("Infinity Test", async (asParallel) => {
const min = await asParallel([ Number.POSITIVE_INFINITY ])
.minAsync(async (x) => x)
expect(min).toBe(Number.POSITIVE_INFINITY)
})
//#endregion
//#region Zero Array
itEnumerableAsync("Zero Array", async (asEnumerable) => {
const min = await asEnumerable([0, 0]).minAsync(randomTimeOut)
expect(min).toBe(0)
})
itAsync("Zero Array", async () => {
const min = await asAsync([0, 0]).minAsync(randomTimeOut)
expect(min).toBe(0)
})
itParallel("Zero Array", async (asParallel) => {
const min = await asParallel([0, 0]).minAsync(randomTimeOut)
expect(min).toBe(0)
})
//#endregion
})