I ran into something strange when doing some data-driven testing in Groovy. If it matters, this is inside a Spock test.
Here is the way, I think, that lists are supposed to work:
def list = [[1, 2, 3],
[4, 5, 6],
[7, 8, 9]]
println list[0]
produces:
[1, 2, 3]
I accidentally did something like this:
def whut = [[1, 2, 3]
[4, 5, 6]
[7, 8, 9]]
println whut[0]
println whut
which outputs:
[null, null, null]
[[null, null, null]]
OK, I can see that Groovy did not like the declaration without the commas - but it compiles, so what is this?
Here's what really throws me about this syntax:
def inputz = [
[1, 0.631226308, 0.631226308, 0.631226308, 1, 0, 0.240426243]
[1, 0.312284518, 0.312284518, 0.312284518, 1, 1, 1 ]
[3, 0.823506476, 0.31230335, 0.631237191, 1, 1, 0 ]
[4, 0.934875788, 0.486395986, 0.66732053, 3, 2, 0.927654169]
[4, 0.699869773, 0.234328294, 0.424739329, 3, 3, 1 ]
]
println inputz[0]
println inputz
yields the following:
[0.631226308, 1, 1, 1, 1, 1, 1]
[[0.631226308, 1, 1, 1, 1, 1, 1]]
I'm completely lost here - what is the Groovy construct I'm creating, and why does it output these seemingly random values from my lists?
Thanks, and if you think of a more descriptive name for my question, I'll change it.