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:
/** * * This method takes the middle part of the phone number according to user input @param strphonenum phone number, such as: "0591-83279988-002" @ Returnpublicif ((strphonenum==null) | | "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
(2) Write down the reason why the problem arises
(3) Give the modified code
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)
(2) Explain your design ideas
(3) Write a possible error (at least five kinds)
(4) Write JUnit unit tests to put the test data that was previously given in the possible error into the unit test for testing
Topic One:
1. Questions:
Question one:
public string Getphonenumber (string strphonenum) {
if ((Strphonenum==null) | | "" .equals (strphonenum) {
return ";        }
Question two:
Area code-Phone number-the extension number should be a number and a length of 11 bits
Question three:
Area code-Phone number-extension number format is 3-4-bit area code, 7-8-digit live number, 1-4 poorly transposition machine number
2. Reason:
Cause one: The phone entered in question one is a null value, but it returns ""
Reason two: The code in the system requirements is not perfect, not strict
3. Modification:
public string Getphonenumber (string strphonenum )
< Span style= "color: #000000;" > if (Strphonenum==null) | | ".equals (Strphonenum)) < Span style= "color: #0000ff;" >{ /span>
< Span style= "color: #000000;" > System.out.println ("The input phone cannot be empty!") ");
return false;
}
if (Strphonenum.length ()! = 11) {
throw new Exception ("Phone number must be 11 digits long");
}
for (int i = 2; I < phonenum.length (); i++) {
Char p = phonenum.charat (i);
if (P < ' 0 ' | | p > ' 9 ') {
throw new Exception ("The phone number must consist of numbers!") ");
}
}
String format= "((\d{11}) |^ ((\d{7,8}) | ( \D{4}|\D{3})-(\d{7,8}) | (\d{4}|\d{3})-(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1}) | (\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1})) ";
if (strphonenum.matches (format))
{
Return true;//phone name is valid, returns True
}
else{
Return false;//phone name is not valid, returns false
SYSTEM.OUT.PRINTLN ("The input phone format is not qualified!") ");
}
}
/span> < Span style= "color: #000000;" > string[] Arrphone= Strphonenum.split ("-" return arrphone[1 }
The split ("-") method obtains a numerical result of
0591
83279988
002
Return arrphone[1] is returned as a second array so the result is 83279988
Topic Two:
Minjiang College School of the next 2015-2016 years software testing course-Third blog assignment