Implementation of equivalence class partitioning test on Java

Source: Internet
Author: User

Using JavaFX to implement the partitioning of valid equivalence classes and invalid equivalence classes:

Code:

Import javafx.application.Application;
Import javafx.event.ActionEvent;
Import Javafx.event.EventHandler;
Import Javafx.scene.Scene;
Import Javafx.scene.control.Button;
Import Javafx.scene.control.Label;
Import Javafx.scene.control.TextField;
Import Javafx.scene.layout.AnchorPane;
Import Javafx.scene.text.Font;
Import Javafx.scene.text.FontWeight;
Import Javafx.scene.text.Text;
Import Javafx.stage.Stage;


public class Main extends application{
TextField TextField;
Label label;

public static void Main (string[] args) {
Application.launch (args);
}

public void start (stage stage) {
Stage.settitle ("for Test");
Anchorpane root = new Anchorpane ();
Scene scene = new Scene (root, 500, 300);

Text text = new text ();
Text.settext ("Write Something for Test:");
Text.setfont (Font.font ("Comic Sans MS", 18));
Anchorpane.settopanchor (text, 0.0);
Anchorpane.setleftanchor (text, 10.0);

Text Text2 = new text ();
Text2.settext ("Result:");
Text2.setfont (Font.font ("Comic Sans MS", 18));
Anchorpane.settopanchor (Text2, 50.0);
Anchorpane.setleftanchor (Text2, 10.0);

Label = new label ("");
Label.setfont (Font.font ("Comic Sans MS", 16));
Anchorpane.settopanchor (label, 90.0);
Anchorpane.setleftanchor (label, 50.0);

Button button = New button ();
Button.settext ("sure");
Anchorpane.settopanchor (button, 5.0);
Anchorpane.setleftanchor (button, 420.0);

TextField = new TextField ();
Textfield.setprefwidth (160);
Textfield.gettext ();
Anchorpane.settopanchor (TextField, 5.0);
Anchorpane.setleftanchor (TextField, 250.0);

Button.setonaction (New eventhandler<actionevent> () {

@Override
public void handle (ActionEvent e) {
char input[] = Textfield.gettext (). ToCharArray ();
int errorcase = 3;
if (Textfield.gettext (). Length () ==0 | | textfield.gettext (). Length () >= 7) {
Errorcase = 1;
}
Else {
for (int i=0;i<textfield.gettext (). Length (); i++) {
if (! ( (input[i]>=48 && input[i]<57) | | (input[i]>=65 && input[i]<=90) | | (input[i]>=97 && input[i]<=122))) {
Errorcase = 2;
break;
}
}
}
switch (errorcase) {

Case 1:
Label.settext ("input is" + textfield.gettext () + "\ n" + "error1:the length of input is Error");
Break

Case 2:
Label.settext ("input is" + textfield.gettext () + "\ n" + "error2:the kind of input is error");
Break

Case 3:
Label.settext ("Input is" + textfield.gettext () + "\ n" + "Succeed:input is correct");

}
}
});

Root.getchildren (). AddAll (Text,text2,textfield,button,label);
Stage.setresizable (FALSE);
Stage.setscene (Scene);
Stage.show ();
}
}

equivalence class partitioning and test Case Design:


Tests for numbers 1, 2, 3, 8, 11, 17:

Implementation of equivalence class partitioning test on Java

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.