File tree 1 file changed +5
-3
lines changed
1 file changed +5
-3
lines changed Original file line number Diff line number Diff line change @@ -56,10 +56,12 @@ def sumRoots(xs: List[String]) = // inferred: Result[Double, String]
56
56
57
57
def resultTest () =
58
58
println(" resultTest" )
59
+ def assertFail (value : Any , s : String ) = value match
60
+ case Err (msg : String ) => assert(msg.contains(s))
59
61
assert(sumRoots(List (" 1" , " 4" , " 9" )) == Ok (6 ))
60
- assert (sumRoots(List (" 1" , " -2" , " 4" )) == Err ( s " cannot take sqrt of negative -2.0 " ) )
61
- assert (sumRoots(List ()) == Err ( " list is empty" ) )
62
- assert (sumRoots(List (" 1" , " 3ab" )) == Err ( " java.lang. NumberFormatException: For input string: \" 3ab \" " ) )
62
+ assertFail (sumRoots(List (" 1" , " -2" , " 4" )), " cannot take sqrt of negative" )
63
+ assertFail (sumRoots(List ()), " list is empty" )
64
+ assertFail (sumRoots(List (" 1" , " 3ab" )), " NumberFormatException" )
63
65
64
66
@ main def Test =
65
67
breakTest()
You can’t perform that action at this time.
0 commit comments