1.
computes the greatest common divisor of an integer x and an integer y. (It is not allowed in the way that the classroom is used).
Use classes and methods (write a method for greatest common divisor), and name them according to the specification. In the main mode, get the two integers entered by the user, call the previously written method, and output their greatest common divisor. Use FindBugs to find out if a bug exists in the program.
Demo class
Package cn.wu.test;
Public class Demo {
/**
* @param args
*/
Public Static void Main (string[] args) {
TODO auto-generated measure stub
Measure s =new measure ();
S.index ();
}
}
Method class
Package cn.wu.test;
Public class Measure {
Public void Index () {
int a=48,b=90;
int min =math. min (A, B);
for (int k=min;k>0;k--) {
if (A%k==0 && b%k==0) {
System. The greatest common divisor of out. println (A + "and" +b+ "are:" +k ");
return;
}
}
}
}
2,
the application of logic coverage
According to the program flowchart given, write out the Java code (implemented with classes and methods) to write out the statement overlay, the branch coverage of the test case, and the path it covers, using JUnit to write test cases to test.
L test Cases (statement overrides):
X |
Y |
Results |
Path |
3 |
2 |
Y+1=3 x=3 |
Abd |
3 |
1 |
Not change |
Abc |
6 |
-1 |
X-y=7 |
Aeg |
4 |
-1 |
X+y=3 |
Aef |
L test Case (branch coverage):
X<4 or Y>0 |
X>5 |
Y>1 |
Case |
Results |
Path |
T |
F |
|
X=3,y=1 |
Not change |
Abc |
T |
T |
|
x=3,y=2 |
Y+1=3 x=3 |
adb |
F |
|
F |
X=6,y=-1 |
X-y=7 |
Aeg |
F |
|
T |
X=4,y=-1 |
X+y=3 |
Aef |
Package cn.wu.test;
Public class Measure {
Public void Tests () {
int x = 5,y = 6;
if (X<4 | | y>0) {
if (y>1) {
y=y+1;
System. out. println ("x result is:" +x);
System. out. println ("Y+1 results are:" +y);
}
Else {
System. out. println ("x result is:" +x);
System. out. println ("y result is:" +y);
}
}
Else {
if (x>=5) {
X=x-y;
System. out. println ("x-y results are:" +x);
}
Else {
X=x+y;
System. out. println ("X+y results are:" +x);
}
}
}
}
Package cn.wu.test;
Public class Demo {
/**
* @param args
*/
Public Static void Main (string[] args) {
TODO auto-generated measure stub
Measure s =new measure ();
S.tests ();
}
}
Software Test Third Job