FAULT PRONENESS

14.1 FAULT PRONENESS

What makes a software product prone to faults is its complexity; hence complexity metrics are adequate measures of fault proneness. Empirical studies routinely show

a significant correlation between complexity metrics and fault density in software pro- ducts. In this section, we present two widely known, routinely used metrics of struc- tural complexity of control structures.

14.1 FAULT PRONENESS 315

14.1.1 Cyclomatic Complexity

In its simplest expression, the cyclomatic complexity of a program reflects the com- plexity of its control structure and is computed by drawing the flowchart (say, F) of the program, then deriving the value of the expression as:

v F = e −n + 2,

where • e is the number of edges in F and

• n is the number of nodes in F. We know from graph theory that if the flowchart is a planar graph (i.e., a graph that

can be drawn on a planar surface without any two edges crossing each other) then v (F) represents the number of regions in F. Also, note that if the flowchart is merely a linear sequence of nodes, then its cyclomatic complexity is 1, regardless of the number of nodes; hence a single statement (corresponding to e = 0 and n = 1) has the same cyclo- matic complexity as a sequence of 100 statements (e = 99 and n = 100). This is con- sistent with our intuitive understanding of complexity as an orthogonal attribute to size: a sequence of 100 statements is longer than a single statement but is not more complex. As an illustration of this metric, we consider the following sample example:

int product (int a, int b) { int c; c=0; while (b!=0)

{if (b%2==0) {b=b/2; a=2*a;} else

{b=b-1; c=c+a;}}

return c; }

The flowchart of this program is given in Figure 14.1. From this flowchart, we compute the number of nodes and edges, and we find:

• e=7, • n=6

whence

vF=3

Exercises 1 and 2 in Section 14.8 explore how this figure is affected after we make the program more complex by additional tests.

316 METRICS FOR SOFTWARE TESTING

int c; c=0;

b!=0

int c; c=0;

b%2==0

b=b/2; a=2*a;

b=b–1; c=c+a;

Figure 14.1 Counting nodes and edges.

14.1.2 Volume

Whereas cyclomatic complexity measures the complexity of a program by consider- ing the density of its control structure, the metric of program volume measures complexity by the amount of intellectual effort that it took to develop the program. We can argue that unlike the cyclomatic complexity, which measures structure inde- pendently of size, program volume captures size along with structural complexity. Specifically, program volume is computed as follows:

• If N is the number of lexemes (operators, operands, symbols, constants, etc.) in a program and • n is the number of distinct lexemes (operators, operands, symbols, constants, etc.) in the program,

then the volume of the program is given by the following formula:

V = N × log 2 n

Interpretation: n is the size of the vocabulary in which the program is written; log 2 (n) measures the number of binary decisions one has to make to select one symbol in a vocabulary of size n; N × log 2 n measures the total development effort of the program, viewed as the selection of N symbols in a vocabulary of size n, and quanti- fied in terms of binary decisions. Alternatively, log 2 (n) can be interpreted as the entropy of the random variable that represents each symbol of the program and N × log 2 n is then the entropy of the whole program (quantity of information contained within its source text). If we consider again the product program given above, we find the following quantities:

14.2 FAULT DETECTABILITY 317

• Number of lexemes, N: 66. • Vocabulary: {int, product, (, a, ‘,’, b, ), {, c, ;, =, 0, while, !=, if, %, 2, ==, /, *, },

else, −, 1, +, return}. Hence n=26. The volume of this program is:

V = 66 × log 2 26 = 310 23 bits

Generating this program requires the equivalent of 310 binary (yes/no) decisions.

Dokumen yang terkait

Analisis Komparasi Internet Financial Local Government Reporting Pada Website Resmi Kabupaten dan Kota di Jawa Timur The Comparison Analysis of Internet Financial Local Government Reporting on Official Website of Regency and City in East Java

19 819 7

ANTARA IDEALISME DAN KENYATAAN: KEBIJAKAN PENDIDIKAN TIONGHOA PERANAKAN DI SURABAYA PADA MASA PENDUDUKAN JEPANG TAHUN 1942-1945 Between Idealism and Reality: Education Policy of Chinese in Surabaya in the Japanese Era at 1942-1945)

1 29 9

Improving the Eighth Year Students' Tense Achievement and Active Participation by Giving Positive Reinforcement at SMPN 1 Silo in the 2013/2014 Academic Year

7 202 3

Improving the VIII-B Students' listening comprehension ability through note taking and partial dictation techniques at SMPN 3 Jember in the 2006/2007 Academic Year -

0 63 87

The Correlation between students vocabulary master and reading comprehension

16 145 49

Improping student's reading comprehension of descriptive text through textual teaching and learning (CTL)

8 140 133

The correlation between listening skill and pronunciation accuracy : a case study in the firt year of smk vocation higt school pupita bangsa ciputat school year 2005-2006

9 128 37

Perancangan Sistem Informasi Akuntansi Laporan Keuangan Arus Kas Pada PT. Tiki Jalur Nugraha Ekakurir Cabang Bandung Dengan Menggunakan Software Microsoft Visual Basic 6.0 Dan SQL Server 2000 Berbasis Client Server

32 174 203

Pengaruh Kualitas Software Aplikasi pengawasan kredit (C-M@X) Pt.PLN (PERSERO) Distribusi Jawa Barat Dan Banten (DJBB) Terhadap Produktivitas Kerja karyawan UPJ Bandung Utara

5 72 130

Transmission of Greek and Arabic Veteri

0 1 22