-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathDistinct.ts
69 lines (50 loc) · 2.24 KB
/
Distinct.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
import { EqualityComparer } from "linq-to-typescript"
import { asAsync, itAsync, itEnumerable, itParallel } from "../TestHelpers"
describe("distinct", () => {
it("String", () => {
expect("foo".distinct().toArray()).toEqual(["f", "o"])
})
itEnumerable("Basic", (asEnumerable) => {
expect(asEnumerable([1, 1]).distinct().toArray()).toEqual([1])
})
itAsync("Basic", async () => {
expect(await asAsync([1, 1]).distinct().toArray()).toEqual([1])
})
itParallel("Basic", async (asParallel) => {
expect(await asParallel([1, 1]).distinct().toArray()).toEqual([1])
})
itEnumerable<string | number>("Distinct", (asEnumerable) => {
const array = asEnumerable(["f", "o", "o"])
expect(array.distinct().toArray()).toEqual(["f", "o"])
})
itAsync("Distinct", async () => {
const array = asAsync(["f", "o", "o"])
expect(await array.distinct().toArray()).toEqual(["f", "o"])
})
itParallel<string>("Distinct", async (asParallel) => {
const array = asParallel(["f", "o", "o"])
expect(await array.distinct().toArray()).toEqual(["f", "o"])
})
itEnumerable<string | number>("DistinctWeakEquality", (asEnumerable) => {
const array = asEnumerable(["1", 1, 2, 2, 3, "3"])
expect(array.distinct(EqualityComparer).toArray()).toEqual(["1", 2, 3])
})
itAsync("DistinctWeakEquality", async () => {
const array = asAsync(["1", 1, 2, 2, 3, "3"])
expect(await array.distinct(EqualityComparer).toArray()).toEqual(["1", 2, 3])
})
itParallel<string | number>("DistinctWeakEquality", async (asParallel) => {
const array = asParallel(["1", 1, 2, 2, 3, "3"])
expect(await array.distinct(EqualityComparer).toArray()).toEqual(["1", 2, 3])
})
itEnumerable("Empty array to remain empty", (asEnumerable) =>
expect(asEnumerable([]).distinct().toArray()).toEqual([]))
itAsync("Empty array to remain empty", async () => {
const value = await asAsync([]).distinct().toArray()
expect(value).toEqual([])
})
itParallel("Empty array to remain empty", async (asParallel) => {
const value = await asParallel([]).distinct().toArray()
expect(value).toEqual([])
})
})