Testing arrays
Component Testing for Ada
With Component Testing for Ada, you can test arrays in quite the same way as you test variables. In the Ada Test Script Language, this is done with the ARRAY statement.
The ARRAY statement specifies both the test start-up procedure and the post-execution test for simple variables. This instruction uses three parameters:
-
Name of the variable under test: species the name of the array in any of the following ways:
-
-
To test one array element, conform to the Ada syntax: histo(0).
-
To test the entire array without specifying its bounds, the size of the array is deduced by analyzing its declaration. This can only be done for well-defined arrays.
-
To test a part of the array, specify the lower and upper bounds within which the test will be run, separated with two periods (..), as in: histo(1..SIZE_HISTO)
-
-
Initial value of the array: identified by the keyword INIT.
-
Expected value of the array after the procedure has been executed: identified by the keyword EV.
Declare variables under test with the ARRAY statement, followed by the declaration keywords:
-
INIT = for an assignment
-
INIT == for no initialization
-
EV = for a simple test.
It does not matter where the ARRAY instructions are located with respect to the test procedure call since the Ada code generator separates ARRAY instructions into two parts :
-
The array test is initialized with the ELEMENT instruction
-
The actual test against the expected value is done with the END ELEMENT instruction
Testing an Array with Ada Expressions
To initialize and test an array, specify the same value for all the array elements. The following two examples illustrate this simple form.
ARRAY image, init = 0, ev = init
ARRAY histo[1..SIZE_HISTO-1], init = 0, ev = 0
You can use the same expressions for initial and expected values as those used for simple variables (literal values, constants, variables, functions, and Ada operators).
Example
HEADER histo, 1, 1
#with histo; use histo;
BEGIN
SERVICE COMPUTE_HISTO
# x1, x2, y1, y2 : integer;
# histo : T_HISTO;
TEST 1
FAMILY nominal
ELEMENT
VAR x1, init = 0, ev = init
VAR x2, init = SIZE_IMAGE1, ev = init
VAR y1, init = 0, ev = init
VAR y2, init = SIZE_IMAGE1, ev = init
ARRAY image(1..200,1..200), init = 0, ev = init
VAR histo(1), init = 0, ev = SIZE_IMAGE*SIZE_IMAGE
ARRAY histo(1..SIZE_HISTO), init = 0, ev = 0
#compute_histo(x1, y1, x2, y2, histo);
END ELEMENT
END TEST
END SERVICE
Related Topics
Testing variables | Testing an array with pseudo-variables | Testing character arrays | Testing large arrays | Testing arrays with lists | Testing arrays with other arrays