Binary Search Testing Strategies
Binary Search Testing Strategies
Mishiag Behere
223 Cs3143
Rollno :
Software
Testing e
Assi g nment
,
) ate : 30/01/2029
Write a
for binary Id design test
program search a
site
for the function binary search that satifie
the
following white-bor
testing strategies
>
-
int
binary Search (int arr 25 eitn int
key) &
II
,
,
int low -o
,
high-n-1 ;
1) condition I
while (low I
high) &
int mid-low + (high-low)12 ;
Il condition
of (arr (mid] =
-key)
&
return mid ;
I/ conditions
if (are Smid key)
low-mid + 1 ;
ele
high-mid-1 ;
3 return ;
3
Testing the above
program
with
different testing strategies :
Coverage
:
1 .
Statement
that each statement is executed
Make sure
at least once .
Carr ,
S
, 12)3
Branch
2
Coverage
.
:
branch
Design test cases such that different
Conditions are tested at least once.
say are =
[1 ,
2 ,
3,4, 53
Scars ,
5
,
3) , Carr ,
s ,
2) , (are ,
S
, 4) Carr
,
-
,
3,
7)3
- -
I
-
Key
=
↓
are [mid] ↓ Regar cons
ke y 2 mid
<are keynot
i
Condition
Coverage
:
.
3
evaluated as
I
both true false
Condition1 :
33
3)3
an [] =
3) Can ,
&Care W
,
0 ,
, ,
ar =
21 ,
2 ,
3 , 9,
53
Sar ,
5
, 3)3 11 ar
<mid]-key
Condition 3:
are =
21 ,
2
,
3,9 , 53
Scare ,
s , 9)3 11 arr <mid] <
key
&
.
4 Path Coverage-Based Testing Read are ,
Key
P
↓
>
-
2
while(low
-
Shigh)
g
3 return -
p
V
S
an (mid]
Key &
=
=
V
~
6
return arr
(mid]
arr [mid]
Skey
V
V
low mid-I:
Low-mid
9
g
The
possible paths are :
1 -
142
2 .
1 + 3 +
4
31139596 + 8 + 3 +
9
+ 953 + 4
4 .
1 +
3 + 5 +
7
QG ) Write
. a e
program for
sort
functions for merge sort
algorithm and
the sort
.
a Determine the
eyelomatic Complexity of
function .
sort that
b .
Deigna
test site for the
function
satisfies
the following
white-bos strategies
1 . Statement Coverage
2 .
Branch Coverage
.
3 Condition Coverage
4 .
Path Coverage
(int arr C , left ent ,
int mid ,
ent
right I
?
- Vid merge
intn1 =
mid-left + 1 ;
intn2-right-mid
;
[n2] ;
int left Ars(n1 , right Arr
for (int i = 0
; i <
11 : i ++ ) 11
Condition I
lendlan
int i = 0
, j = 0 ,
k =
left ;
while
Candle t
I
-
I [K] leftArr[i] ;
=
ar
i + +;
Sehe E
arr [K] =
right Arr [j] ;
j + +;
+;
3
While (i < n1) & // Condition&
[
arr [K] =
leftArr[i];
i + +;
k++;
3
While (j < n2) & Il conditions
[
arr [K] =
rightArr(j] ;
j + +;
k +j
+
3
3
will be :
The CFG for the above program
Read input
·
values
Calculate initial
3
Seati
Santi
a
Dami i
:
got) gardenin
()) Conditioe
n
we know the ,
eyelomatic Complexity
vCG)
of
is
graph
:
a
E N + 2
v(a) nodes in G&
-
=
7 .
(b) 1 . Statement
Coverage
arr [] =
23
1 :
Empty array
2.
Away with one element , are <] =
2923
.
3
Multiple array elements
arr[] =
25 ,
2 ,
9 ,
1 ,
5 ,
63
.
2 Branch Coverage
:
Test Suite are
·
- are [] =
[1 ,
2, 3, 9 ,
53
· -
ar (3 =
35 ,
9 , 3, 2 , 13
3 .
Condition Coverage are :
Test suite
for Coverage
condition
· - arc 27 =
73 ,
7 7
, ,
7 ,
· - arr (1 21 =
9 7
83 ,
2
,
3
, ,
5
,
6 , ,
·
-
wr /] 93 =
33d ,
1 ,
9 , 5,
element
Repeated
4 .
Path Coverage
· - are < =
2123
·
earr[] =
23
·
- are <] =
93 ,
2, 13
· e arr [1 =
21 ,
2 , 3, 43
·
earr [] =
21 ,
7 ,
3 , 1 ,2 ,
43
93 . ) Write a function in C to
find the maximum element
I draw the control
of given
0
three
out
enleger From the control
function
that .
How graph for
determine its eyelomatic complexity
.
flow graph ,
sort that
I
ent aus
= U ;
if Canea vS
[3 ans
= V
;
Canew)
[ef ans
=
w ;
return ans ;
3
(CFG) es
flow Graph
:
It's Control
① Sreads
v, v , w]
am -r
⑤ if ans v
ana f ans w
b
sale
ans-wo- + return an
is :
of the program
The Cyclomatic complexity
E N +2
v(a)
-
v(a) 8 =
- 7 + 2
v(a) = 3
... .
are
testing strategies
The test suite for different
:
1 Statement Coverage 2), (3 2 , 9) ,
(3 9 ,
.
(4 2)
&
3, , ,
Testerite = , ,
(2 ,
3, 433
testcases will execute all the
These I
statements of
the
program.
Coverage
:
2 Branch (9 1) (4 3,
6)3
.
(9 6) , 3,
[(9 1) , 5 , ,
S , , ,
Test Crite = , ,
Coverage
:
3 .
Condition
Testlase I :
>v (Jue)
Simput er w)]
am
is
=
(9 ,
5
,
13 of ,
Test Case 2 :
ans v
(false)
=
(9 ,
3 ,
13
3 :
Test Case
(True)
.
am < W
(3 ,
4 , 5)
Case 4 :
Test
and < W (Falce)
=
(3 ,
5, 4)
.
9 Path Coverages can have are ?
differentPaths
we
The
5 7
1 . 1 ,
2, 3 , ,
2, 3 4 , 5, 7
3 . 1 ,
,
2, 3 4, 5 6 7
3 1 , ,
4)3
.
, ,
(9 2) (2 3,
((9
5
3 , h) ,
,
Test Suite =
,
, , ,
Q4) Write a
function of insertion sort in & design
for the function satisfies
a test site that the
following
1 Statement Coverage
.
.Branch Coverage
3 Condition Coverage
-
9 Path Coverage
.
vid
II
enti , key j ;
,
i(n ; i ++ )[
for (i
= 1;
arr [i] ;
key
-
i-1 ;
j
=
While (j)
= 0 && are (j) key) &
[
are (j + 17
= are [p] ;
j =
j =
1 ;
3
arr [j + 1] =
Key ;
3
3
1 . Statement Coverage
choose testcases in such
We need to
way
a
-
2 93 ,
1 ,2 , 3
, 33 [1 ,
2 ,
3, 9, 93
3 25 ,
1 ,
2 , 23 2 1 , 2, 2 , 53
2 .
Branch Coverage
>
- Test Seite :
& (3 , 2 ,
1) ,
(4 ,
1 ,
5, 3, h) 3
the
that it covers
The testcases ensures
while .
loop
.
3 Condition Coverage
- Test Suite
:
(3 3 1) , (112 , 3) 3
(2 , 2 2)
,
G
,
, ,
6 All the
texteaser lovers different
.
while loop
conditions of
9 .
Path Coverage
>
-
The CFG
for envection sort
function is
② initialize i ,
hey
* for loop
D
↓
③ key-arr [i]
S j = i =
1
are :
The
3 Can 13 =
33 ,
0)3
10 1 2 , 3 , 11
empty array
,
i .
e .,
1 2, 3, 4 5 6 7 8, 6 9 , 10 , 11
2 .
,
, , , , ,
[112 9, 113
&Care
5 9 7
(2 =
, , , ,
9) Design MC/DC testcases for the below condition :
(A && (B1(2))
>
-
Test case A B c (Ade(B11C)) A
S
B 2
i
T T T
4
i
6
T T F
2 7 4
if T
3 2 3
f
TF
F I
T T
F
f 2
FT F
F 3
f + T
7
F
f
g F F
condition :
the below
9) Design MC/DC testcases
for
(A && (BIC) && D)
ABD As BCD
A B C D
- Jetlan
T
9
2
3 ·
II 7
F
%
·
13
·
6
3 S
F
F A
i
3
S
MC/DC the below condition :
Q) Design tuteaus
for
(AllB && C)
(AllB && C) A B C
A B C
Test lase T 7 3
F T
T 7
↑
T 4
T
F T
i
F F
9
↑ F
-
T T
5
T T
S T S
T F
6 ↑
P &
T
7 -F
f F
g +