File tree Expand file tree Collapse file tree 1 file changed +5
-3
lines changed Expand file tree Collapse file tree 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]
5656
5757def resultTest () =
5858 println(" resultTest" )
59+ def assertFail (value : Any , s : String ) = value match
60+ case Err (msg : String ) => assert(msg.contains(s))
5961 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" )
6365
6466@ main def Test =
6567 breakTest()
You can’t perform that action at this time.
0 commit comments