You are on page 1of 21

Assignment Cover Sheet

• The information on this coversheet will be included in Turnitin’s similarity analysis; however, your lecturers are
aware of this and will disregard it.

Student Details

Student Number 1 0 4 4 9 3 1 4

Family Name PERERA Given Name BERNEDETTE

Unit Details

Unit Code CSI3105 Unit Title SOFTWARE TESTING

Name of Lecturer PROFESSOR C.PENG LAM Due Date 09 / MAY / 2018

STRUCTURAL TESTING Group or Tutorial INDIVIDUAL


Topic of Assignment
(if applicable)
ACBT
Course COMPUTER SCIENCE Campus COLOMBO
I certify that the attached assignment is my own work and that any material drawn from other sources has been
acknowledged. This work has not previously been submitted for assessment in any other unit or course.
Copyright in assignments remains my property. I grant permission to the University to make copies of assignments
for assessment, review and/or record keeping purposes. I note that the University reserves the right to check my
assignment for plagiarism. Should the reproduction of all or part of an assignment be required by the University for
any purpose other than those mentioned above, appropriate authorisation will be sought from me on the relevant
form.

Manual Submission
If handing in an assignment in a paper or other physical form, sign here to indicate that you have read this form, filled it in
completely and that you certify as above.

Signature Date Office Use Only

Electronic Submission

OR, if submitting this paper electronically as per instructions for the unit, place an ‘X’ in the box below to
indicate that you have read this form and filled it in completely and that you certify as above. Please
include this page with your submission. Any responses to this submission will be sent to your ECU
email address.
21/May/2018
Agreement  select check box Date

For procedures and penalties on late assignments please refer to the University Admission, Enrolment and Academic Progress
Rules - rule 24, and the ECU Course and Unit Delivery and Assessment Policy

The information on this coversheet will be included in Turnitin’s similarity analysis; however, your lecturers
are aware of this and will disregard it.
The ECU English Language Proficiency Measure (Feb 2014)
Levels of proficiency Low proficiency Developing Moderate proficiency High proficiency
proficiency
Incorrect or inappropriate Aspects of writing are Aspects of writing are
aspects of writing Incorrect or inappropriate mostly accurate. appropriate and
Aspects of writing obscure meaning in aspects of writing Mistakes rarely affect optimally constructed,
(Indicate with an X main area(s) many places. obscure meaning in clarity of meaning. allowing clarity of
needing improvement) some places. Minor editing needed to meaning.
Significant editing needed clarify the meaning, Meaning is clear and
to clarify the meaning, Some editing needed to along with careful needs only a light
along with extensive clarify the meaning, proofreading to correct proofread to correct
proofreading to correct along with extensive technical errors.
proofreading to correct technical errors.
technical errors.
technical errors.
Sentence structure

 1. sentence completeness

 2. sentence length

 3. phrase/clause order

 4. use of conjunctions

 5. word order

 6. punctuation

Word use

 7. word choice

 8. word form

 9. word omission/redundancy

 10. verb tense/agreement

 11. spelling

 12. apostrophes

Sentence Structure Word Use

1. Sentence completeness: sentence includes subject, verb a 7. Word choice: words are correct and appropriate for
complete thought. the context.
2. Sentence length: length is appropriate to context or 8. Word form: correct part of speech is used, e.g., [to]
disciple affect / [the] effect.
9. Word omission/redundancy: words should not be
3. Phrase/clause order: parts of the sentence (phrases and
missing or be unnecessarily repetitive.
clauses) are ordered logically.
10. Verb tense/agreement: correct use of verbs that
4. Use of conjunctions: linking words are used correctly to
indicate time and correct word forms that agree
show the relationship between ideas.
grammatically with other words in the sentence.
5. Word order: words are ordered correctly in a sentence.
11. Spelling: correct spelling is used.
6. Punctuation: the correct use of full stops, commas,
12. Apostrophes: indicate ownership or contraction.
semicolons, colons and capitals.
STRUCTURAL TESTING
Assessment 01

