Skip to content

Commit a70967a

Browse files
hellrichjuanpedromoreno
authored andcommitted
minor fixes in Maps (#77)
* minor fixes in Maps * added printed output as comment * additional comment, comment formatting * additional comment * added another list example * Fix foldRight code quote * In foldRightFunctionTraversables explanation, foldRight is not quoted correctly and the rest of phrase is rendered as code. * minor fixes in Maps
1 parent 564dcfe commit a70967a

File tree

2 files changed

+19
-18
lines changed

2 files changed

+19
-18
lines changed

src/main/scala/stdlib/Maps.scala

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ object Maps extends FlatSpec with Matchers with org.scalaexercises.definitions.S
2424
myMap.size should be(res0)
2525
}
2626

27-
/** Maps contain distinct pairings:
27+
/** Maps do not contain multiple identical pairs:
2828
*/
2929
def distinctPairingsMaps(res0: Int) {
3030
val myMap = Map("MI" "Michigan", "OH" "Ohio", "WI" "Wisconsin", "MI" "Michigan")
@@ -50,6 +50,15 @@ object Maps extends FlatSpec with Matchers with org.scalaexercises.definitions.S
5050

5151
val lastElement = mapValues.last
5252
lastElement should be(res2) //Failed presumption: The order in maps is not guaranteed
53+
54+
}
55+
56+
/** Maps may be accessed:
57+
*/
58+
def mayBeAccessedMaps(res0: String, res1: String) {
59+
val myMap = Map("MI" "Michigan", "OH" "Ohio", "WI" "Wisconsin", "IA" "Iowa")
60+
myMap("MI") should be(res0)
61+
myMap("IA") should be(res1)
5362
}
5463

5564
/** Maps insertion with duplicate key updates previous entry with subsequent value:
@@ -70,14 +79,6 @@ object Maps extends FlatSpec with Matchers with org.scalaexercises.definitions.S
7079
myMap(49931) should be(res1)
7180
}
7281

73-
/** Maps may be accessed:
74-
*/
75-
def mayBeAccessedMaps(res0: String, res1: String) {
76-
val myMap = Map("MI" "Michigan", "OH" "Ohio", "WI" "Wisconsin", "IA" "Iowa")
77-
myMap("MI") should be(res0)
78-
myMap("IA") should be(res1)
79-
}
80-
8182
/** If a nonexistent map key is requested using `myMap(missingKey)`, a `NoSuchElementException` will be thrown.
8283
* Default values may be provided using either `getOrElse` or `withDefaultValue` for the entire map:
8384
*/

src/test/scala/stdlib/MapsSpec.scala

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,29 +43,29 @@ class MapsSpec extends Spec with Checkers {
4343
)
4444
}
4545

46-
def `duplicate keys` = {
46+
def `map key access` = {
4747
check(
4848
Test.testSuccess(
49-
Maps.duplicatedKeyInsertionMaps _,
50-
3 :: "Meechigan" :: HNil
49+
Maps.mayBeAccessedMaps _,
50+
"Michigan" :: "Iowa" :: HNil
5151
)
5252
)
5353
}
5454

55-
def `mixed key types` = {
55+
def `duplicate keys` = {
5656
check(
5757
Test.testSuccess(
58-
Maps.mixedTypeKeysMaps _,
59-
"MI" :: "MI" :: HNil
58+
Maps.duplicatedKeyInsertionMaps _,
59+
3 :: "Meechigan" :: HNil
6060
)
6161
)
6262
}
6363

64-
def `map key access` = {
64+
def `mixed key types` = {
6565
check(
6666
Test.testSuccess(
67-
Maps.mayBeAccessedMaps _,
68-
"Michigan" :: "Iowa" :: HNil
67+
Maps.mixedTypeKeysMaps _,
68+
"MI" :: "MI" :: HNil
6969
)
7070
)
7171
}

0 commit comments

Comments
 (0)