17
INSTITUTE OF INFORMATION TECHNOLOGY UNIVERSITY OF DHAKA Software Testing Submitted by Minhas Kamal Roll- BSSE0509 Submitted to Alim-ul-Giash Lecturer Institute of Information Technology, University of Dhaka Data: 10-Nov-15

White-Box Testing on Methods

Embed Size (px)

Citation preview

INSTITUTE OF INFORMATION TECHNOLOGY

UNIVERSITY OF DHAKA

Software Testing

Submitted by

Minhas Kamal

Roll- BSSE0509

Submitted to

Alim-ul-Giash

Lecturer

Institute of Information Technology,

University of Dhaka

Data: 10-Nov-15

Method -1: findQueen

1 private int findQueen(int row){

2 intqueenColumnNo=

3 for(int j=0; j<boardSize; j++){

4 if(boxes[row][j]==1){

5 queenColumnNo=j;

6 break;

7 }

8 }

9 return queenColumnNo;

10 }

Flow Diagram:

Cyclomatic Complexity:

1. V(G) = e - n + 2p = 7 – 6 + 2 = 3

2. V(G) = d + 1 = (1+1) + 1 = 3

3. V(G) = number of regions = 3

findQueen(int row){

intqueenColumnNo=-1;

for(int j=0; j<boardSize; j++){

if(boxes[row][j]==1){

queenColumnNo=j;

break;

return queenColumnNo;

6 + 2 = 3

V(G) = d + 1 = (1+1) + 1 = 3

V(G) = number of regions = 3

1

2

Independent Paths:

1. 1, 2, 3, 4, 5, 6, 9, 10

2. 1, 2, 3, 9, 10

3. 1, 2, 3, 4, 8, 3, 9, 10

Test Case:

Test Case ID Input Expected Output Independent Path Covered by Test Case

TC-1 row = 0

boardSize = 2

boxes = {{1,0},{0,0}}

queenColumnNo = 0 1

TC-2 row = 0

boardSize = -1

boxes = {{ }}

queenColumnNo = -1 2

TC-3 row = 0

boardSize = 1

boxes = {{0}}

queenColumnNo = -1 3

Data Flow Graph for ‘queenColumnNo

Data Flow Graph for ‘row’:

queenColumnNo’:

3

4

All du-paths:

queenColumnNo row

2-3-9 1-2-3-4-8-3-4

2-3-4-8-3-9 1-2-3-4

2-3-4-5-6-9

2-3-4-8-3-4-5-6-9

5-6-9

Method -2: setQueen

1 public void setQueen(int row, int column) {

2 for(int i=0; i<boardSize; i++){

3 boxes[row][i] = 0;

4 }

5

6 geneticSequence[row] = column;

7 boxes[row][column] = 1;

8 }

Flow Diagram:

Cyclomatic Complexity:

1. V(G) = e - n + 2p = 4 – 4

2. V(G) = d + 1 = 1 + 1 = 2

3. V(G) = number of regions =

Independent Paths:

1. 1, 2, 3, 4, 2, 5, 6, 7, 8

2. 1, 2, 5, 6, 7, 8 (unfeasible path)

public void setQueen(int row, int column) {

for(int i=0; i<boardSize; i++){

boxes[row][i] = 0;

geneticSequence[row] = column;

boxes[row][column] = 1;

4 + 2 = 2

V(G) = number of regions = 2

(unfeasible path)

5

Test Case:

Test Case ID Input

TC-1 row = 0

column = 0

boardSize = 1

Data Flow Graph for ‘row’:

Expected Output Independent Path Covered by Test Case

boxes = {{1}}

queenColumnNo = {0}

1

6

Independent Path Covered by Test Case

Data Flow Graph for ‘column’

All du-paths:

row

1-2-5-6-7

1-2-3-4-2-5-6-7

1-2-3

1-2-3-2-3

column’:

column

1-2-5-6-7

1-2-3-4-2-5-6-7

7

Method -3: toString

1 public String toString(){

2 String string = "";

3

4 for(int i=0; i<boardSize; i++){

5 for(int j=0; j<boardSize; j++){

6 string += boxes[i][j] + " ";

7 }

8 string += "

9 }

10

11 return string;

12 }

Flow Diagram:

Cyclomatic Complexity:

1. V(G) = e - n + 2p = 7 – 6 + 2 = 3

2. V(G) = d + 1 = (1+1) + 1 = 3

3. V(G) = number of regions = 3

public String toString(){

String string = "";

for(int i=0; i<boardSize; i++){

for(int j=0; j<boardSize; j++){

string += boxes[i][j] + " ";

string += "\n";

6 + 2 = 3

V(G) = d + 1 = (1+1) + 1 = 3

(G) = number of regions = 3

8

9

Independent Paths:

1. 1, 2, 3, 4, 5, 6, 7, 5, 8, 9, 4, 10, 11, 12

2. 1, 2, 3, 4, 10, 11, 12

3. 1, 2, 3, 4, 5, 8, 9, 4, 10, 11, 12 (unfeasible path)

Test Case:

Test Case ID Input Expected Output Independent Path Covered by Test Case

TC-1 boardSize = 1

boxes = {{0}}

string = “0 \n” 1

TC-2 boardSize = -1

boxes = {{ }}

string = “” 2

Data Flow Graph for ‘string’:

All du-paths:

string

2-

2-

2-

2-

6-

6-

6-

8-

8-

8-

string

-3-4-10-11

-3-4-5-6

-3-4-5-6-7-5-8

-3-4-5-6-7-5-8-4-10-11

-5-8

-5-8-4-10-11

-5-6

-4-10-11

-4-5-6

-4-5-8

10

Method -4: occurMutation

1 public void occurMutation(

2 Random random = new Random();

3

4 if(randomValue

5 int rowNo = Math.abs(random.nextInt()%boardSize);

6 int columnNo = Math.abs(random.nextInt()%boardSize);

7

8 setQueen(rowNo, columnNo);

9 }

10 }

Flow Diagram:

Cyclomatic Complexity:

1. V(G) = e - n + 2p = 4 – 4

2. V(G) = d + 1 = 1 + 1 = 2

3. V(G) = number of regions = 2

Independent Paths:

1. 1, 2, 3, 4, 5, 6, 7, 8, 9, 10

2. 1, 2, 3, 4, 10

public void occurMutation(int randomValue){

Random random = new Random();

%10==0){

rowNo = Math.abs(random.nextInt()%boardSize);

columnNo = Math.abs(random.nextInt()%boardSize);

setQueen(rowNo, columnNo);

4 + 2 = 2

number of regions = 2

10

11

rowNo = Math.abs(random.nextInt()%boardSize);

columnNo = Math.abs(random.nextInt()%boardSize);

Test Case:

Test Case ID Input

TC-1 random = 100

TC-2 random = 97

Data Flow Graph for ‘random

Data Flow Graph for ‘random

Expected Output Independent Path Covered by Test Case

“setQueen()” method

is called & queen is

randomly placed

1

Do nothing 2

randomValue’:

random’:

12

Independent Path Covered by Test Case

Data Flow Graph for ‘rowNo’:

Data Flow Graph for ‘columnNo

All du-paths:

randomValue random

1-2-3-4 2-3-4-5

2-3-4-5

’:

columnNo’:

random rowNo columnNo

5-6 5-6-7-8 6-7

5

13

columnNo

7-8

Method -5: getCopy

1 public Board getCopy(){

2 Board newBoard = new Board(boardSize);

3

4 for(int i=0; i<boardSize; i++){

5 for(int j=0; j<boardSize; j++){

6 newBoard.boxes[i][j] = this.boxes[i][j];

7 }

8 newBoard.geneticSequence[i] = this.geneticSequence[i];

9 }

10

11 return newBoard;

12 }

Flow Diagram:

public Board getCopy(){

Board newBoard = new Board(boardSize);

for(int i=0; i<boardSize; i++){

for(int j=0; j<boardSize; j++){

newBoard.boxes[i][j] = this.boxes[i][j];

newBoard.geneticSequence[i] = this.geneticSequence[i];

return newBoard;

14

newBoard.boxes[i][j] = this.boxes[i][j];

newBoard.geneticSequence[i] = this.geneticSequence[i];

15

Cyclomatic Complexity:

1. V(G) = e - n + 2p = 7 – 6 + 2 = 3

2. V(G) = d + 1 = (1+1) + 1 = 3

3. V(G) = number of regions = 3

Independent Paths:

1. 1, 2, 3, 4, 5, 6, 7, 5, 8, 9, 4, 10, 11, 12

2. 1, 2, 3, 4, 10, 11, 12

3. 1, 2, 3, 4, 5, 8, 9, 4, 10, 11, 12 (unfeasible path)

Test Case:

Test Case ID Input Expected Output Independent Path Covered by Test Case

TC-1 boardSize = 1

boxes = {{1}}

newBoard = {{1}} 1

TC-2 boardSize = -1

boxes = {{ }}

newBoard = {{ }} 2

Data Flow Graph for ‘newBoard

All du-paths:

newBoard

2-3-4-10-11

2-3-4-5-8-4-10

2-3-4-5-6-7-5

6-7-5-8-9-4-10

8-9-4-10-11

newBoard’:

10-11

5-8-4-10-11

10-11

16