1
- // scalac: -deprecation
2
- //
3
- // ############################################################################
4
- // Literals
5
- // ############################################################################
6
1
7
- // ############################################################################
2
+ import scala . util .{ Failure , Success , Try }
8
3
9
4
object Test {
10
5
11
- def check_success [A ](name : String , closure : => A , expected : A ): Unit = {
12
- val res : Option [String ] =
13
- try {
14
- val actual : A = closure
15
- if (actual == expected) None // print(" was successful")
16
- else Some (s " failed: expected $expected, found $actual" )
17
- } catch {
18
- case exception : Throwable => Some (s " raised exception $exception" )
19
- }
20
- for (e <- res) println(s " test $name $e" )
21
- }
6
+ def check_success [A ](name : String , closure : => A , expected : A ): Unit =
7
+ Try (closure) match {
8
+ case Success (actual) => assert(actual == expected, s " test $name failed: expected $expected, found $actual" )
9
+ case Failure (error) => throw new AssertionError (s " test $name raised exception $error" )
10
+ }
22
11
23
12
def main (args : Array [String ]): Unit = {
24
13
// char
@@ -83,6 +72,7 @@ object Test {
83
72
check_success(" 01.23f == 1.23f" , 01.23f , 1.23f )
84
73
check_success(" 3.14f == 3.14f" , 3.14f , 3.14f )
85
74
check_success(" 6.022e23f == 6.022e23f" , 6.022e23f , 6.022e23f )
75
+ check_success(" 9f == 9.0f" , 9f , 9.0f )
86
76
check_success(" 09f == 9.0f" , 09f , 9.0f )
87
77
check_success(" 1.00000017881393421514957253748434595763683319091796875001f == 1.0000001f" ,
88
78
1.00000017881393421514957253748434595763683319091796875001f ,
@@ -114,5 +104,3 @@ object Test {
114
104
check_success(" \"\" .length()" , " \u001a " .length(), 1 )
115
105
}
116
106
}
117
-
118
- // ############################################################################
0 commit comments