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
+100
Original file line number
Diff line number
Diff line change
@@ -74,4 +74,104 @@ 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
+
ourChanges -> theirChanges
115
+
116
+
ourChanges.mergeByKey(theirChanges)
117
+
118
+
Assert.assertEquals("Expect all the keys to appear in an outer join.", ourChanges.mergeByKey(theirChanges).keys, allKeys)
119
+
120
+
theirChanges.mergeByKey(ourChanges)
121
+
122
+
Assert.assertEquals("Expect all the keys to appear in an outer join.", theirChanges.mergeByKey(ourChanges).keys, allKeys)
123
+
124
+
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.",
// In this test case, associated values collide across keys...
140
+
141
+
valtheirChangesRedux=Map(
142
+
(
143
+
arthur,
144
+
sharedValue
145
+
),
146
+
(
147
+
sandra,
148
+
sharedValue
149
+
)
150
+
)
151
+
152
+
ourChanges -> theirChangesRedux
153
+
154
+
ourChanges.mergeByKey(theirChangesRedux)
155
+
156
+
Assert.assertEquals("Expect all the keys to appear in an outer join, but they don't.", ourChanges.mergeByKey(theirChangesRedux).keys, allKeys)
157
+
158
+
theirChangesRedux.mergeByKey(ourChanges)
159
+
160
+
Assert.assertEquals("Expect all the keys to appear in an outer join, and they do, good.", theirChangesRedux.mergeByKey(ourChanges).keys, allKeys)
161
+
162
+
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