Testing arrays with pseudo-variables

Component Testing for C

Another form of initialization consists of using one or more pseudo-variables, as the following example illustrates:


  FAMILY nominal


    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);



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 C expression.

This lets you create more complicated test scripts in the case of very large arrays, where the use of enumerated expressions is limited.

For multidimensional arrays, you can combine these different types of initialization and test expressions, as the following example shows:

ARRAY image, init = {0 => I2, 1 => { 0 => 100, others => 0 },

& others => (I1 + I2) % 255 }

Related Topics

Testing arraysTesting large arraysTesting arrays with listsTesting character arraysTesting arrays with other arraysTesting an array of union elements