Minor Assessment 02

Student Name: Bernedette Perera


Student Number: 10449314
Unit: CSI3105
CSI3105 SOFTWARE TESTING – Minor 02

Table of Contents
Question 01: Basic block (A - L) within the program .................................................................2
a) List of all the def-use pairs .............................................................................................2
(i) Code: ..........................................................................................................................2
(ii) Def-use pairs: .............................................................................................................2
(iii) Data Flow Chart: ......................................................................................................3
b) Test suite ........................................................................................................................4
(i) All-defs coverage:.......................................................................................................4
(ii) All-uses coverage: ......................................................................................................6
2.1. Test Suite for All-def coverage and All-use coverage ..........................................8
2.1.1. For variable “n”.............................................................................................8
2.1.2. For variable “key” .........................................................................................8
2.1.3. For variable “mid”.........................................................................................9
2.1.4. For variable “low” and “high”.....................................................................11
2.1.5. For variable “found” ...................................................................................11
(iii) All-du-path coverage: ............................................................................................12
3.1. Test Suite for All-du-path coverage ...................................................................14
3.1.1. For variable “low” .......................................................................................14
3.1.2. For variable “high” ......................................................................................14
3.1.3. For variable “found” ...................................................................................15
Question 02: Using the program code .....................................................................................16
(i) Control Flow Graph ..................................................................................................16
(ii) Test suite that achieves branch coverage ...............................................................17
(iii) List of the set of basis path ....................................................................................18
(iv) Test case using the basic path ...............................................................................18

List of Figures
Figure 1: Data Flow Chart ..........................................................................................................3
Figure 2: Control Flow Chart ....................................................................................................16

List of Tables
Table 1: Def-use pairs ................................................................................................................2
Table 2: All-def coverage table ..................................................................................................5
Table 3: All uses coverage table.................................................................................................7
Table 4: All-du-path coverage table.........................................................................................13
Table 5: Branch Coverage Test Suite .......................................................................................17
Table 6: Test case for basis path ..............................................................................................18

10449314 Page |1
CSI3105 SOFTWARE TESTING – Minor 02

Question 01: Basic block (A - L) within the program


a) List of all the def-use pairs

(i) Code:

1. int search(int arr-list[], int n, int key) {


2. int low = 0;
3. int mid;
4. int high = n – 1;
5. int found = -1;
6. while ((high >= low) && (found == -1)) {
7. mid = (low + high) / 2;
8. if (arr-list[mid] == key)
9. found = mid;
10. else if (arr-list[mid] > key)
11. high = mid – 1;
12. else
13. low = mid + 1;
14. }
15. return found;
16. }

(ii) Def-use pairs:


Def-use pair is associated between definition and the use of the variable such as a
C-use (operations) or P-use (conditions) with at least one def-clear path between
them and there could be many. In other words, def-use pairs consist of a definition
(D) of a variable and all the uses of the variable.

Variable Name Definition Line C-use Line P-use Line


arr-list[] 1 - 8, 10
n 1 4 -
key 1 - 8, 10
2 2, 7 6
low
13 13 -
3 7 -
mid
7 9, 11, 13 8, 10
4 4, 7 6
high
11 11 -
5 5 6
found
9 15 -
Table 1: Def-use pairs

10449314 Page |2
CSI3105 SOFTWARE TESTING – Minor 02

(iii) Data Flow Chart:


Assumption: I am assuming that initialization and definitions of variables will be in
one node (node 1) as shown below in figure 01, because in the assignment sheet all
those variables are initialized and defined in one basic block ‘A’.

Figure 1: Data Flow Chart

10449314 Page |3
CSI3105 SOFTWARE TESTING – Minor 02

