Condition Coverage

10.2.3 Condition Coverage

A variation of the previous criterion can be applied for programs that have compound conditions and it provides for generating test data to let each term of any condition (rather than the condition as a whole) take both truth values, true and false. So that if the condition has the form

a b,

it is not enough to let the condition be true then false, but we want to ensure that each individual term takes both truth values through the test. To generate test data accord- ing to this criterion, we proceed as follows:

For each term, say a, of each condition of the program, say C, choose a path in the program that starts at the beginning of the program and ends at C; let P be the function of this path. Then generate:

• A state in dom(P /a ) and •

A state in dom(P /−a ).

As an illustration, we consider the following triangle program, which we modify specifically to create compound conditions.

#include <iostream> #include <cmath> using namespace std; /* constants

float eps = 0.000001; /* state variables */ float x, y, z; /* functions */ bool tri(float x, float y, float z);

// triangle bool equal(float a, float b);

// equal, within eps bool equi(float x, float y, float z);

// equilateral bool iso(float x, float y, float z);

// isoceles bool right(float x, float y, float z); // right triangle int main () {cout << “enter the triangle sides on one line” << endl;

cin >> x >> y >> z; if (!tri(x,y,z)) {cout << “not a triangle” << endl;} if (tri(x,y,z) && equi(x,y,z)) {cout << “equilateral”

<< endl;} if (tri(x,y,z) && (!equi(x,y,z)) && iso(x,y,z) && (!right(x,y,z))) {cout << “isoceles” << endl;}

if (tri(x,y,z) && (!equi(x,y,z)) && (!iso(x,y,z)) && right(x,y,z))

208 STRUCTURAL CRITERIA

{cout << “right” << endl;} if (tri(x,y,z) && (!equi(x,y,z)) && iso(x,y,z) && right(x,y,z)) {cout << “isoceles right” << endl;} if (tri(x,y,z) && (!equi(x,y,z)) && (!iso(x,y,z)) && (!right(x,y,z))) {cout << “scalene” << endl;}}

We can simplify this program by referring to the following identities: • An equilateral triangle is isosceles; hence a non-isosceles triangle is not equilateral.

A triplet (x, y, z) that satisfies right(x, y, z) necessarily satisfies tri(x, y, z). •

A triplet (x, y, z) that satisfies equi(x, y, z) necessarily satisfiestri(x, y, z). We find:

int main () {cout << “enter the triangle sides on one line” << endl; cin >> x >> y >> z; if (!tri(x,y,z)) {cout << “not a triangle” << endl;} if (equi(x,y,z)) {cout << “equilateral” << endl;} if (tri(x,y,z) && (!equi(x,y,z)) && iso(x,y,z) &&

(!right(x,y,z))) {cout << “isoceles” << endl;}

if ((!iso(x,y,z)) && right(x,y,z)) {cout << “right” << endl;} if ((!equi(x,y,z)) && iso(x,y,z) && right(x,y,z))

{cout << “isoceles right” << endl;} if (tri(x,y,z) && (!iso(x,y,z)) && (!right(x,y,z))) {cout << “scalene” << endl;}}

In this particular example, all the if-statements refer to the same values of variables x, y, and z. Indeed, though they are written sequentially, the if-statements are merely printing messages to the output stream and are not altering the program variables that are invoked in the conditions. A cursory inspection of the structure of the conditions reveals that the criterion of condition coverage is satisfied if we generated test data to ensure that each elementary function call returns both truth values, in turn. The following table shows sample test data that satisfies this criterion.

False tri(x,y,z)

equi(x,y,z)

iso(x,y,z)

right(x,y,z)

Note that the data generated to make iso(x, y, z) true does not define a triangle, nor does it have to—it only has to make iso(x, y, z) true; such data will cause the program

10.2 CONTROL FLOW COVERAGE 209

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