Skip to content

Instantly share code, notes, and snippets.

@ciis0
Created July 15, 2018 11:11
Show Gist options
  • Save ciis0/264676760cb5128710e271f81ab822a3 to your computer and use it in GitHub Desktop.
Save ciis0/264676760cb5128710e271f81ab822a3 to your computer and use it in GitHub Desktop.
/*
0 x..-1
1 0..x
*/
def test(index, myindex){
ary = [
/*0*/ 7, /*1*/ 8, /*2*/ 9,
/*3*/ 17, /*4*/ 18, /*5*/ 19]
println "$index $myindex"
start = 0 + myindex * ( 1 - index);
end = -1 + ( ( myindex + 1 ) * index**2 );
println "$start $end"
ary[start..end]
}
[
// starts
[ [0, 0] /* 0 ..-1 */, [7,8,9,17,18,19] ],
[ [0, 1] /* 1 ..-1 */, [ 8,9,17,18,19] ],
// ends
[ [1, 3] /* 0 .. 3 */, [7,8,9,17 ] ],
[ [1, 5] /* 0 .. 5 */, [7,8,9,17,18,19] ],
].each { args, expc ->
def act = test(args[0], args[1])
assert(expc == act)
println act
}
null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment