Execution Paths

10.1.1 Execution Paths

Now that we are interested in structural test data generation, we need to look at programs rather than specifications. We assume that our programs are written in a traditional C-like programming language, which includes the following statements:

• Variable declarations, of the form <data type><variable name>. • Labeled statements, of the form <label>: <statement>. • Assignment statements, of the form <variable name> = <expression>. • Sequence statements, of the form <statement1> ; <statement2>. • Conditional statements, of the form if <condition><statement>. • Alternation statements, of the form if <condition><statement1> else

.

• Iteration statements, of the form while <condition><statement>. • Statement blocks, of the form {<statement>}. • Function calls, of the form <function name> ( <parameter list> ).

Because we use structured constructs exclusively, any program is executed in sequence from the first statement to the last statement (we have no exits or return statements in the middle of a program). Hence all executions of our programs start from the first statement and proceed through the code according to the outcome of the various conditions that appear therein. Hence the following definitions.

An elementary statement is any one of the following • An assignment statement

• A function call •

A condition test of the form

○ ( <condition> ? true ) ○ ( <condition> ? false )

A path through a program is a sequence of elementary statements separated by semicolons such that whenever two elementary statements <es1> and <es2> follow each other in the path, then one of the following conditions holds:

• <es1> and <es2> follow each other in the program, or • <es2> is derived from the condition of a conditional statement or an alternative

statement or an iterative statement which follows <es1> in the program, or

10.1 PATHS AND PATH CONDITIONS 195

• <es1> is the last elementary statement of a conditional statement or an alternative statement that precedes <es2> in the program, or • <es1> is derived from the condition of an iterative statement that precedes <es2> in the program. • <es1> has the form (c? true), where c is the condition of a conditional statement or an alternative statement, and <es2> is the first statement of the then-branch, or • <es1> has the form (c? false), where c is the condition of an alternative statement and (es2> is the first statement of the else branch, or • <es1> has the form (c? true), where c is the condition of an iterative statement and <es2> is the first statement of the loop body.

As an application, we consider the following program and write some of its paths. Note that the definition of paths does not stipulate that they start from the beginning of the programs nor that they end with its last statement, as we want to have the liberty to define partial paths through the code. Nevertheless the sample paths we show below start at the first statement of the program and end at its last statement.

Program g:

{int x; int y; read(x); read(y); // assuming x>0, y>0 while (x!=y) {if (x>y) {x=x-y;} else {y=y-x;}}; write(x);}

Sample paths through this program include the following:

• p0: int x; int y; read(x); read(y); ((x!=y)? false); write(x);

• p1: int x; int y; read(x); read(y); ((x!=y)? true); ((x>y)? true); x=x-y;

((x!=y)? false); write(x); • p2: int x; int y; read(x); read(y);

((x!=y)? true); ((x>y)? false); y=y-x; ((x!=y)? false); write(x);

• p3: int x; int y; read(x); read(y); ((x!=y)? true); ((x>y)? true); x=x-y; ((x!=y)? true); ((x>y)? true); x=x-y;

((x!=y)? false); write(x);

196 STRUCTURAL CRITERIA

• p4: int x; int y; read(x); read(y);

((x!=y)? true); ((x>y)? false); y=y-x; ((x!=y)? true); ((x>y)? false); y=y-x; ((x!=y)? false); write(x);

• p5: int x; int y; read(x); read(y); ((x!=y)? true); ((x>y)? true); x=x-y;

((x!=y)? true); ((x>y)? false); y=y-x; ((x!=y)? false); write(x);

• p6: int x; int y; read(x); read(y);

((x!=y)? true); ((x>y)? false); y=y-x; ((x!=y)? true); ((x>y)? true); x=x-y; ((x!=y)? false); write(x);

• p7: int x; int y; read(x); read(y); ((x!=y)? true); ((x>y)? true); x=x-y;

((x!=y)? true); ((x>y)? false); y=y-x; ((x!=y)? true); ((x>y)? true); x=x-y; ((x!=y)? false); write(x);

• p8: int x; int y; read(x); read(y);

((x!=y)? true); ((x>y)? false); y=y-x; ((x!=y)? true); ((x>y)? true); x=x-y; ((x!=y)? true); ((x>y)? false); y=y-x;

((x!=y)? false); write(x);

and so on. Each path represents a trace of execution through the original program.

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