Information Technology Reference
In-Depth Information
(1) int cas_check(char* cas) {
(2)
int count = 0, checksum = 0, checkdigit = 0, pos;
(3)
(4)
for (pos=strlen(cas)-1; pos >= 0; pos--) {
(5)
int digit = cas[pos] - '0';
(6)
(7)
if (digit >= 0 && digit <= 9) {
(8)
if (count == 0)
(9)
checkdigit = digit;
(10)
if (count > 0)
(11)
checksum += count * digit;
(12)
(13)
count ++;
(14)
}
(15)
}
(16)
(17)
if (count >= 4)
(18)
if (count <= 10)
(19)
if (checksum % 10 == checkdigit)
(20)
return 0;
(21)
else return 1;
(22)
else return 2;
(23)
else return 3;
(24) }
Fig. 15. C routine for validating CAS registry numbers of chemical substances (e.g.
'7732-18-5', the CAS number of water), taken from McMinn [66]
Fitness Function. In this case study, each branch is taken as the focus of
a separate test data search, using the fitness function defined by Wegener et
al. [97]. Fitness is computed according to the function fit ( t,
i
)
R
,thattakesa
structural target t and individual input
, and returns a real number that scores
how 'close' the input was to executing the required branch. This assessment
is based on a) the path taken by the input, and b) the values of variables in
predicates at critical points along the path.
The path taken by the input is assessed and used to derive the value of a met-
ric known as the 'approach level'. The approach level is essentially a count of the
target's control dependencies that were not executed by the path. For structured
programs, the approach level reflects the number of unpenetrated levels of nest-
ing levels surrounding the target. Suppose, for example, a string is required for the
execution of the true branch from line 19, i.e. where the string corresponds to a
valid registry number. A diagram charting the computation of fitness can be seen in
Figure 16. The approach level will be 2 if no invalid characters are found in the
string, but there are too few digits in the string to form a valid CAS number, and
the false branch is taken at line 17. If instead the string has too many digits, the true
branch is taken at node 17, but the target is then missed because the false branch
was taken at node 18, and the approach level is 1. When the checksum calculation
is reached at line 19, the approach level is zero.
i
 
Search WWH ::




Custom Search