有关问题:
有3个EditBox,每次允许输入1~6个英文字符或数字,按enter结束
关注点:
输入字符的长度,输入字符的类型
等价类划分:
编号 | 有效or无效 | 等价类内容 |
1 | 有效 | 长度为1-6 |
2 | 有效 | 内容为英文字符或数字 |
3 | 有效 | 3个EditBox都正确 |
4 | 无效 | 长度为0或大于6 |
5 | 无效 | 内容不全为英文字符和数字 |
6 | 无效 | 3个EditBox不全都正确 |
测试用例:
输入1 | 输入2 | 输入3 | 覆盖等价类 | 预测输出 |
123 | abc | AS1acx | 123 | ok |
123 | abc | 426 | false | |
123 | abc, | AS1acx | 156 | false |
1234567 | abc. | AS1acx | 456 | false |
测试结果:
代码:
1 import javafx.application.Application; 2 import javafx.event.ActionEvent; 3 import javafx.event.EventHandler; 4 import javafx.scene.*; 5 import javafx.scene.control.Button; 6 import javafx.scene.control.TextField; 7 import javafx.scene.layout.AnchorPane; 8 import javafx.scene.layout.StackPane; 9 import javafx.scene.text.Text; 10 import javafx.stage.Stage; 11 12 class Kuang extends AnchorPane{ 13 Text text = new Text("Name:"); 14 TextField textField=new TextField(); 15 double hight = 0; 16 Kuang(double hight,AnchorPane pane){ 17 this.getChildren().addAll(text,textField); 18 this.hight = hight; 19 AnchorPane.setTopAnchor(this, hight); 20 AnchorPane.setLeftAnchor(this, 50.0); 21 pane.getChildren().add(this); 22 } 23 public boolean check(){ 24 int length = this.textField.getText().length(); 25 if(length > 6 || length < 1) 26 return false; 27 for (char a : this.textField.getText().toCharArray()){ 28 if(!Character.isAlphabetic(a)&&!Character.isDigit(a)) 29 return false; 30 } 31 return true; 32 } 33 } 34 public class MyTest extends Application { 35 36 /** 37 * @param args 38 */ 39 public static void main(String[] args) { 40 // TODO Auto-generated method stub 41 MyTest.launch(args); 42 43 } 44 45 @Override 46 public void start(Stage stage) throws Exception { 47 // TODO Auto-generated method stub 48 stage.setTitle("MyTest"); 49 AnchorPane root = new AnchorPane(); 50 final Kuang kuang1= new Kuang(50,root); 51 final Kuang kuang2= new Kuang(100,root); 52 final Kuang kuang3 = new Kuang(150,root); 53 Button but = new Button("enter"); 54 but.setOnAction(new EventHandler<ActionEvent>(){ 55 public void handle(ActionEvent event){ 56 String back = "false"; 57 if(kuang1.check()&&kuang2.check()&kuang3.check()){ 58 back = "ok"; 59 } 60 System.out.println(back); 61 } 62 }); 63 AnchorPane.setTopAnchor(but, 200.0); 64 AnchorPane.setLeftAnchor(but, 100.0); 65 root.getChildren().add(but); 66 stage.setScene(new Scene(root,250,250)); 67 stage.show(); 68 } 69 70 }