forked from dreamer-89-zz/complexity-measure
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SW_BVA_WorstCaseTesting.java
127 lines (124 loc) · 5.29 KB
/
SW_BVA_WorstCaseTesting.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package software_testing_meaures;
import java.util.Scanner;
/**
*
* @author Suraj Singh
*/
class SW_BVA_WorstCaseTesting {
static int BoundaryValues[],RobustnessValues[],WorstCase[];
static int high,low,discriminant,counter;
public static void setBoundaryValues(int low, int high)
{
BoundaryValues = new int[]{low,low+1,high-1,high};// Assuming four boundary values
RobustnessValues= new int[]{low-1,low,low+1,(low+high)/2,high-1,high};// Assuming six boundary values
WorstCase = new int[]{low,low+1,(low+high)/2,high-1,high};// Assuming five boundary values
}
public static void calculateDiscriminant(int a, int b, int c)
{
discriminant = b*b - 4*a*c;
if(a>high || a<low|| b < low || b > high || c < low || c > high)
System.out.printf("\n%-8d %3d %3d %-4d %-50s",counter,a,b,c,"Invalid Input... Values Out of Range !!!");
else if(a==0)
System.out.printf("\n%-8d %3d %3d %-4d %-30s",counter,a,b,c,"Not a Quadratic Equation");
else if(discriminant>0)
System.out.printf("\n%-8d %3d %3d %-4d %-30s",counter,a,b,c,"Real Roots");
else if(discriminant==0)
System.out.printf("\n%-8d %3d %3d %-4d %-30s",counter,a,b,c,"Equal Roots");
else if(discriminant<0)
System.out.printf("\n%-8d %3d %3d %-4d %-30s",counter,a,b,c,"Imaginary Roots");
counter++;
}
public static void main(String args[])
{
Scanner s = new Scanner(System.in);
int a,b,c,count=0,type,average;
char choice;
do
{
System.out.println("\nEnter the type of testing to be performed !!!");
System.out.println("\n1.\tBoundary Value Analysis.");
System.out.println("\n2.\tRobustness Testing");
System.out.println("\n3.\tWorst Case Testing\n\nEnter your choice !!!");
type = s.nextInt();
System.out.print("Enter the range for [a,b,c] => ");
low = s.nextInt();
high = s.nextInt();
average = (low+high)/2;
counter = 1;
System.out.println(low+"<= a,b,c <="+high);
System.out.println();
System.out.println("\nTestCase a b c Output");
// Auto generation of values of a,b anc c
setBoundaryValues(low,high);
switch(type)
{
case 1 :
for(int i=0;i<3;i++)
{
for(int j=0;j<BoundaryValues.length;j++)
{
a = BoundaryValues[j];
b = average;
c = average;
if(i==0) // a should be changed
calculateDiscriminant(a,b,c);
else if(i==1) // b should be
calculateDiscriminant(b,a,c);
else // c should be changed
calculateDiscriminant(c,b,a);
}
}
calculateDiscriminant(average,average,average);
break;
case 2:
for(int i=0;i<3;i++)
{
for(int j=0;j<RobustnessValues.length;j++)
{
a = RobustnessValues[j];
b = average;
c = average;
if(i==0) // a should be changed
calculateDiscriminant(a,b,c);
else if(i==1) // b should be changed
calculateDiscriminant(b,a,c);
else // c should be changed
calculateDiscriminant(c,b,a);
}
}
calculateDiscriminant(average,average,average);
break;
case 3 :
for(int j=0;j<WorstCase.length;j++)
{
a = WorstCase[j];
for(int k=0;k<WorstCase.length;k++)
{
b = WorstCase[k];
for(int l=0;l<WorstCase.length;l++)
{
c = WorstCase[l];
if(count==0) // a should be changed
calculateDiscriminant(a,b,c);
else if(count==1) // b should be changed
calculateDiscriminant(b,a,c);
else // c should be changed
calculateDiscriminant(c,b,a);
}
}
count++;
}
break;
default : System.out.println("\n Please enter the correct choice ");
}
System.out.println("\nDo you want to continue ? \nY/y to continue. Other key to stop.");
choice = s.next().charAt(0);
System.out.println();
}while(choice=='Y'||choice=='y');
}
}