Testing arrays with pseudo-variables
Component Testing for Ada
Another form of initialization consists of using one or more pseudo-variables, as the following example illustrates:
TEST 3
FAMILY nominal
ELEMENT
VAR x1, init = 0, ev = init
VAR x2, init = SIZE_IMAGE-1, ev = init
VAR y1, init = 0, ev = init
VAR y2, init = SIZE_IMAGE-1, ev = init
ARRAY image, init=(int)(100*(1+sin((float)(I1+I2)))), ev = init
ARRAY histo[0..200], init = 0, ev ==
ARRAY histo[201..SIZE_HISTO-1], init = 0, ev = 0
VAR status, init ==, ev = 0
#status = compute_histo(x1, y1, x2, y2, histo);
END ELEMENT
END TEST
I1 and I2 are two pseudo-variables which take as their value the current values of the array indices (for image, from 0 to 199 for I1 and I2). You can use these pseudo-variables like a standard variable in any Ada expression.
This allows you to create more complex test scripts when using large arrays when the use of enumerated expressions is limited.
For multidimensional arrays, you can combine these different types of initialization and test expressions, as demonstrated in the following example:
ARRAY image, init = (0 => I2, 1 => ( 0 => 100, others => 0 ),
& others => (I1 + I2) % 255 )
Related Topics
Testing variables | Testing arrays | Testing character arrays | Testing large arrays | Testing arrays with lists | Testing arrays with other arrays