Unit Test Example

Source: Internet
Author: User

Unit testing is very important when writing a program, and the following is the code implementation and Unit test section for the maximum value of the array and the result screenshot

1 ImportJava.util.Scanner;2  Public classTest {3      Public Static voidMain (string[] args) {4         inta[]={1,2,3,4,5,6};5Judge (Largest (a,6));6         inta2[]={9,4,0,2,5,10};7Judge (Largest (a2,6));8         int[] a3={000,-1,-88,3,000,999};9Judge (Largest (a3,6));Ten         inta4[]={}; OneJudge (Largest (a4,0)); A         int[] a5=New int[5]; -Judge (Largest (a5,5)); -          while(1>0){ theSystem.out.println ("\ n Please enter the length of the array"); -Scanner sc2=NewScanner (system.in); -             intLength=sc2.nextint (); -             inta[]=New int[length]; +System.out.println ("Please enter an array"); -Scanner sc=NewScanner (system.in); +              for(inti=0;i<length;i++) A             { ata[i]=sc.nextint (); -             } - judge (Largest (a,length));  -         } -     } -      Public Static intLargest (intList[],intlength) {     in         if(list==NULL|| Length==0){ -                 return0; to         } +         intI,max=list[0]; -          for(i=0;i<length;i++){ the             if(list[i]>max) { *max=List[i]; $             }Panax Notoginseng         } -System.out.print ("\ n" +max); the         return1; +     } A      Public Static voidJudgeinti) { the         if(i==0){ +System.out.print ("\ n array is empty! "); -         } $         Else{ $System.out.print ("is the maximum value"); -         } -     } the}

Know in

These test arrays run with the following results:

Unit Test Example

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.