b) Test suite
Test suite is a collection of test cases that is intended to test specified set of behaviors
of a program and also known as validation suite. It often contains goal for each
collection of test cases and occasionally test suites are used to group similar test cases
together.
(i) All-defs coverage:
In this criteria, for each variable x has a global definition in a node i, a complete
path should be selected which includes a def-clear path from node i to node j that
has a global c-use (node) of variable x or a p-use (edge) of variable x.

Note: I am assuming the while loop only iterates once when selecting test paths in
data flow testing.

Variable Definition in Global c-use


ID p-use (edge) Path
Name Node (node)
(3,4)
01 1 - (1 – 2 – 3 – 4 – 8 – 2 – 9)
(arr-list[mid] == key)
(3,5), (5,6)
02 arr-list[] 1 - ~(arr-list[mid] == key) (1 – 2 – 3 – 5 – 6 – 8 – 2 – 9)
(arr-list[mid] > key)
- (5,7)
03 1 (1 – 2 – 3 – 5 – 7 – 8 – 2 – 9)
~(arr-list[mid] > key)
1
04 n 1 - (1 – 2 – 9)
high = n - 1
(3,4)
05 1 - (1 – 2 – 3 – 4 – 8 – 2 – 9)
(arr-list[mid] == key)
(3,5), (5,6)
06 key 1 - ~(arr-list[mid] == key) (1 – 2 – 3 – 5 – 6 – 8 – 2 – 9)
(arr-list[mid] > key)
(5,7)
07 1 - (1 – 2 – 3 – 5 – 7 – 8 – 2 – 9)
~(arr-list[mid] > key)
(2,3) (1 – 2 – 3 – 4 – 8 – 2 – 9)
1 3
08 ((high >= low) &&
low = 0 mid = (low + high) / 2
(found == -1))
(1 – 2 – 3 – 5 – 6 – 8 – 2 – 9)
low
(2,9)
1
09 - ~((high >= low) && (1 – 2 – 9)
low = 0
(found == -1))
(2,3) (1 – 2 – 3 – 4 – 8 – 2 – 9)
1 3
10 ((high >= low) &&
high = n - 1 mid = (low + high) / 2
(found == -1))
(1 – 2 – 3 – 5 – 7 – 8 – 2 – 9)
high
(2,9)
1
11 - ~((high >= low) && (1 – 2 – 9)
high = n - 1
(found == -1))

10449314 Page |4
CSI3105 SOFTWARE TESTING – Minor 02

(2,9)
1 9
14 ~((high >= low) && (1 – 2 – 9)
found = -1 return found
(found == -1))
(2,3) (1 – 2 – 3 – 5 – 6 – 8 – 2 – 9)
1
15 found - ((high >= low) &&
found = -1
(found == -1))
(1 – 2 – 3 – 5 – 7 – 8 – 2 – 9)

