Software Test Third Blog Job

Source: Internet
Author: User

1, a website management system, the user registration, the phone number is optional input, the input format is: Area code-Telephone number-extension number, in the middle with "-" separated. The following is the design on the JSP page and does not have any control over the input.

Suppose the system now needs to take out the middle phone number part, the code is as follows:

/** * * *       @param phonenum  phone number, such as: "0760-8888888-011"      * @return  return to the number section, such as: "8888888" */      Public     string Getphonenumber (String strphonenum) {         if (strphonenum==null) | | ". Equals (Strphonenum)) {             return" ";         }         String[] Arrphone=strphonenum.split ("-");         return arrphone[1];     }

  

Use the techniques and methods you have learned to identify the problems in this approach, and analyze the cause of the problem, and give your solution. (Hint: there is more than one problem)

Requirements:

(1) Write the question

A, can enter the number unlimited

B, does not define whether the input is a number

C, no validation is empty

(2) Write down the reason why the problem arises

A, no limit on the length of the input

B. Lack of judgment

C, lack of validation

(3) Give the modified code

  Publicstring Getphonenumber (String strphonenum) {if((strphonenum==NULL) || "". Equals (Strphonenum)) {             if(strphonenum.lenth==17){                     return"True"; }Else{            return"False"; System.out.println ("The number entered is not in the correct format!!! "); }} string[] Arrphone=strphonenum.split ("-"); returnArrphone[1]; }   

2, write a paragraph for the integer array sorting code, explain your design ideas, and use the error-guessing method to give a possible error (at least 5), design the test case, and use JUnit to write unit tests to test. (assuming that the passed-in parameter has been determined to be an integer array)

Requirements:

(1) Write code, and conform to code specification (naming to specification, not directly written in the main method, need to have class comments, method comments, and appropriate line comments)

public class Supeng {   /**  * Simple sort  * 2016/04/28  * @author * * Public  static int[] Jiandan (int[] a) {      Compare and swap       int temp;        for (int i=0;i<a.length-1;i++) {for                 (int j=i+1;j<a.length;j++) {                              if (A[i]>a[j]) {                         temp=a[i];                         A[I]=A[J];                         A[j]=temp                     ;   }}} for (int i:a) {  System.out.println (i + "");}          return A;             }       public static void Main (string[] args) {//TODO auto-generated method stub int[] i={1,3,0}; SYSTEM.OUT.PRINTLN ("The result after sorting is:"); Jiandan (i);  Call the Sort Jiandna method System.out.println (); } }    

  

(2) Explain your design ideas

Set an integer array int a[4], containing four elements:

a[0]= 4,a[1] =3,a[2] =1,a[3] =2

The most basic operation for simple comparison sorting is comparison and exchange. The idea of the algorithm (from small to large rows) is:a[0] element compared to each subsequent element, if a[i] is less than a[0],a[i] and a[0] exchange, otherwise, Do not exchange.

After the first round of comparisons, swaps, the minimum elements are deposited into a[0]. The a[1] element is then compared with each subsequent element, if a[i] is less than a[1], A[i] and a[1] are exchanged, otherwise, not exchanged. After the second round of comparison, exchange, sub-value elements deposited a[1]. Continue repeating the above operations until each element is sorted by value from small to large and the sort ends.

(3) Write a possible error (at least five kinds)

A, the array contains only one element

B, the array contains negative numbers

C, all elements in the array are the same

D, the elements in the array are already lined up.

E, array is empty

(4) Write JUnit unit tests to put the test data that was previously given in the possible error into the unit test for testing

A

B

C

D

Software Test Third Blog 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.