Escaped the first, but not 15 of the three input box the implementation and test of text content detection

Source: Internet
Author: User
Tags control characters

Lazy last week, did not complete the implementation of EditBox, to test ... Finally, this week to escape, the teacher assigned the task is to complete the input of three text boxes and detect the text content at the same time ...

The subject requirements are as follows:

Allow 1 to 6 English characters or numbers, press OK to end the valid equivalence class: Length: 1 to 6; character: a-z,a-z,0-9 Invalid equivalence class: Length: 0, 7; characters: English, other than the number of characters, control characters, punctuation and other slightly different place is this time to ask three text boxes to enter the content, click OK after the three text box content detection, and output test results. Good ~ Lazy thinking, I chose the more useful Java implementation, the main reason is that the interface and string processing is easier to complete ~ Well, the code is as follows:
 Packagetesting;ImportJava.awt.event.MouseAdapter;Importjava.awt.event.MouseEvent;ImportJavax.swing.JButton;ImportJavax.swing.JFrame;ImportJavax.swing.JPanel;ImportJavax.swing.JTextArea; Public classTesting {Static Booleanresult;  Public Static voidMain (string[] args) {//TODO auto-generated Method Stub//InterfaceJFrame frame =NewJFrame (); Frame.settitle ("Testing"); Frame.setsize (250,200); Frame.setlocationrelativeto (NULL); Frame.setvisible (true); JPanel Jp_top=NewJPanel (); Jp_top.setlayout (NULL); Jp_top.setbounds (0, 0, 300,300); FinalJTextArea []text =NewJtextarea[3];  for(inti=0;i<3;i++) {Text[i]=NewJTextArea (); Text[i].setbounds (20+40*i, 100, 20);        Jp_top.add (Text[i]); } JButton Button=NewJButton ("ok!"); Button.setbounds (140, 100, 80, 20);                Jp_top.add (button); //Checkresult =true; Button.addmouselistener (NewMouseadapter () { Public voidmouseclicked (MouseEvent e) {String []str=NewString[3];  for(inti=0;i<3;i++) {Str[i]=NewString (); Str[i]=Text[i].gettext (); }                 for(inti=0;i<3;i++){                    if(Str[i].length () >0 && str[i].length () <7){                         for(intP=str[i].length () -1;p>=0;p--){                            if(! Character.isdigit ((Str[i].charat (P))) &&!character.isletter (Str[i].charat (p))) {Result=false;  Break; }                        }                    }                    Else{result=false;            }} System.out.println (Result);                        }        });        Frame.add (Jp_top);    Frame.repaint (); }}

Show the effect of the code:

Well... Finally finished the coding process, the following test!

Review the test cases completed last week (using the equivalence class partitioning method):

No. Input Expected output
1 123456 Ok
2 ABCdef Ok
3 ABCDEF Ok
4 Aa1bb2 Ok
5 Abc Ok
6 Abcdefg ERROR (string length more than 6)
7 Empty (do not enter anything) ERROR (no input)
8 abc//b ERROR (contains invalid characters)
9 Ab,c ERROR (contains invalid characters)

Because there are multiple test cases and three more text boxes to input, I'm going to group the test cases to improve the efficiency of the tests.

The test cases are grouped according to the expected output (taking into account that the output will contain various cases)

(3,4,5), (1,2,6), (1,2,7), (1,2,8), (1,2,9)

The test results are as follows:

Use case combinations Test results
(a) True
(3,4,5) True
(1,2,6) False
(1,2,7) False
(1,2,8) False
(1,2,9) False

Overall, the results are quite satisfactory ... ^_^

Attach several pieces of the test process:

The first time to put out the code or something, really catch the urgency, we found that there is something wrong to welcome a discussion! thx~

Escaped the first, but not 15 of the three input box the implementation and test of text content detection

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.