Branch Coverage

10.2.2 Branch Coverage

The criterion of branch coverage provides that we generate test data so that for each branch in the control structure of the candidate program (whether it arises in an if-then statement, an if-then-else statement, or a while statement), the program proceeds through each of the True branch and the False branch at least once. As an illustration of this criterion, we consider the following program:

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

float eps = 0.000001; /* state variables */

10.2 CONTROL FLOW COVERAGE 205 float x, y, z;

/* functions */ Bool tri(float x, float y, float z); bool equal(float a, float b); bool equi(float x, float y, float z); bool iso(float x, float y, float z); bool right(float x, float y, float z); 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;} else {if (equi(x,y,z))

{cout << “equilateral” << endl;} else if (iso(x,y,z)) {if (right(x,y,z)) {cout << “isoceles right” << endl;}

else {cout << “isoceles” <<endl;} else {if (right(x,y,z)) {cout << “right” << endl;} else {cout << “scalene” << endl;}}}} bool tri (float x, float y, float z)

{return ((x<=y+z) && (y<=x+z) && (z<=x+y));} bool equal (float a, float b) {return abs(a-b)<eps;} bool equi(float x, float y, float z) {return (equal(x,y) && equal(y,z));} bool iso(float x, float y, float z) {return (equal(x,y) || equal(y,z) || equal(x,z));} bool right(float x, float y, float z)

{return (equal(x*x+y*y,z*z) || equal(x*x+z*z,y*y) ||

equal(y*y+z*z,x*x));}

The following set of paths allows us to traverse every branch at least once:

• p1: cout << “enter the triangle sides on one line” << endl; cin >> x >> y >> z;

((!tri(x,y,z))? True) {cout << “not a triangle” << endl;} • p2: cout << “enter the triangle sides on one line” << endl;

cin >> x >> y >> z; ((!tri(x,y,z))? False);((equi(x,y,z))? True) {cout << “equilateral” << endl;}

206 STRUCTURAL CRITERIA

• p3: cout << “enter the triangle sides on one line” << endl; cin >> x >> y >> z;

((!tri(x,y,z))? False); ((equi(x,y,z))? False); ((iso(x,y,z))? True); ((right(x,y,z))? True);

{cout << “isoceles right” << endl;} • p4: cout << “enter the triangle sides on one line” << endl;

cin >> x >> y >> z; ((!tri(x,y,z))? False); ((equi(x,y,z))? False); ((iso(x,y,z))? True); ((right(x,y,z))? False);

{cout << “isoceles” << endl;} • p5: cout << “enter the triangle sides on one line” << endl;

cin >> x >> y >> z; ((!tri(x,y,z))? False); ((equi(x,y,z))? False);

((iso(x,y,z))? False); ((right(x,y,z))? True); {cout << “right” << endl;}

• p6: cout << “enter the triangle sides on one line” << endl; cin >> x >> y >> z;

((!tri(x,y,z))? False); ((equi(x,y,z))? False); ((iso(x,y,z))? False); ((right(x,y,z))? False);

{cout << “scalene” << endl;}

A brief inspection of the paths presented above enables us to check that each condition appears at least once with the outcome True and once with the outcome False. In the following table, we list the paths, along with their path conditions and a test vector that satisfies the path condition.

Path Path condition Test vector p1

((!tri(x,y,z))? True)

p2 ((!tri(x,y,z))? False); ((equi(x,y,z))? True)

p3 ((!tri(x,y,z))? False); ((equi(x,y,z))? False);

((iso(x,y,z))? True); ((right(x,y,z))? True); p4

((!tri(x,y,z))? False); ((equi(x,y,z))? False);

((iso(x,y,z))? True); ((right(x,y,z))? False); p5

((!tri(x,y,z))? False); ((equi(x,y,z))? False);

((iso(x,y,z))? False); ((right(x,y,z))? True); p6

((!tri(x,y,z))? False); ((equi(x,y,z))? False);

((iso(x,y,z))? False); ((right(x,y,z))? False);

10.2 CONTROL FLOW COVERAGE 207

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