Advertisement
Guest User

Untitled

a guest
Jan 24th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. /*
  2. * Copyright (C) 2007-2017, GoodData(R) Corporation. All rights reserved.
  3. */
  4. @Grab("org.spockframework:spock-core")
  5. import spock.lang.*
  6.  
  7. @Unroll
  8. class ExampleSpec extends Specification {
  9. def "should throw"() {
  10. when: roman(-1)
  11. then: thrown(IllegalArgumentException)
  12. }
  13.  
  14. def "roman number for #a is #r"() {
  15. expect:
  16. roman(a) == r
  17.  
  18. where:
  19. a || r
  20. 0 || ""
  21. 1 || "I"
  22. 4 || "IV"
  23. 10 || "X"
  24. }
  25.  
  26. String roman(int arabic) {
  27. if(arabic < 0) throw new IllegalArgumentException("no negative numbers")
  28. if(arabic == 0) return ""
  29. if(arabic == 1) return "I"
  30.  
  31. def conversion = [2: "II", 3: "III", 4: "IV"]
  32.  
  33. conversion.get(arabic) ?: "X"
  34. }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement