File tree Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Original file line number Diff line number Diff line change
1
+ package advancedfp
2
+
3
+ object Chatbot extends App {
4
+ val reply : PartialFunction [String , String ] = {
5
+ case " Hi" => " Hello"
6
+ case " Bye" => " Ciao"
7
+ case _ => " I don't understand you"
8
+ }
9
+
10
+ scala.io.Source .stdin.getLines()
11
+ .map(reply)
12
+ .foreach(println)
13
+ }
Original file line number Diff line number Diff line change
1
+ package advancedfp
2
+
3
+ import org .scalatest .funspec .AnyFunSpec
4
+ import org .scalatest .matchers .should .Matchers
5
+
6
+ class ChatbotSpec extends AnyFunSpec with Matchers {
7
+
8
+ describe(" speak" ) {
9
+ it (" should reply 'Hi' when input is 'Hello'" ) {
10
+ val reply = Chatbot .reply(" Hi" )
11
+
12
+ reply should be (" Hello" )
13
+ }
14
+ it (" should reply 'Ciao' when input is 'Bye'" ) {
15
+ val reply = Chatbot .reply(" Bye" )
16
+
17
+ reply should be (" Ciao" )
18
+ }
19
+ it (" should reply 'I don't understand you' when input is anything else" ) {
20
+ val reply = Chatbot .reply(" hahahaha" )
21
+
22
+ reply should be (" I don't understand you" )
23
+ }
24
+ }
25
+ }
You can’t perform that action at this time.
0 commit comments