You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/test/scala/scala/collection/decorators/MapDecoratorTest.scala
+88Lines changed: 88 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -74,4 +74,92 @@ class MapDecoratorTest {
74
74
// Assert.assertEquals(expected, zipped2)
75
75
}
76
76
77
+
@Test
78
+
defmergingByKeyPerformsFullOuterJoin():Unit= {
79
+
valarthur="arthur.txt"
80
+
81
+
valtyson="tyson.txt"
82
+
83
+
valsandra="sandra.txt"
84
+
85
+
valallKeys=Set(arthur, tyson, sandra)
86
+
87
+
valsharedValue=1
88
+
89
+
valourChanges=Map(
90
+
(
91
+
arthur,
92
+
sharedValue
93
+
),
94
+
(
95
+
tyson,
96
+
2
97
+
)
98
+
)
99
+
100
+
{
101
+
// In this test case, none of the associated values collide across keys...
102
+
103
+
valtheirChanges=Map(
104
+
(
105
+
arthur,
106
+
sharedValue
107
+
),
108
+
(
109
+
sandra,
110
+
3
111
+
)
112
+
)
113
+
114
+
Assert.assertEquals("Expect the same keys to appear in the join taken either way around.", ourChanges.mergeByKey(theirChanges).keySet, theirChanges
115
+
.mergeByKey(ourChanges)
116
+
.keys)
117
+
118
+
Assert.assertTrue("Expect the same associated values to appear in the join taken either way around, albeit swapped around and not necessarily in the same key order.",
Assert.assertEquals("Expect all the keys to appear in an outer join.", ourChanges.mergeByKey(theirChanges).keys, allKeys)
128
+
129
+
Assert.assertEquals("Expect all the keys to appear in an outer join.", theirChanges.mergeByKey(ourChanges).keys, allKeys)
130
+
}
131
+
132
+
{
133
+
// In this test case, associated values collide across keys...
134
+
135
+
valtheirChangesRedux=Map(
136
+
(
137
+
arthur,
138
+
sharedValue
139
+
),
140
+
(
141
+
sandra,
142
+
sharedValue
143
+
)
144
+
)
145
+
146
+
Assert.assertEquals("Expect the same keys to appear in the join taken either way around.", ourChanges.mergeByKey(theirChangesRedux).keySet, theirChangesRedux
147
+
.mergeByKey(ourChanges)
148
+
.keys)
149
+
150
+
Assert.assertTrue("Expect the same associated values to appear in the join taken either way around, albeit swapped around and not necessarily in the same key order.",
0 commit comments