(2,9)
4 9
16 ~((high >= low) && (1 – 2 – 3 – 4 – 8 – 2 – 9)
found = mid return found
(found == -1))
(3,4)
(arr-list[mid] == key
3 (1 – 2 – 3 – 4 – 8 – 2 – 9)
17 1
mid = (low + high) / 2
(3,5) (1 – 2 – 3 – 5 – 6 – 8 – 2 – 9)
~(arr-list[mid] == key
(3,5)
3 ~(arr-list[mid] == key)
mid 6
18 mid = (low + high) (1 – 2 – 3 – 5 – 6 – 8 – 2 – 9)
high = mid - 1
/2 (5,6)
(arr-list[mid] > key)
(3,5)
3 ~(arr-list[mid] == key)
7
19 mid = (low + high) (1 – 2 – 3 – 5 – 7 – 8 – 2 – 9)
low = mid + 1
/2 (5,7)
~(arr-list[mid] > key)
Table 2: All-def coverage table

10449314 Page |5
CSI3105 SOFTWARE TESTING – Minor 02

(ii) All-uses coverage:


In this criterion, a set of paths that includes every c-uses (computational) and every
p-uses (conditions). There should be a complete path including a def-clear path as
well from node i to node j.

Variable Definition in Global c-use


ID p-use (edge) Path
Name Node (node)
(3,4)
01 1 - (1 – 2 – 3 – 4 – 8 – 2 – 9)
(arr-list[mid] == key)

(3,5) (1 – 2 – 3 – 5 – 6 – 8 – 2 – 9)
02 1 -
arr-list[] ~(arr-list[mid] == key) (1 – 2 – 3 – 5 – 7 – 8 – 2 – 9)
- (5,6)
03 1 (1 – 2 – 3 – 5 – 6 – 8 – 2 – 9)
(arr-list[mid] > key)
(5,7)
04 1 - (1 – 2 – 3 – 5 – 7 – 8 – 2 – 9)
~(arr-list[mid] > key)
1
05 n 1 - (1 – 2 – 9)
high = n - 1
(3,4)
06 1 - (1 – 2 – 3 – 4 – 8 – 2 – 9)
(arr-list[mid] == key)

(3,5) (1 – 2 – 3 – 5 – 6 – 8 – 2 – 9)
07 1 -
~(arr-list[mid] == key) (1 – 2 – 3 – 5 – 7 – 8 – 2 – 9)
key
(5,6)
08 1 - (1 – 2 – 3 – 5 – 6 – 8 – 2 – 9)
(arr-list[mid] > key)
(5,7)
09 1 - (1 – 2 – 3 – 5 – 7 – 8 – 2 – 9)
~(arr-list[mid] > key)
(2,9)
1
10 - ~((high >= low) && (1 – 2 – 9)
low = 0
(found == -1))
(2,3) (1 – 2 – 3 – 4 – 8 – 2 – 9)
low 1
11 - ((high >= low) &&
low = 0
(found == -1))
(1 – 2 – 3 – 5 – 6 – 8 – 2 – 9)
1 3 (1 – 2 – 3 – 4 – 8 – 2 – 9)
12 -
low = 0 mid = (low + high) / 2 (1 – 2 – 3 – 5 – 6 – 8 – 2 – 9)
(2,9)
1
13 - ~((high >= low) && (1 – 2 – 9)
high = n - 1
(found == -1))
(2,3) (1 – 2 – 3 – 4 – 8 – 2 – 9)
1
14 high - ((high >= low) &&
high = n - 1
(found == -1))
(1 – 2 – 3 – 5 – 7 – 8 – 2 – 9)

1 3 (1 – 2 – 3 – 4 – 8 – 2 – 9)
15 -
high = n - 1 mid = (low + high) / 2 (1 – 2 – 3 – 5 – 7 – 8 – 2 – 9)

1 9
16 found - (1 – 2 – 9)
found = -1 return found

10449314 Page |6
CSI3105 SOFTWARE TESTING – Minor 02

(2,9)
1
17 - ~((high >= low) && (1 – 2 – 9)
found = -1
(found == -1))
(2,3) (1 – 2 – 3 – 5 – 6 – 8 – 2 – 9)
1
20 - ((high >= low) &&
found = -1
(found == -1))
(1 – 2 – 3 – 5 – 7 – 8 – 2 – 9)

4 9
21 - (1 – 2 – 3 – 4 – 8 – 2 – 9)
found = mid return found

(1 – 2 – 3 – 4 – 8 – 2 – 9)
3
22 1 - (1 – 2 – 3 – 5 – 6 – 8 – 2 – 9)
mid = (low + high) / 2
(1 – 2 – 3 – 5 – 7 – 8 – 2 – 9)
(3,4)
23 1 - (1 – 2 – 3 – 4 – 8 – 2 – 9)
(arr-list[mid] == key
(3,5)
24 1 - (1 – 2 – 3 – 5 – 6 – 8 – 2 – 9)
~(arr-list[mid] == key
3
4
25 mid = (low + high) - (1 – 2 – 3 – 4 – 8 – 2 – 9)
found = mid
/2
3
(3,4)
26 mid = (low + high) - (1 – 2 – 3 – 4 – 8 – 2 – 9)
(arr-list[mid] == key
/2

mid 3
6
27 mid = (low + high) - (1 – 2 – 3 – 5 – 6 – 8 – 2 – 9)
high = mid - 1
/2

3
(3,5)
28 mid = (low + high) - (1 – 2 – 3 – 5 – 6 – 8 – 2 – 9)
~(arr-list[mid] == key)
/2

3
(5,6)
29 mid = (low + high) - (1 – 2 – 3 – 5 – 6 – 8 – 2 – 9)
(arr-list[mid] > key)
/2
3
7
30 mid = (low + high) - (1 – 2 – 3 – 5 – 7 – 8 – 2 – 9)
low = mid + 1
/2
3
(5,7)
31 mid = (low + high) - (1 – 2 – 3 – 5 – 7 – 8 – 2 – 9)
~(arr-list[mid] > key)
/2
Table 3: All uses coverage table

10449314 Page |7
CSI3105 SOFTWARE TESTING – Minor 02

2.1. Test Suite for All-def coverage and All-use coverage


The following test suite tests each path of the data flow, all c-uses and p-uses are covered related
to that respective variable. Note: The “key” is considered as an element of the array.

2.1.1. For variable “n”


ID Variable n Node/Edge
Global Definition 1
1
C-use
(high = n - 1)
Def-Clear Path (1)
A-1 Complete Path (1 – 2(F) - 9)
Inputs Expected Output
arr-list[]={0,1,2,3} -1
n = -1
key = 4

2.1.2. For variable “key”


ID Variable key Node/Edge
Global Definition 1
(3,4)
P-use
(arr-list[mid] == key)
Def-Clear Path (1 – 2 – 3 – 4)
B-1 Complete Path (1 – 2(T) – 3(T) – 4 – 8 – 2(F) – 9)
Inputs Expected Output
arr-list[]={2,1,0,-1} 0
n=1
key = 2

ID Variable key Node/Edge


Global Definition 1
(5,6)
P-use
(arr-list[mid] > key)
(3,5)
Covered P-use
(arr-list[mid] == key)
B-2 Def-Clear Path (1 – 2 – 3 – 5)
Complete Path (1 – 2(T) – 3(F) – 5(T) – 6 – 8 – 2(F) – 9)
Inputs Expected Output
arr-list[]={5,8,9,11} -1
n=2
key = -1

10449314 Page |8
CSI3105 SOFTWARE TESTING – Minor 02

ID Variable key Node/Edge


Global Definition 1
(5,7)
P-use
~(arr-list[mid] > key)
(3,5)
Covered P-use
~(arr-list[mid] == key)
B-3 Def-Clear Path (1 – 2 – 3 – 5)
Complete Path (1 – 2(T) – 3(F) – 5(F) – 7 – 8 – 2(F) – 9)
Input Expected Output
arr-list[]={2,6,11,12} -1
n=1
key = 10

2.1.3. For variable “mid”


ID Variable mid Node/Edge
Global Definition 1
4
C-use
found = mid
(3,4)
P-use
(arr-list[mid] == key)
3
Covered C-use
mid = (low+high)/2
C-1
Def-Clear Path (1 – 2 – 3 – 4)
Complete Path (1 – 2(T) – 3(T) – 4 – 8 – 2(F) – 9)
Input Expected Output
arr-list[]={1,4,5,8} 1
n=3
key = 4

10449314 Page |9
CSI3105 SOFTWARE TESTING – Minor 02

ID Variable mid Node/Edge


Global Definition 1
6
C-use
high = mid - 1
(5,6)
P-use
(arr-list[mid] > key)
3
Covered C-use
mid = (low+high)/2

C-2 (3,5)
Covered P-use
~(arr-list[mid] == key)
Def-Clear Path (1 – 2 – 3 – 5 – 6)
Complete Path (1 – 2(T) – 3(F) – 5(T) – 6 – 8 – 2(F) – 9)
Input Expected Output
arr-list[]={0,2,4,7} -1
n=2
key = -1

ID Variable mid Node/Edge


Global Definition 1
(5,7)
P-use
~(arr-list[mid] > key)
3
Covered C-use
mid = (low+high)/2

(3,5)
Covered P-use
C-3 ~(arr-list[mid] == key)
Def-Clear Path (1 – 2 – 3 – 5 – 7)
Complete Path (1 – 2(T) – 3(F) – 5(F) – 7 – 8 – 2(F) – 9)
Input Expected Output
arr-list[]={2,8,10,12} -1
n=1
key = 10

10449314 P a g e | 10
CSI3105 SOFTWARE TESTING – Minor 02

2.1.4. For variable “low” and “high”


ID Variable low/high Node/Edge
Global Definition 1
C-use 1
(2,9)
P-use
~((high>=low) && (found==-1))
D-1 Def-Clear Path (1 – 2 - 9)
Complete Path (1 – 2(F) - 9)
Input Expected Output
arr-list[]={1,1,3,4} -1
n = -5
key = 4

ID Variable low/high Node/Edge


Global Definition 1
3
C-use
mid = (low + high)/2
(2,3)
P-use
((high>=low) && (found==-1))
D-2 Def-Clear Path (1 – 2 – 3 – 4)
Complete Path (1 – 2(T) – 3(T) – 4 – 8 – 2(F) – 9)
Input Expected Output
arr-list[]={2,3,4,5} 0
n=1
key = 2

2.1.5. For variable “found”


ID Variable found Node/Edge
Global Definition 1
9
C-use
(return found)
1
Covered C-use
(found = -1)
(2,9)
P-use
F-1 ~((high>=low) && (found==-1))
Def-Clear Path (1 – 2 - 9)
Complete Path (1 – 2(F) - 9)
Input Expected Output
arr-list[]={1,2,3,4} -1
n = -1
key = 4

10449314 P a g e | 11
CSI3105 SOFTWARE TESTING – Minor 02

(iii) All-du-path coverage:


In this criteria, du-path is a path which either starts from a global definition to a
global c-use or a global definition to a p-use. In simple words, going from where it is
defined to where it is used. A specific node has a global c-use of a variable x and a
def-clear simple path or a specific edge has a p-use of a variable x and a def-clear
loop-free path. It should also be a complete path.

Variable Definition in Global c-use p-use


ID Path
Name Node (node) (edge)
(3,4)
01 1 - (1 – 2 – 3 – 4 – 8 – 2 – 9)
(arr-list[mid] == key)
(3,5), (5,6)
02 arr-list[] 1 - ~(arr-list[mid] == key) (1 – 2 – 3 – 5 – 6 – 8 – 2 – 9)
(arr-list[mid] > key)
- (5,7)
03 1 (1 – 2 – 3 – 5 – 7 – 8 – 2 – 9)
~(arr-list[mid] > key)
1
04 n 1 - (1 – 2 – 9)
high = n - 1
(3,4)
05 1 - (1 – 2 – 3 – 4 – 8 – 2 – 9)
(arr-list[mid] == key)
(3,5), (5,6)
06 key 1 - ~(arr-list[mid] == key) (1 – 2 – 3 – 5 – 6 – 8 – 2 – 9)
(arr-list[mid] > key)
(5,7)
07 1 - (1 – 2 – 3 – 5 – 7 – 8 – 2 – 9)
~(arr-list[mid] > key)
(2,3) (1 – 2 – 3 – 4 – 8 – 2 – 9)
1 3
08 ((high >= low) &&
low = 0 mid = (low + high) / 2
(found == -1))
(1 – 2 – 3 – 5 – 6 – 8 – 2 – 9)
(2,3)
1 7
09 ((high >= low) && (1 – 2 – 3 – 5 – 7 – 8 – 2 – 9)
low = 0 low = mid + 1
(found == -1))
low
(2,9)
1
10 - ~((high >= low) && (1 – 2 – 9)
low = 0
(found == -1))
(2,9)
11 7 7 (1 – 2 – 3 – 5 – 7 – 8 – 2 – 9)
~((high >= low) &&
low = mid + 1 low = mid + 1
(found == -1))
(2,3) (1 – 2 – 3 – 4 – 8 – 2 – 9)
1 3
12 ((high >= low) &&
high = n - 1 mid = (low + high) / 2
(found == -1))
(1 – 2 – 3 – 5 – 7 – 8 – 2 – 9)
(2,3)
1 6
13 ((high >= low) && (1 – 2 – 3 – 5 – 6 – 8 – 2 – 9)
high = n - 1 high = mid - 1
(found == -1))
high
(2,9)
1
14 - ~((high >= low) && (1 – 2 – 9)
high = n - 1
(found == -1))
(2,9)
6 6
15 ~((high >= low) && (1 – 2 – 3 – 5 – 6 – 8 – 2 – 9)
high = mid - 1 high = mid - 1
(found == -1))

10449314 P a g e | 12
CSI3105 SOFTWARE TESTING – Minor 02

(2,9)
1 9
16 ~((high >= low) && (1 – 2 – 9)
found = -1 return found
(found == -1))
(2,3) (1 – 2 – 3 – 5 – 6 – 8 – 2 – 9)
1 4
17 ((high >= low) && (1 – 2 – 3 – 5 – 7 – 8 – 2 – 9)
found = -1 found = mid
(found == -1)) (1 – 2 – 3 – 4 – 8 – 2 – 9)
found
(2,9)
4 4
18 ~((high >= low) && (1 – 2 – 3 – 4 – 8 – 2 – 9)
found = mid found = mid
(found == -1))

(2,9)
4 9
19 ~((high >= low) && (1 – 2 – 3 – 4 – 8 – 2 – 9)
found = mid return found
(found == -1))
(3,4)
(arr-list[mid] == key (1 – 2 – 3 – 4 – 8 – 2 – 9)
3
20 1
mid = (low + high) / 2
(3,5) (1 – 2 – 3 – 5 – 6 – 8 – 2 – 9)
~(arr-list[mid] == key
3 4 (3,4)
21 mid = (low + high) (1 – 2 – 3 – 4 – 8 – 2 – 9)
found = mid (arr-list[mid] == key
/2
mid (3,5)
3 ~(arr-list[mid] == key)
6
22 mid = (low + high) (1 – 2 – 3 – 5 – 6 – 8 – 2 – 9)
high = mid - 1
/2 (5,6)
(arr-list[mid] > key)
(3,5)
3 ~(arr-list[mid] == key)
7
23 mid = (low + high) (1 – 2 – 3 – 5 – 7 – 8 – 2 – 9)
low = mid + 1
/2 (5,7)
~(arr-list[mid] > key)
Table 4: All-du-path coverage table

10449314 P a g e | 13
CSI3105 SOFTWARE TESTING – Minor 02

3.1. Test Suite for All-du-path coverage

The following test suite for all-du-path coverage will include the paths with c-uses that has
def-clear simple path and p-uses that has a def-clear loop free path. The paths with def-clear
path in all-du-path coverage is already covered in the above given test suite.

3.1.1. For variable “low”


ID Variable low Node/Edge
Global Definition 1
7
C-use
(low = mid + 1)
(2,3)
P-use
((high>=low) && (found==-1))
1
G-1 Covered C-use
(low = 0)
Complete Path (1 – 2(T) – 3(F) – 5(F) – 7 – 8 – 2(F) – 9)
Input Expected Output
arr-list[]={15,16,18,20} -1
n=1
key = 20

3.1.2. For variable “high”


ID Variable high Node/Edge
Global Definition 1
6
C-use
(high = mid - 1)
(2,3)
P-use
((high>=low) && (found==-1))
1
G-1 Covered C-use
(high = n - 1)
Complete Path (1 – 2(T) – 3(F) – 5(T) – 6 – 8 – 2(F) – 9)
Input Expected Output
arr-list[]={0,2,4,7} -1
n=2
key = -1

10449314 P a g e | 14
CSI3105 SOFTWARE TESTING – Minor 02

3.1.3. For variable “found”


ID Variable found Node/Edge
Global Definition 1
4
C-use
(found = mid)
(2,3)
P-use
((high>=low) && (found==-1))
1
G-1 Covered C-use
(found = -1)
Complete Path (1 – 2(T) – 3(T) – 4 – 8 – 2(F) – 9)
Input Expected Output
arr-list[]={0,1,2,3} 3
n=7
key = 3

10449314 P a g e | 15
CSI3105 SOFTWARE TESTING – Minor 02

Question 02: Using the program code

(i) Control Flow Graph

Figure 2: Control Flow Chart

10449314 P a g e | 16
CSI3105 SOFTWARE TESTING – Minor 02

(ii) Test suite that achieves branch coverage


For each branch in a program such as if statement or loops, each of them must
be executed at least once during testing. In other words, each branch condition
must be true at least once and false at least once. 100% branch coverage means
each branch must be included in a set of paths that is associated to a particular
CFG at least once.

T – True
F – False

P1 = [ A – B (F) – L ]
P2 = [ A – B (T) – C (T) – D – E (T) – G – B (T) – C (F) – L ]
P3 = [ A – B (T) – C (T) – D – E (F) – H (T) – J – B (F) – L ]
P4 = [ A – B (T) – C (T) – D – E (F) – H (F) – K – B (T) – L ]

Path Inputs Excepted Output


arr-list[] = {0,2,4,7}
Path 01 n = -11 -1
key = 7
arr-list[] = {2,3,4,7}
Path 02 n=5 2
key = 2
arr-list[] = {4,6,7,8}
Path 03 n=1 -1
key = 0
arr-list[] = {0,1,2,3}
Path 04 n=1 -1
key = 8
Table 5: Branch Coverage Test Suite

10449314 P a g e | 17
CSI3105 SOFTWARE TESTING – Minor 02

(iii) List of the set of basis path

There are two ways you can find the cyclomatic complexity:
Cyclomatic complexity = the number of regions + 1 OR the number of predicates + 1
In this CFG, the number of predicates is equal to 4 and regions is equal to 4
therefore 4 + 1 is equal to 5 paths

E = {( Start,A ), ( A,B ), ( B, L ), ( B,C ), ( C,L ), (C,D ), ( D,E ), ( E,H ), ( E,G ), ( H,K ), ( H, J ),


( K,B ), ( J,B ), ( G,B )}

P1 = [ A – B (F) – L ]
P2 = [ A – B (T) – C (F) – L ]
P3 = [ A – B (T) – C (T) – D – E (T) – G – B (F) – L ]
P4 = [ A – B (T) – C (T) – D – E (F) – H (T) – J – B (F) – L ]
P5 = [ A – B (T) – C (T) – D – E (F) – H (F) – K – B (F) – L ]
Total: 5 Paths

(iv) Test case using the basic path

Path Inputs Excepted Output


arr-list[] = {2,4,6,8}
Path 01 n = -5 -1
key = 2
arr-list[] = {0,2,4,7}
Path 02 n=1 Infeasible
key = 3
arr-list[] = {2,3,4,5}
Path 03 n=1 0
key = 2
arr-list[] = {0,2,4,7}
Path 04 n=2 -1
key = -1
arr-list[] = {15,16,18,20}
Path 05 n=1 -1
key = 20
Table 6: Test case for basis path

• Path 02 is infeasible because without entering the while loop, the variable “found” is
always equal to -1

10449314 P a g e | 18

You might also like