@@ -1290,5 +1290,75 @@ class OrderedDictionaryTests: CollectionTestCase {
12901290 }
12911291 }
12921292
1293+ func test_uniqueKeysWithValues_initializer_ambiguity( ) {
1294+ // https://github.com/apple/swift-collections/issues/125
1295+
1296+ let names = [ " dylan " , " bob " , " aaron " , " carol " ]
1297+ let expected = names. map { ( key: $0, value: 0 ) }
1298+
1299+ let d1 = OrderedDictionary ( uniqueKeysWithValues: names. map { ( $0, 0 ) } )
1300+ expectEqualElements ( d1, expected)
1301+
1302+ let d2 = OrderedDictionary (
1303+ uniqueKeysWithValues: [ " dylan " , " bob " , " aaron " , " carol " ] . map { ( $0, 0 ) } )
1304+ expectEqualElements ( d2, expected)
1305+
1306+ let d3 = OrderedDictionary (
1307+ uniqueKeysWithValues: names. map { ( key: $0, value: 0 ) } )
1308+ expectEqualElements ( d3, expected)
1309+
1310+ let d4 = OrderedDictionary (
1311+ uniqueKeysWithValues: [ " dylan " , " bob " , " aaron " , " carol " ] . map { ( key: $0, value: 0 ) } )
1312+ expectEqualElements ( d4, expected)
1313+ }
1314+
1315+ func test_uniquingKeysWith_initializer_ambiguity( ) {
1316+ // https://github.com/apple/swift-collections/issues/125
1317+ let d1 = OrderedDictionary (
1318+ [ " a " , " b " , " a " ] . map { ( $0, 1 ) } ,
1319+ uniquingKeysWith: + )
1320+ expectEqualElements ( d1, [ " a " : 2 , " b " : 1 ] as KeyValuePairs )
1321+
1322+ let d2 = OrderedDictionary (
1323+ [ " a " , " b " , " a " ] . map { ( key: $0, value: 1 ) } ,
1324+ uniquingKeysWith: + )
1325+ expectEqualElements ( d2, [ " a " : 2 , " b " : 1 ] as KeyValuePairs )
1326+ }
1327+
1328+ func test_merge_ambiguity( ) {
1329+ // https://github.com/apple/swift-collections/issues/125
1330+
1331+ var d1 : OrderedDictionary = [ " a " : 1 , " b " : 2 ]
1332+ d1. merge (
1333+ [ " c " , " a " ] . map { ( $0, 1 ) } ,
1334+ uniquingKeysWith: +
1335+ )
1336+ expectEqualElements ( d1, [ " a " : 2 , " b " : 2 , " c " : 1 ] as KeyValuePairs )
1337+
1338+ var d2 : OrderedDictionary = [ " a " : 1 , " b " : 2 ]
1339+ d2. merge (
1340+ [ " c " , " a " ] . map { ( key: $0, value: 1 ) } ,
1341+ uniquingKeysWith: +
1342+ )
1343+ expectEqualElements ( d2, [ " a " : 2 , " b " : 2 , " c " : 1 ] as KeyValuePairs )
1344+ }
1345+
1346+ func test_merging_ambiguity( ) {
1347+ // https://github.com/apple/swift-collections/issues/125
1348+
1349+ let d1 : OrderedDictionary = [ " a " : 1 , " b " : 2 ]
1350+ let d1m = d1. merging (
1351+ [ " c " , " a " ] . map { ( $0, 1 ) } ,
1352+ uniquingKeysWith: +
1353+ )
1354+ expectEqualElements ( d1m, [ " a " : 2 , " b " : 2 , " c " : 1 ] as KeyValuePairs )
1355+
1356+ let d2 : OrderedDictionary = [ " a " : 1 , " b " : 2 ]
1357+ let d2m = d2. merging (
1358+ [ " c " , " a " ] . map { ( key: $0, value: 1 ) } ,
1359+ uniquingKeysWith: +
1360+ )
1361+ expectEqualElements ( d2m, [ " a " : 2 , " b " : 2 , " c " : 1 ] as KeyValuePairs )
1362+ }
12931363}
12941364
0 commit comments