You are on page 1of 9

TUGAS INDIVIDU

“ SOFTWARE ENGINEERING ”
DOSEN : Dr. Ir. Gunadi Nurcahyo, M.Sc

D
i
s
u
s
u
n

Oleh :

NAMA : TRI PUTRI LESTARI


NO. BP : 202321020
KELAS : 37A

MAGISTER ILMU KOMPUTER


UNIVERSITAS PUTRA INDONESIA “YPTK” PADANG
2022
Daftar Isi

White Box Testing


Flowgraph
Independent Path
White Box Testing.

Here is some java code that reads in daily data for rainfall, average windspeed and
hours of sun for a number of days and prints out summary statistics. Use a
program flow graph to show the paths through the program and to calculate the
cyclomatic complexity. This should determine the number of independent paths.
Now make up some data to test each path.
import java.io.*;
import java.text.*;
public class Weather{

private static BufferedReader keyb = new BufferedReader(


new InputStreamReader(System.in));

public static void getWeatherStats(int NumberOfDays)


{ int i,j;
int wData[][] = new int[NumberOfDays][3]; //2-D array for the
weather data
String wType[] = {"Rainfall", "WindSpeed", "Hours of Sun"}; //1-D
array for type of data
//read in the data
for(i=0; i<NumberOfDays; i++)
{ for(j=0; j<3; j++)
{ System.out.print("Enter " + wType[j] + " for day " + i
+ ": ");
try{
wData[i][j] = Integer.parseInt(keyb.readLine());
}

catch (IOException e){


System.out.println("!! Error trying to read an int - zero
returned !!");
wData[i][j] = 0;
}

}//for j
System.out.println();
}//for i

//menu
int choice=0;
while (choice == 0)
{ System.out.println("Stats for");
System.out.println("\t1. Rain");
System.out.println("\t2. Wind");
System.out.println("\t3. Sun\n");
System.out.println("\tChoice: ");

try{
choice = Integer.parseInt(keyb.readLine());
}

catch (IOException e){


System.out.println("!! Choose between 1 and 3 please !!");
choice = 0;
}

//reports
int total = 0;
switch (choice)
{ case 1: //average rain
for(i=0; i<NumberOfDays; i++)
{ total = total + wData[i][0];
}//for i
System.out.println("\nAverage Rain = " +
total/NumberOfDays);
break;
case 2: //average wind
for(i=0; i<NumberOfDays; i++)
{ total = total + wData[i][1];
}//for i
System.out.println("\nAverage WindSpeed = " +
total/NumberOfDays);
break;
case 3://average sun
for(i=0; i<NumberOfDays; i++)
{ total = total + wData[i][2];
}//for i
System.out.println("\nAverage Hours Sun = " +
total/NumberOfDays);
break;
default: choice = 0;
}//switch
}//while
System.out.println();
}//main
}//Weather
Flowgraph
import java.io.*;
import java.text.*;
public class Weather{
private static BufferedReader keyb = new BufferedReader(
new InputStreamReader(System.in));
public static void getWeatherStats(int NumberOfDays)
{ int i,j; 1

int wData[][] = new int[NumberOfDays][3]; //2-D array for the weather data
2 String wType[] = {"Rainfall", "WindSpeed", "Hours of Sun"}; //1-D array for
type of data
//read in the data
for(i=0; i<NumberOfDays; i++) 3

{ for(j=0; j<3; j++) 4


5
{ System.out.print("Enter " + wType[j] + " for day " + i + ": ");
try{
wData[i][j] = Integer.parseInt(keyb.readLine());
} 6

catch (IOException e){


7
System.out.println("!! Error trying to read an int - zero returned !!");
wData[i][j] = 0;
}
}//for j 8

System.out.println();
}//for i 9

//menu
int choice=0;

1
while (choice == 0)
{ System.out.println("Stats for"); 1

System.out.println("\t1. Rain");
System.out.println("\t2. Wind");
System.out.println("\t3. Sun\n");
System.out.println("\tChoice: ");

1
try{
choice = Integer.parseInt(keyb.readLine());
}

catch (IOException e){ 1

System.out.println("!! Choose between 1 and 3 please !!");


choice = 0;
} 1

//reports
int total = 0;
1 switch (choice)
1
{ case 1: //average rain
for(i=0; i<NumberOfDays; i++) 1

{ total = total + wData[i][0];


}//for i 1

1 System.out.println("\nAverage Rain = " +


total/NumberOfDays);
break;
2
case 2: //average wind
for(i=0; i<NumberOfDays; i++) 2

{ total = total + wData[i][1];


}//for i 2

2 System.out.println("\nAverage WindSpeed = " +


total/NumberOfDays);
break;
case 3://average sun 2

for(i=0; i<NumberOfDays; i++) 2

{ total = total + wData[i][2];


}//for i 2

System.out.println("\nAverage Hours Sun = " +


total/NumberOfDays);
break;
default: choice = 0;
}//switch
2
}//while
System.out.println(); 2

}//main 3

}//Weather 3
Independent Path

Gambar Independent Part


Cylomatic complexity = number of edges – number of nodes + 2

CC = (40-31)+2
=9+2
= 11

40 = Banyak Panah
31 = Banyak Bulatan
2 = Kententuan

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

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

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

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

4. 1,2,9,10,11,12,13,14,15,16,17,16

5. 1,2,9,10,11,12,13,14,15,20,21,20

6. 1,2,9,10,11,12,13,14,15,24,25,24

7. 1,2,9,10,11,12,14,15,16,17,16

8. 1,2,9,10,11,12,14,15,20,21,20

9. 1,2,9,10,11,12,14,15,24,25,24

10. 1,2,9,10,11,12,13,14,15,16,18,19,28,10 /

1,2,9,10,11,12,13,14,15,20,22,23,28,10 /

1,2,9,10,11,12,13,14,15,24,26,27,28,10 /

1,2,9,10,11,12,14,15,16,18,19,28,10 /

1,2,9,10,11,12,14,15,20,22,23,28,10 /

1,2,9,10,11,12,14,15,24,26,27,28,10

11. 1,2,9,10,29,30,31

You might also like