Software Test Third Job

Source: Internet
Author: User
Tags greatest common divisor

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.