软件测试——等价类划分(EditText * 3)

一、程序要求

  EditBox 同时允许输入三个1到6个英文字符或数字,点击确定结束。

二、测试分析

编号 第一个输入框 第二个输入框 第三个输入框 输出
1 null null null 三个输入框均不符合要求
2 abc 123 ab112 三个输入框均符合要求
3 abc.. 123 ab112 第一个输入框不符合要求
4 abc 123.. ab112 第二个输入框不符合要求
5 abc 123 ab112. 第三个输入框不符合要求
6 abcadlsfkja 123 ab112 第一个输入框不符合要求
7 abcadlsfkja 12312192 ab112 只有第三个输入框符合要求
8 abcadlsfkja 12312192 ab112sfav 三个输入框均不符合要求

三、程序代码

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.TextField;
import javafx.scene.layout.AnchorPane;
import javafx.scene.text.Text;
import javafx.stage.Stage;


public class Equivalence extends Application{
    
    public static void main(String arg0[]){
        Equivalence.launch(arg0);
    }

    @Override
    public void start(Stage stage) throws Exception {
        stage.setTitle("Equivalence class");
        AnchorPane root = new AnchorPane();
        
        Text message = new Text("请输入:");
        root.getChildren().add(message);
        AnchorPane.setTopAnchor(message, 50.0);
        AnchorPane.setLeftAnchor(message, 80.0);
        
        final TextField textInput1 = new TextField();
        root.getChildren().add(textInput1);
        AnchorPane.setTopAnchor(textInput1, 70.0);
        AnchorPane.setLeftAnchor(textInput1, 33.0);
        
        final TextField textInput2 = new TextField();
        root.getChildren().add(textInput2);
        AnchorPane.setTopAnchor(textInput2, 100.0);
        AnchorPane.setLeftAnchor(textInput2, 33.0);
        
        final TextField textInput3 = new TextField();
        root.getChildren().add(textInput3);
        AnchorPane.setTopAnchor(textInput3, 130.0);
        AnchorPane.setLeftAnchor(textInput3, 33.0);
        
        Button submit = new Button();
        submit.setText("确定");
        root.getChildren().add(submit);
        AnchorPane.setTopAnchor(submit, 170.0);
        AnchorPane.setLeftAnchor(submit, 77.0);
        
        submit.setOnAction(new EventHandler<ActionEvent>() {
            public void handle(ActionEvent arg0) {
                if(checkString(textInput1.getText().toString()) && checkString(textInput2.getText().toString()) && checkString(textInput3.getText().toString())){
                     Stage newStage = new Stage();
                     AnchorPane newRoot = new AnchorPane();
                     
                     Text result = new Text("三个输入框均符合要求~");
                     newRoot.getChildren().add(result);
                     AnchorPane.setTopAnchor(result, 20.0);
                     AnchorPane.setLeftAnchor(result, 30.0);
                     
                     newStage.setScene(new Scene(newRoot, 200, 50));
                     newStage.show();
                }else if(checkString(textInput1.getText().toString()) && checkString(textInput2.getText().toString())){
                    Stage newStage = new Stage();
                     AnchorPane newRoot = new AnchorPane();
                     
                     Text result = new Text("第三个输入框不符合要求~");
                     newRoot.getChildren().add(result);
                     AnchorPane.setTopAnchor(result, 20.0);
                     AnchorPane.setLeftAnchor(result, 30.0);
                     
                     newStage.setScene(new Scene(newRoot, 200, 50));
                     newStage.show();
                }else if(checkString(textInput1.getText().toString()) && checkString(textInput3.getText().toString())){
                    Stage newStage = new Stage();
                     AnchorPane newRoot = new AnchorPane();
                     
                     Text result = new Text("第二个输入框不符合要求~");
                     newRoot.getChildren().add(result);
                     AnchorPane.setTopAnchor(result, 20.0);
                     AnchorPane.setLeftAnchor(result, 30.0);
                     
                     newStage.setScene(new Scene(newRoot, 200, 50));
                     newStage.show();
                }else if(checkString(textInput2.getText().toString()) && checkString(textInput2.getText().toString())){
                    Stage newStage = new Stage();
                     AnchorPane newRoot = new AnchorPane();
                     
                     Text result = new Text("第一个输入框不符合要求~");
                     newRoot.getChildren().add(result);
                     AnchorPane.setTopAnchor(result, 20.0);
                     AnchorPane.setLeftAnchor(result, 30.0);
                     
                     newStage.setScene(new Scene(newRoot, 200, 50));
                     newStage.show();
                }else if(checkString(textInput1.getText().toString())){
                    Stage newStage = new Stage();
                     AnchorPane newRoot = new AnchorPane();
                     
                     Text result = new Text("只有第一个输入框符合要求~");
                     newRoot.getChildren().add(result);
                     AnchorPane.setTopAnchor(result, 20.0);
                     AnchorPane.setLeftAnchor(result, 30.0);
                     
                     newStage.setScene(new Scene(newRoot, 200, 50));
                     newStage.show();
                }else if(checkString(textInput2.getText().toString())){
                    Stage newStage = new Stage();
                     AnchorPane newRoot = new AnchorPane();
                     
                     Text result = new Text("只有第二个输入框符合要求~");
                     newRoot.getChildren().add(result);
                     AnchorPane.setTopAnchor(result, 20.0);
                     AnchorPane.setLeftAnchor(result, 30.0);
                     
                     newStage.setScene(new Scene(newRoot, 200, 50));
                     newStage.show();
                }else if(checkString(textInput3.getText().toString())){
                    Stage newStage = new Stage();
                     AnchorPane newRoot = new AnchorPane();
                     
                     Text result = new Text("只有第三个输入框符合要求~");
                     newRoot.getChildren().add(result);
                     AnchorPane.setTopAnchor(result, 20.0);
                     AnchorPane.setLeftAnchor(result, 30.0);
                     
                     newStage.setScene(new Scene(newRoot, 200, 50));
                     newStage.show();
                }else{
                    Stage newStage = new Stage();
                     AnchorPane newRoot = new AnchorPane();
                     
                     Text result = new Text("三个输入框均不符合要求~");
                     newRoot.getChildren().add(result);
                     AnchorPane.setTopAnchor(result, 20.0);
                     AnchorPane.setLeftAnchor(result, 25.0);
                     
                     newStage.setScene(new Scene(newRoot, 200, 50));
                     newStage.show();
                }
            }
        });
        
        stage.setScene(new Scene(root, 200,230));
        stage.show();
    }
    
    public boolean checkString(String str){
        if(str.length() == 0 || str.length() >= 7){
            return false;
        }
        
        char arr[] = new char[str.length()];
        arr = str.toCharArray();
        
        for(int i = 0; i < str.length(); i++){
            if((arr[i] >= 'a' && arr[i] <= 'z')||(arr[i] >= 'A' && arr[i] <= 'Z')||(arr[i] >= '0' && arr[i] <= '9'));
            else{
                return false;
            }
        }
        return true;
    }
    
}

四、程序结果

原文地址:https://www.cnblogs.com/wuditju/p/4375416.html