Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Copyright (C) 2007-2017, GoodData(R) Corporation. All rights reserved.
- */
- @Grab("org.spockframework:spock-core")
- import spock.lang.*
- @Unroll
- class ExampleSpec extends Specification {
- def "should throw"() {
- when: roman(-1)
- then: thrown(IllegalArgumentException)
- }
- def "roman number for #a is #r"() {
- expect:
- roman(a) == r
- where:
- a || r
- 0 || ""
- 1 || "I"
- 4 || "IV"
- 10 || "X"
- }
- String roman(int arabic) {
- if(arabic < 0) throw new IllegalArgumentException("no negative numbers")
- if(arabic == 0) return ""
- if(arabic == 1) return "I"
- def conversion = [2: "II", 3: "III", 4: "IV"]
- conversion.get(arabic) ?: "X"
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement