groovy test

Groovy (beta) code posted by nikolay.vasiliev
created at 28 Mar 13:37

Edit | Back
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
package groyve
 
def func = {
    switch(it){
        case Integer : return it.doubleValue()
        case Double : return it.intValue()
        case String : return it.split(" ")
        case null : return null
        default : throw new UnsupportedOperationException()
    }
}
assert func(new Integer(6)) == 6.0
assert func(new Double(Math.PI)) == 3
assert func("this is a string") == ['this', 'is', 'a', 'string']
assert func(null) == null
try{
    println func(new Float(5.5))
}catch(Exception ex){
    assert ex.class == UnsupportedOperationException.class
}
582 Bytes in 3 ms with coderay