Software Test Job 3

Source: Internet
Author: User
Tags greatest common divisor

 PackageCn.zheng;ImportJava.util.Scanner; Public classDemo {/**     * @paramargs*/     Public Static voidMain (string[] args) {//TODO auto-generated Method StubInpu IP =NewInpu (); Sushu SS=NewSushu (Ip.run ());    Ss.run (); }}
 PackageCn.zheng;ImportJava.util.Scanner; Public classSushu {Private intx; Private inty; Private int[] b;  PublicSushu (int[] b) {Super();  This. B =b; }         PublicSushu () {Super(); }         Public  voidrun () {if(b = =NULL)            {                return; } x= B[0]; Y= B[1]; inttemp = 0; if(x<y) {temp=x; X=y; Y=temp; }             while(x%y!=0) {Temp=y; Y=x%y; X=temp; } System.out.println ("The greatest common divisor of these two numbers is:" +y); }}
 PackageCn.zheng;ImportJava.util.Scanner; Public classInpu {Private intx; Private inty; Private int[] b;  Public int[] Run () {b=New int[2]; intresult; Scanner a=NewScanner (system.in); System.out.println ("Please enter two integers"); Try{System.out.println ("Please enter the first integer"); X= Integer.parseint ((A.nextline (). Replace ("", ""))); System.out.println ("Please enter a second integer"); Y= Integer.parseint ((A.nextline (). Replace ("", ""))); if(X==0 | | y==0) {System.out.println ("The data you entered is not valid"); b=NULL; returnb; } b[0]=x; b[1]=y; returnb; } Catch(Exception e) {//Todo:handle ExceptionSYSTEM.OUT.PRINTLN ("The data you entered is not valid"); b=NULL; returnb; }}} This class does not know how to test with JUnit ... I'll change it when I learn more ...
 PackageCn.zheng;Import Staticorg.junit.assert.*;ImportOrg.junit.After;ImportOrg.junit.Before;Importorg.junit.Test; Public classTestsushu {PrivateSushu SS; @Before Public voidSetUp ()throwsException {SS=NewSushu (); } @After Public voidTearDown ()throwsException {} @Test Public voidTest () {int[]B =New int[2]; b[0]=34; b[1]=2; SS=NewSushu (b);                Ss.run (); b=NULL; SS=NewSushu (b);                Ss.run (); b=New int[2]; b[0]=2; b[1]=34; SS=NewSushu (b);                Ss.run (); b[0]=-35; b[1]=3; SS=NewSushu (b);        Ss.run (); }}

Test Case: First Number: 3 6 second number: 6 result is 6

First Number: result is data not valid

First Number: 3 second number: 34 result is 1

First Number: A V C result for data not valid

Software Test Job 3

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.