on master help sign in
Update groovy.md
3b21b95Kohányi Róbert
docs/nock/implementations/groovy.md+21−9
@@ -9,6 +9,17 @@ sort: 8
9From [Kohányi Róbert](https://github.com/kohanyirobert/gnock/blob/master/gnock.groovy):
9From [Kohányi Róbert](https://github.com/kohanyirobert/gnock/blob/master/gnock.groovy):
10
10
11```
11```
12+def i(def a) {
13+ a.class in [
14+ byte, Byte,
15+ char, Character,
16+ short, Short,
17+ int, Integer,
18+ long, Long,
19+ BigInteger
20+ ] && a >= 0
21+}
22+
12def n(def a) {
23def n(def a) {
13 if (a in List) {
24 if (a in List) {
14 if (a.size() == 1) {
25 if (a.size() == 1) {
@@ -20,15 +31,15 @@ def n(def a) {
20 } else {
31 } else {
21 throw new IllegalStateException()
32 throw new IllegalStateException()
22 }
33 }
23− } else if (a in Integer && a >= 0) {
34+ } else if (i(a)) {
24− a
35+ (BigInteger) a
25 } else {
36 } else {
26 throw new IllegalStateException()
37 throw new IllegalStateException()
27 }
38 }
28}
39}
29
40
30def wut(def a) {
41def wut(def a) {
31− a in Integer ? 1 : 0
42+ i(a) ? 1 : 0
32}
43}
33
44
34def lus(def a) {
45def lus(def a) {
@@ -50,7 +61,7 @@ def fas(def a) {
50 throw new IllegalStateException()
61 throw new IllegalStateException()
51 }
62 }
52 def h = a[0]
63 def h = a[0]
53− if (!(h in Integer)) {
64+ if (!i(h)) {
54 throw new IllegalStateException()
65 throw new IllegalStateException()
55 }
66 }
56 def t = a[1]
67 def t = a[1]
@@ -59,18 +70,19 @@ def fas(def a) {
59 } else if (h == 1) {
70 } else if (h == 1) {
60 t
71 t
61 } else {
72 } else {
62− if (t in Integer) {
73+ if (i(t)) {
63 throw new IllegalStateException()
74 throw new IllegalStateException()
75+ }
64− } else if (h == 2) {
76+ if (h == 2) {
65 t[0]
77 t[0]
66 } else if (h == 3) {
78 } else if (h == 3) {
67 t[1]
79 t[1]
68 } else {
80 } else {
69− def i = h.intdiv(2)
81+ def x = h.intdiv(2)
70 if (h.mod(2) == 0) {
82 if (h.mod(2) == 0) {
71− fas([2, fas([i, t])])
83+ fas([2, fas([x, t])])
72 } else {
84 } else {
73− fas([3, fas([i, t])])
85+ fas([3, fas([x, t])])
74 }
86 }
75 }
87 }
76 }
88 }