deno.land / x / linq@4.0.2 / test / join.js

نووسراو ببینە
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import { test, testModule, deepEqual } from './testutils.js'import Enumerable from '../linq.js'
testModule("Join");
test("join", function (){ var math = { yamada: 100, tanaka: 80, yoshida: 94 }; var english = { yamada: 73, yoshida: 26, tanaka: 99 }; let actual = Enumerable.from(math) .join(english, "outer=>outer.key", "inner=>inner.key", "o,i=>{Name:o.key,Math:o.value,English:i.value}") .toArray(); let expected = [{ Name: "yamada", Math: 100, English: 73 }, { Name: "tanaka", Math: 80, English: 99 }, { Name: "yoshida", Math: 94, English: 26}]; deepEqual(actual, expected);
actual = Enumerable.from(math) .join(english, "outer=>outer", "inner=>inner", "o,i=>{Name:o.key,Math:o.value,English:i.value}", "$.key") .toArray(); expected = [{ Name: "yamada", Math: 100, English: 73 }, { Name: "tanaka", Math: 80, English: 99 }, { Name: "yoshida", Math: 94, English: 26}]; deepEqual(actual, expected);
actual = Enumerable.from(math) .join(english, "outer=>outer.key", "inner=>inner.key", "(o,i)=>{return {Name:o.key, Math:o.value, English:i.value}}") .toArray();
expected = [{ Name: "yamada", Math: 100, English: 73 }, { Name: "tanaka", Math: 80, English: 99 }, { Name: "yoshida", Math: 94, English: 26}];
deepEqual(actual, expected);
actual = Enumerable.from(math) .join(english, "outer=>outer.key", "inner=>inner.key", "(o,i)=>{returnVal: o.key}") .toArray();
expected = [{ returnVal: "yamada" }, { returnVal: "tanaka" }, { returnVal: "yoshida"}];
deepEqual(actual, expected);});
test("groupJoin", function (){ var array1 = [3, 3, 4, 5, 6]; var array2 = [2, 4, 5, 6, 6]; let actual = Enumerable.from(array1) .groupJoin(array2, " i => i", " i => i", function (outer, collection) { return { outer: outer, collection: collection.toArray() } }) .toArray(); let expected = [{ outer: 3, collection: [] }, { outer: 3, collection: [] }, { outer: 4, collection: [4] }, { outer: 5, collection: [5] }, { outer: 6, collection: [6, 6]}]; deepEqual(actual, expected);
actual = Enumerable.from(array1) .groupJoin(array2, " i => i", " i => i", function (outer, collection) { return { outer: outer, collection: collection.toArray() } }, function (key) { return key % 2 == 0; }) .toArray(); expected = [{ outer: 3, collection: [5] }, { outer: 3, collection: [5] }, { outer: 4, collection: [2, 4, 6, 6] }, { outer: 5, collection: [5] }, { outer: 6, collection: [2, 4, 6, 6]}]; deepEqual(actual, expected);});
test("leftJoin", function (){ var math = { yamada: 100, tanaka: 80, yoshida: 94 }; var english = { yamada: 73, tanaka: 99 }; let actual = Enumerable.from(math) .leftJoin(english, "outer=>outer.key", "inner=>inner.key", (o,i) => ({Name:o.key,Math:o.value,English:i == null ? null : i.value})) .toArray(); let expected = [{ Name: "yamada", Math: 100, English: 73 }, { Name: "tanaka", Math: 80, English: 99 }, { Name: "yoshida", Math: 94, English: null}]; deepEqual(actual, expected);
actual = Enumerable.from(math) .leftJoin(english, "outer=>outer", "inner=>inner", (o,i) => ({Name:o.key,Math:o.value,English:i == null ? null : i.value}), "$.key") .toArray(); expected = [{ Name: "yamada", Math: 100, English: 73 }, { Name: "tanaka", Math: 80, English: 99 }, { Name: "yoshida", Math: 94, English: null}]; deepEqual(actual, expected);});
linq

Version Info

Tagged at
7 months ago