/
Range.ts
40 lines (31 loc) · 1.46 KB
/
Range.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
import { ArgumentOutOfRangeException, range, rangeAsync, rangeParallel } from "linq-to-typescript"
import { itAsync, itEnumerable, itParallel } from "../../TestHelpers"
describe("range", () => {
itEnumerable("1 to 10", () => {
const oneToTen = range(1, 10).toArray()
expect(oneToTen).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
})
itAsync("1 to 10", async () => {
const oneToTen = await rangeAsync(1, 10).toArray()
expect(oneToTen).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
})
itParallel("1 to 10", async () => {
const oneToTen = await rangeParallel(1, 10).toArray()
expect(oneToTen).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
})
itEnumerable("Invalid Input Throws", () => {
expect(() => range(-1, 99)).toThrowError(ArgumentOutOfRangeException)
expect(() => range(Number.MAX_SAFE_INTEGER - 10, 99))
.toThrowError(ArgumentOutOfRangeException)
})
itAsync("Invalid Input Throws", async () => {
expect(() => rangeAsync(-1, 99)).toThrowError(ArgumentOutOfRangeException)
expect(() => rangeAsync(Number.MAX_SAFE_INTEGER - 10, 99))
.toThrowError(ArgumentOutOfRangeException)
})
itParallel("Invalid Input Throws", async () => {
expect(() => rangeParallel(-1, 99)).toThrowError(ArgumentOutOfRangeException)
expect(() => rangeParallel(Number.MAX_SAFE_INTEGER - 10, 99))
.toThrowError(ArgumentOutOfRangeException)
})
})