Skip to content

Commit a561d64

Browse files
author
Chris Myers
committed
Merge branch 'master' into answers
Conflicts: src/main/scala/com/rea/typesafety/OptionExercises.scala
2 parents 766afab + e9998cc commit a561d64

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

src/main/scala/com/rea/typesafety/OptionExercises.scala

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,6 @@ package com.rea.typesafety
22

33

44
object OptionalExercises1 {
5-
def main(args: Array[String]) {
6-
println("The host name is: " + getFromConfig("host").getOrElse("Not Found"))
7-
println("The length of host name is: " + lengthOfHost().getOrElse(0))
8-
println("The port plus 1000 is: " + portPlus1000().getOrElse(0) + " (expecting 9080)")
9-
}
10-
115
val config = Map[String, String]("host" -> "rea.com", "port" -> "8080")
126

137
def getFromConfig(key: String): Option[String] = config.get(key)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,29 @@
11
package com.rea.typesafety
22

33
import org.specs2.mutable.Specification
4+
import OptionalExercises1._
45

56
class OptionalExercises1Spec extends Specification {
67

8+
"getting Host Name from config" should {
9+
"be rea.com for host" in {
10+
getFromConfig("host") should beSome("rea.com")
11+
}
12+
"be none for other" in {
13+
getFromConfig("other") should beNone
14+
}
15+
16+
}
17+
18+
"The length of host name" should {
19+
"be 7" in {
20+
lengthOfHost() should beSome(7)
21+
}
22+
}
23+
24+
"The port plus 1000" in {
25+
portPlus1000() should beSome(9080)
26+
}
27+
28+
729
}

0 commit comments

Comments
 (0)