- 问题描述
- 输入区间仅允许输入1到6个英文字符或数字,按submit结束
- 若输入不符合要求输出错误信息
- 等价划分类
有效等价类 | 无效等价类 |
E1:长度: 1到6 | T1: 长度: 0,7 |
E2:字符: a-z,A-Z,0-9 | T2: 英文、数字以外字符,控制字符,标点符号 |
对于一个Editing Boxing来说:
长度:字符 | ||
C (正确输入) | E1:E2 | 输入正确 |
W1(一类错误输入) | E1:T2 | 输入输入字符不完全为英文和数字组成 |
W2(二类错误输入) | T1:E2 | 输入长度超过6或输入为空 |
W3(三类错误输入) | 输入为空 |
- 设计测试用例
编号 | 测试用例 | 预期输出 | ||||
text1 | text2 | text3 | text1 | text1 | text3 | |
1(CCC) | "abc2" | "abc2" | "abc2" | 输入正确 | 输入正确 | 输入正确 |
2 (W3W3W3) | "" | "" | "" | 输入为空 | 输入为空 | 输入为空 |
3 (W2W2W2) | "abc22dd" | "abc22dd" | "abc22dd" | 输入长度超过6 | 输入长度超过6 | 输入长度超过6 |
4 (W1W1W1) | "abc\\" | "abc\\" | "abc\\" | 输入字符不完全为英文和数字组成 | 输入字符不完全为英文和数字组成 | 输入字符不完全为英文和数字组成 |
5(CCW3) | "abc2" | "abc2" | "" | 输入正确 | 输入正确 | 输入为空 |
6(CW2C) | "abc2" | "abc22dd" | "abc2" | 输入正确 | 输入长度超过6 | 输入正确 |
7(W1CC) | "abc\\" | "abc2" | "abc2" | 输入字符不完全为英文和数字组成 | 输入正确 | 输入正确 |
8(CW3W1) | "abc2" | "" | "abc\\" | 输入正确 | 输入为空 | 输入字符不完全为英文和数字组成 |
9(W3CW2) | "" | "abc2" | "abc22dd" | 输入为空 | 输入正确 | 输入长度超过6 |
10(W2W1C) | "abc22dd" | "abc\\" | "abc2" | 输入长度超过6 | 输入字符不完全为英文和数字组成 | 输入正确 |
11(W3W1W2) | "" | "abc\\" | "abc22dd" | 输入为空 | 输入字符不完全为英文和数字组成 | 输入长度超过6 |
- 代码
import javax.swing.JOptionPane;import javafx.application.Application;import javafx.event.ActionEvent;import javafx.event.EventHandler;import javafx.geometry.Pos;import javafx.scene.Scene;import javafx.scene.control.Button;import javafx.scene.control.Label;import javafx.scene.control.TextField;import javafx.scene.layout.HBox;import javafx.scene.layout.VBox;import javafx.stage.Stage;public class editboxing extends Application { public static void main(String[] args) { // TODO Auto-generated method stub editboxing.launch( args ); } TextField textfield1 = new TextField(); TextField textfield2 = new TextField(); TextField textfield3 = new TextField(); @Override public void start(Stage primaryStage) throws Exception { // TODO Auto-generated method stub primaryStage.setTitle("Editing Boxing"); VBox root = new VBox( 30 ); Scene scene = new Scene( root, 400, 200 ); primaryStage.setScene( scene ); HBox hbox1 = new HBox( 20 ); textfield1.setPrefColumnCount( 25 ); hbox1.setAlignment( Pos.CENTER_LEFT ); hbox1.getChildren().addAll( new Label( "text1:" ), textfield1 ); HBox hbox2 = new HBox( 20 ); textfield2.setPrefColumnCount( 25 ); hbox2.setAlignment( Pos.CENTER_LEFT ); hbox2.getChildren().addAll( new Label( "text2:" ), textfield2 ); HBox hbox3 = new HBox( 20 ); textfield3.setPrefColumnCount( 25 ); hbox3.setAlignment( Pos.CENTER_LEFT ); hbox3.getChildren().addAll( new Label( "text3:" ), textfield3 ); HBox hbox4 = new HBox( 20 ); Button btn = new Button(); btn.setText( "submit" ); btn.setOnAction( new Listener() ); btn.setAlignment( Pos.CENTER ); hbox4.getChildren().addAll( btn ); hbox4.setAlignment( Pos.CENTER ); root.getChildren().addAll( hbox1, hbox2, hbox3, hbox4 ); primaryStage.show(); } public class Listener implements EventHandler{ @Override public void handle(ActionEvent arg0) { // TODO Auto-generated method stub String text1 = textfield1.getText(); String text2 = textfield2.getText(); String text3 = textfield3.getText(); String inf1 = testing( text1, "text1" ); String inf2 = testing( text2, "text2" ); String inf3 = testing( text3, "text3" ); String inf = inf1 + "\n" + inf2 + "\n" + inf3; JOptionPane.showMessageDialog( null, inf, "information", JOptionPane.INFORMATION_MESSAGE ); } public String testing( String arg, String arg1 ) { String ans = ""; if( arg == null || arg.equals( "" ) ){ ans = arg1 + " 输入为空!"; } else if( arg.length() > 6){ ans = arg1 + " 输入字符长度大于6"; } else{ boolean pcount = true; for(int i = 0; i < arg.length(); i++ ) { if( !( isChar( arg.charAt(i) ) || isNum( arg.charAt(i) ) ) ) { pcount = false; break; } } if( pcount ) { ans = arg1 + " 输入正确"; } else { ans = arg1 + " 输入字符不完全为英文字符和数字组成"; } } return ans; } public boolean isChar( char arg1 ) { if( ( arg1 >= 'a' && arg1 <= 'z' ) || ( arg1 >= 'A' && arg1 <= 'Z' ) ) { return true; } else { return false; } } public boolean isNum( char arg1 ) { if( arg1 >= '0' && arg1 <= '9' ) { return true; } else { return false; } } }}
- 测试
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.